0

task2.py,我正在执行一个这样的python文件:

text = os.system("python new_image.py  --image_file " + "/home/roots/" + str(nc) + ".jpg --num_top_predictions 1")

new_image.py外观的基本线条

def main(_):
    maybe_download_and_extract()
    image = (FLAGS.image_file if FLAGS.image_file else
            os.path.join(FLAGS.model_dir, 'cropped_panda.jpg'))
    score = run_inference_on_image(image)
    return score


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--model_dir',
        type=str,
        default='/tmp/imagenet',
        help="""\
        Path to classify_image_graph_def.pb,
        imagenet_synset_to_human_label_map.txt, and
        imagenet_2012_challenge_label_map_proto.pbtxt.\
        """
    )
    parser.add_argument(
        '--image_file',
        type=str,
        default='',
        help='Absolute path to image file.'
    )
    parser.add_argument(
        '--num_top_predictions',
        type=int,
        default=5,
        help='Display this many predictions.'
    )
    FLAGS, unparsed = parser.parse_known_args()
    tf.app.run(main=main, argv=[sys.argv[0]] + unparsed)

我已经classify_image.py在 tensorflow 模型 imagenet 中进行了修改,以便run_inference_on_image()返回一个列表。我现在想在task2.py. 我将如何做到这一点?

4

1 回答 1

0

一种简单的方法是将列表保存为临时pickle文件new_image.py,然后将pickle文件加载到task2.py. IE

# In new_image.py
import pickle
picklefile = open('temp.pkl', 'wb')

# Dump list to the pickle file
pickle.dump(listvariable, picklefile)
picklefile.close()

和,

# In task2.py
import pickle 
picklefile = open('temp.pkl', 'rb')
newlist_variable = pickle.load(picklefile)
picklefile.close()

我不知道是否有办法在两个 python 进程之间共享动态变量。但如果有的话,我很想知道!

于 2017-12-20T18:50:44.490 回答