我正在尝试修改服务教程以使用我的模型,这基本上是修改为使用 CSV 文件和 JPEG 的 CIFAR 示例。我似乎找不到 Exporter 类的文档,但这是我目前所拥有的。它在 cifar10_train.py 文件的 train() 函数中:
# Save the model checkpoint periodically.
if step % 10 == 0 or (step + 1) == FLAGS.max_steps:
checkpoint_path = os.path.join(FLAGS.train_dir, 'model.ckpt')
saver.save(sess, checkpoint_path, global_step=step)
export_dir = FLAGS.export_dir
print 'Exporting trained model to ' + FLAGS.export_dir
export_saver = tf.train.Saver(sharded=True)
model_exporter = exporter.Exporter(export_saver)
#
# TODO: where to find x and y?
#
signature = exporter.classification_signature(input_tensor=x, scores_tensor=y)
model_exporter.init(sess.graph.as_graph_def(),
default_graph_signature=signature)
model_exporter.export(export_dir, tf.constant(FLAGS.export_version), sess)
这是我用来训练模型的代码:
labels = numpy.fromfile(os.path.join(data_dir, 'labels.txt'), dtype=numpy.int32, count=-1, sep='\n')
filenames_and_labels = []
start_image_number = 1
end_image_number = 8200
for i in xrange(start_image_number, end_image_number):
file_name = os.path.join(data_dir, 'image%d.jpg' % i)
label = labels[i - 1]
filenames_and_labels.append(file_name + "," + str(label))
print('Reading filenames for ' + str(len(filenames_and_labels)) + ' files (from ' + str(start_image_number) + ' to ' + str(end_image_number) + ')')
for filename_and_label in filenames_and_labels:
array = filename_and_label.split(",")
f = array[0]
# print(array)
if not tf.gfile.Exists(f):
raise ValueError('Failed to find file: ' + f)
# Create a queue that produces the filenames to read.
filename_and_label_queue = tf.train.string_input_producer(filenames_and_labels)
filename_and_label_tensor = filename_and_label_queue.dequeue()
filename, label = tf.decode_csv(filename_and_label_tensor, [[""], [""]], ",")
file_contents = tf.read_file(filename)
image = tf.image.decode_jpeg(file_contents)
任何想法如何正确设置导出器?