如何在 Inception 中对视频帧进行 运行 分类,而不为每一帧启动一个新的 tensorflow 会话?

How to run classifications on video frames in Inception, without starting a new tensorflow session for every frame?

我正在使用 this repo 到 运行 Inception 图像分类器。但是,我希望它在视频上循环并 运行 对每一帧进行检测,而不是对图像进行 运行 检测。我调整了 read_tensor_from_image_file() 函数,使其可以处理帧而不是图像文件,这很好。然而,现在发生的是,对于每一帧,一个新的 tensorflow 会话因为这个位而开始:

 with tf.Session(graph=graph) as sess:
    start = time.time()
    results = sess.run(output_operation.outputs[0],
                      {input_operation.outputs[0]: t})
    end=time.time()
  results = np.squeeze(results)

(t 定义为 t = read_tensor_from_image_file()

我的问题是:如何更改此代码以便我可以 运行 对帧进行分类,而无需为每个帧启动新的 tf.Session。相反,我想在视频开头开始一个 tf.Session,并在视频结束时关闭它。

    graph = load_graph(model_file)
    with tf.Session (graph=graph) as sess:    # initiate tensorflow session
        for t in frame_list:                  # framelist is a list with all frames
            results = sess.run(output_operation.outputs[0],
                  {input_operation.outputs[0]: t})