【发布时间】:2016-04-01 05:56:48
【问题描述】:
我正在使用 tensorflow 的 imageNet trained model 来提取最后一个池化层的特征作为新图像数据集的表示向量。
模型在新图像上的预测如下:
python classify_image.py --image_file new_image.jpeg
我编辑了主函数,以便我可以获取一个图像文件夹并立即返回所有图像的预测并将特征向量写入 csv 文件。我是这样做的:
def main(_):
maybe_download_and_extract()
#image = (FLAGS.image_file if FLAGS.image_file else
# os.path.join(FLAGS.model_dir, 'cropped_panda.jpg'))
#edit to take a directory of image files instead of a one file
if FLAGS.data_folder:
images_folder=FLAGS.data_folder
list_of_images = os.listdir(images_folder)
else:
raise ValueError("Please specify image folder")
with open("feature_data.csv", "wb") as f:
feature_writer = csv.writer(f, delimiter='|')
for image in list_of_images:
print(image)
current_features = run_inference_on_image(images_folder+"/"+image)
feature_writer.writerow([image]+current_features)
它对大约 21 张图像运行良好,但随后因以下错误而崩溃:
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/framework/ops.py", line 1912, in as_graph_def
raise ValueError("GraphDef cannot be larger than 2GB.")
ValueError: GraphDef cannot be larger than 2GB.
我认为通过调用方法run_inference_on_image(images_folder+"/"+image) 会覆盖以前的图像数据以仅考虑新的图像数据,但似乎并非如此。如何解决这个问题?
【问题讨论】:
标签: python tensorflow