Docker:如何导出/保存Docker(tensorflow)框外的分类结果?

我只是按照这个教程轻松地训练一个tensorflow的图像分类器:

https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/

我现在在我的Ubuntu笔记本电脑上有一个Docker框,我设法训练图像分类器和IT WORKS。 现在我想分类一批新的图像, 并将结果(即概率)存储在我的笔记本电脑上

我的目标是保存在我的笔记本电脑中的“output.csv”文件如下所示的结果:

pic1 0.95 0.05 pic2 0.94 0.06 pic3 0.97 0.03 pic4 0.09 0.91 

我把新的图像放在一个“testing”的文件夹中,我运行下面的python代码,试图写在输出文件中。

在Dockerterminal里面我运行:

 python /tf_files/label_batch_images.py /tf_files/tested 

其中label_batch_images.py代码是:

 import tensorflow as tf, sys import glob folder_path = sys.argv[1] # Loads label file, strips off carriage return label_lines = [line.rstrip() for line in tf.gfile.GFile("/tf_files/retrained_labels.txt")] # Unpersists graph from file with tf.gfile.FastGFile("/tf_files/retrained_graph.pb", 'rb') as f: graph_def = tf.GraphDef() graph_def.ParseFromString(f.read()) _ = tf.import_graph_def(graph_def, name='') with tf.Session() as sess: out = open('output.csv', 'a') for image_path in glob.glob(folder_path+'/*'): # Read in the image_data image_data = tf.gfile.FastGFile(image_path, 'rb').read() # Feed the image_data as input to the graph and get first prediction softmax_tensor = sess.graph.get_tensor_by_name('final_result:0') predictions = sess.run(softmax_tensor, \ {'DecodeJpeg/contents:0': image_data}) print("%s\t%s\t%s\n" % (image_path,predictions[0][1],predictions[0][0])) #THIS ACTUALLY WORKS, I see in my terminal "/tf_files/tested/pic1.jpg 0.00442768 0.995572" out.write("%s\t%s\t%s\n" % (image_path,predictions[0][1],predictions[0][0])) #This does not work, because output.csv is not modified out.close() 

虽然它的工作原理 – 我看到我的Dockerterminal中的每个图像的预期结果 – 如何将它保存在我的笔记本电脑上的文件?

使用卷

与主机,笔记本电脑共享一个所谓的主机卷,直接在主机上logging结果。 例如,当开始你的形象

docker run -v /home/me/docker/results:/data/results <image>

在你的容器中,当你在/ data /结果上写时,所有的文件将被同步/放置在/ home / me / docker /结果下的主机上

您当然可以调整主机或容器path

用户docker cp

您可以轻松地从Docker容器(或docker容器)用户docker cp复制文件

所以

 docker cp <yourimageid>:/path/to/the/file/on/the/container /home/me/docker/results 

在closures容器之前执行此操作