1

https://github.com/tensorflow/models/tree/master/slim이이 셉션 v1-4 pretrained 모델에 대한 체크 포인트에 대한 다운로드 링크를 제공 Inception_v4 모델

에게 pretrained 사용. 그러나 tar.gz에는 .ckpt 파일 만 들어 있습니다.

Inception v3 2012 [This link] 사용 자습서에서 tar.gz는 분류에 사용되는 .pb 및 .pbtxt 파일을 포함합니다.

어떻게 .ckpt 파일을 사용하여 .pb 및 .pbtxt 파일을 각각 생성 할 수 있습니까? 또는 분류에 .ckpt 파일을 사용하는 다른 방법이 있습니까?

답변

0

심지어 나는 inception_v4 모델을 시도 중입니다. 내 검색 중에 나는 체크 포인트 파일이 가중치를 포함하고있는 것을 발견 할 수 있었다. 그래서 inorder를 사용하려면 inception_v4.py에서 inception_v4 그래프를로드해야하고 체크 포인트 파일에서 세션을 복원해야했습니다. 다음 코드는 검사 점 파일을 읽고 protobuf 파일을 만듭니다.

import tensorflow as tf 
slim = tf.contrib.slim 
import tf_slim.models.slim.nets as net 
# inception_v3_arg_scope 
import tf_slim 
import inception_v4 as net 
import cv2 


# checkpoint file 
checkpoint_file = '/home/.../inception_v4.ckpt' 

# Load Session 
sess = tf.Session() 
arg_scope = net.inception_v4_arg_scope() 
input_tensor = tf.placeholder(tf.float32, [None, 299, 299, 3]) 
with slim.arg_scope(arg_scope): 
    logits, end_points = net.inception_v4(inputs=input_tensor) 

saver = tf.train.Saver() 
saver.restore(sess, checkpoint_file) 
f = tf.gfile.FastGFile('./mynet.pb', "w") 
f.write(sess.graph_def.SerializeToString()) 
f.close() 

# reading the graph 
# 
with tf.gfile.FastGFile('./mynet.pb', 'rb') as fp: 
    graph_def = tf.GraphDef() 
    graph_def.ParseFromString(fp.read()) 

    with tf.Session(graph=tf.import_graph_def(graph_def, name='')) as sess: 
    # op = sess.graph.get_operations() 
    # with open('./tensors.txt', mode='w') as fp: 
    #  for m in op: 
    #  #  print m.values() 
    #   fp.write('%s \n' % str(m.values())) 
    cell_patch = cv2.imread('./car.jpg') 
    softmax_tensor = sess.graph.get_tensor_by_name('InceptionV4/Logits/Predictions:0') 
    predictions = sess.run(softmax_tensor, {'Placeholder:0': cell_patch}) 

그러나 위의 코드는 예측을 제공하지 않습니다. 왜냐하면 그래프에 입력을주는 데 문제가 있기 때문입니다. 그러나 검사 점 파일을 사용하는 것이 좋은 출발점이 될 수 있습니다.

검사 점을 다음 링크에서 다운로드합니다. checkpoints