tf.Tensor' import / Mul:0' shape =(1,299,299,3)dtype = float32>作为输入?

时间:2017-11-11 22:49:35

标签: python image-processing tensorflow deep-learning

在读取图像文件并对其进行规范化之后,我想知道在开始时哪个节点将作为输入。

我使用此函数(来自tensorflow存储库)

对图像进行了规范化
def read_tensor_from_image_file(file_name, input_height=299, input_width=299,
                input_mean=0, input_std=255):
  input_name = "file_reader"
  output_name = "normalized"
  file_reader = tf.read_file(file_name, input_name)
  if file_name.endswith(".png"):
    image_reader = tf.image.decode_png(file_reader, channels = 3,
                                       name='png_reader')
  elif file_name.endswith(".gif"):
    image_reader = tf.squeeze(tf.image.decode_gif(file_reader,
                                                  name='gif_reader'))
  elif file_name.endswith(".bmp"):
    image_reader = tf.image.decode_bmp(file_reader, name='bmp_reader')
  else:
    image_reader = tf.image.decode_jpeg(file_reader, channels = 3,
                                        name='jpeg_reader')
  float_caster = tf.cast(image_reader, tf.float32)
  dims_expander = tf.expand_dims(float_caster, 0);
  resized = tf.image.resize_bilinear(dims_expander, [input_height, input_width])
  normalized = tf.divide(tf.subtract(resized, [input_mean]), [input_std])
  sess = tf.Session()
  result = sess.run(normalized)

  return result

查看初始操作:

<bound method Operation.values of <tf.Operation 'import/DecodeJpeg/contents' type=Const>> 

<bound method Operation.values of <tf.Operation 'import/DecodeJpeg' type=DecodeJpeg>> 

<bound method Operation.values of <tf.Operation 'import/Cast' type=Cast>> 

<bound method Operation.values of <tf.Operation 'import/ExpandDims/dim' type=Const>> 

<bound method Operation.values of <tf.Operation 'import/ExpandDims' type=ExpandDims>> 

<bound method Operation.values of <tf.Operation 'import/ResizeBilinear/size' type=Const>> 

<bound method Operation.values of <tf.Operation 'import/ResizeBilinear' type=ResizeBilinear>> 

<bound method Operation.values of <tf.Operation 'import/Sub/y' type=Const>> 

<bound method Operation.values of <tf.Operation 'import/Sub' type=Sub>> 

<bound method Operation.values of <tf.Operation 'import/Mul/y' type=Const>> 

<bound method Operation.values of <tf.Operation 'import/Mul' type=Mul>> 

<bound method Operation.values of <tf.Operation 'import/conv/conv2d_params' type=Const>> 

似乎前几层对jpeg文件进行了规范化,由于上面提供的功能,我可以跳过它。

现在我不确定我可以输入result的位置(上述功能的结果):

我不确定Mul(乘法)在这种情况下做了什么,但我假设该节点的操作结果应该与结果相同我上面的功能?我的假设是基于后续层 - 这是一个围绕参数(权重?)

的转换层

所以我想知道我是否可以将其作为输入用于推理。

谢谢。

编辑:这些是来自tf存储库的脚本我使用:

再培训

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/retrain.py

推断

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/label_image/label_image.py

0 个答案:

没有答案