如何重新训练inception-v1模型?

时间:2016-10-27 09:47:10

标签: tensorflow

我已经成功完成了official tutorial,它解释了如何重新训练初始-v3模型,后来成功地重新训练了相同的模型,以便为特定目的训练模型。

然而,与其他更简单的模型相比,该模型复杂且缓慢,例如初始-v1,其准确性对于某些任务来说足够好。具体来说,我想重新训练模型以在Android上使用它,理想情况下,速度方面的性能应与原始TensorFlow Android demo相当。无论如何,我尝试重新训练this link中的inception-v1模型,并在retrain.py中进行以下修改:

BOTTLENECK_TENSOR_NAME = 'avgpool0/reshape:0'
BOTTLENECK_TENSOR_SIZE = 2048
MODEL_INPUT_WIDTH = 224
MODEL_INPUT_HEIGHT = 224
MODEL_INPUT_DEPTH = 3
JPEG_DATA_TENSOR_NAME = 'input'
RESIZED_INPUT_TENSOR_NAME = 'input'

与初始v3相反,初始v1没有任何decodeJpeg或调整大小节点:

初始v3节点:

DecodeJpeg/contents
DecodeJpeg
Cast
ExpandDims/dim
ExpandDims
ResizeBilinear/size
ResizeBilinear
...
pool_3
pool_3/_reshape/shape
pool_3/_reshape
softmax/weights
softmax/biases
softmax/logits/MatMul
softmax/logits
softmax

初始v1节点:

input
conv2d0_w
conv2d0_b
conv2d1_w
conv2d1_b
conv2d2_w
conv2d2_b
...
softmax1_pre_activation
softmax1
avgpool0/reshape/shape
avgpool0/reshape
softmax2_pre_activation/matmul
softmax2_pre_activation
softmax2
output
output1
output2

所以我想这些图像必须在被送入图表之前重新整形。

现在,按下以下功能时会发生错误:

def run_bottleneck_on_image(sess, image_data, image_data_tensor,
                            bottleneck_tensor):
  """Runs inference on an image to extract the 'bottleneck' summary layer.

  Args:
    sess: Current active TensorFlow Session.
    image_data: Numpy array of image data.
    image_data_tensor: Input data layer in the graph.
    bottleneck_tensor: Layer before the final softmax.

  Returns:
    Numpy array of bottleneck values.
  """

  bottleneck_values = sess.run(
      bottleneck_tensor,
      {image_data_tensor: image_data})
  bottleneck_values = np.squeeze(bottleneck_values)
  return bottleneck_values

错误:

  

TypeError:无法将feed_dict键解释为Tensor:无法转换a   操作到张量。

我想在初始v3图的输入节点上的数据必须在初始v3中传递以下节点后重新整形以匹配数据:

DecodeJpeg/contents
DecodeJpeg
Cast
ExpandDims/dim
ExpandDims
ResizeBilinear/size
ResizeBilinear

如果有人已经设法重新启动初始v1模型或者想知道如何在初始v1案例中重新整形数据以匹配初始v3,我将非常感谢任何提示或建议。

2 个答案:

答案 0 :(得分:0)

不确定您是否已经解决了这个问题,但我正在研究类似的问题。

我正在尝试使用与Inception-v3传输学习教程不同的模型(不是Inception-v1或Inception-v3)。这篇文章似乎是在重新映射新模型的输入(在你的情况下是inception-v1)的正确轨道上,与本教程其余部分中使用的jpeg编码一起玩得很好: feeding image data in tensorflow for transfer learning

我遇到的唯一问题是输入错误"无法将类型uint8的张量转换为float32的输入类型"但这至少可以让你走上正轨。

祝你好运!

答案 1 :(得分:0)

(对于仍然感兴趣的人)
起始-v1的瓶颈张量大小应为1024。对我来说,以下设置适用于inception-v1提到的this retrain script。不需要jpeg数据张量或其他。

bottleneck_tensor_name = 'avgpool0/reshape:0'
bottleneck_tensor_size = 1024
input_width = 224
input_height = 224
input_depth = 3
resized_input_tensor_name = 'input:0'
相关问题