我试图重新训练(读finetune)一个MobileNet图像分类器。在
tensorflow here(来自tutorial)的重新训练脚本只更新新添加的完全连接层的权重。我修改了这个脚本来更新预先训练模型的所有层的权重。我使用MobileNet架构,深度乘数为0.25,输入大小为128。在
然而,在重新训练时,我发现了一个奇怪的现象,如果我给一个特定的图像作为输入,以便与其他一些图像一起进行批处理,则某些层之后的激活值与单独传递图像时的激活值不同。同样,来自不同批次的相同图像的激活值也不同。示例-两个批次-
batch_1 : [img1, img2, img3]; batch_2 : [img1, img4, img5]
。img1的激活不同于这两个批次。在
这是我用来推断的代码-
for tf.Session(graph=tf.get_default_graph()) as sess:
image_path = '/tmp/images/10dsf00003.jpg'
id_ = gfile.FastGFile(image_path, 'rb').read()
#The line below loads the jpeg using tf.decode_jpeg and does some preprocessing
id = sess.run(decoded_image_tensor, {jpeg_data_tensor: id_})
input_image_tensor = graph.get_tensor_by_name('input')
layerXname='MobilenetV1/MobilenetV1/Conv2d_1_depthwise/Relu:0' #Name of the layer whose activations to inspect.
layerX = graph.get_tensor_by_name(layerXname)
layerXactivations=sess.run(layerX, {input_image_tensor: id})
上面的代码按原样执行一次,最后一行有以下更改:
^{pr2}$以下是图中的一些节点:
[u'input', u'MobilenetV1/Conv2d_0/weights', u'MobilenetV1/Conv2d_0/weights/read', u'MobilenetV1/MobilenetV1/Conv2d_0/convolution', u'MobilenetV1/Conv2d_0/BatchNorm/beta', u'MobilenetV1/Conv2d_0/BatchNorm/beta/read', u'MobilenetV1/Conv2d_0/BatchNorm/gamma', u'MobilenetV1/Conv2d_0/BatchNorm/gamma/read', u'MobilenetV1/Conv2d_0/BatchNorm/moving_mean', u'MobilenetV1/Conv2d_0/BatchNorm/moving_mean/read', u'MobilenetV1/Conv2d_0/BatchNorm/moving_variance', u'MobilenetV1/Conv2d_0/BatchNorm/moving_variance/read', u'MobilenetV1/MobilenetV1/Conv2d_0/BatchNorm/batchnorm/add/y', u'MobilenetV1/MobilenetV1/Conv2d_0/BatchNorm/batchnorm/add', u'MobilenetV1/MobilenetV1/Conv2d_0/BatchNorm/batchnorm/Rsqrt', u'MobilenetV1/MobilenetV1/Conv2d_0/BatchNorm/batchnorm/mul', u'MobilenetV1/MobilenetV1/Conv2d_0/BatchNorm/batchnorm/mul_1', u'MobilenetV1/MobilenetV1/Conv2d_0/BatchNorm/batchnorm/mul_2', u'MobilenetV1/MobilenetV1/Conv2d_0/BatchNorm/batchnorm/sub', u'MobilenetV1/MobilenetV1/Conv2d_0/BatchNorm/batchnorm/add_1', u'MobilenetV1/MobilenetV1/Conv2d_0/Relu6', u'MobilenetV1/Conv2d_1_depthwise/depthwise_weights', u'MobilenetV1/Conv2d_1_depthwise/depthwise_weights/read', ... ...]
现在当layerXname = 'MobilenetV1/MobilenetV1/Conv2d_0/convolution'
上述两种情况下的激活相同。(即。
layerxactivations和layerxactivations\u batch[0]相同)。
但在这一层之后,所有层都有不同的激活值。我觉得'MobilenetV1/MobilenetV1/Conv2d_0/convolction'层之后的batchNorm操作对于批处理输入和单个图像的行为是不同的。还是其他原因引起的?在
如有任何帮助/建议,我们将不胜感激。在
这是由于批量标准化。在
你怎么推断的。您是从检查点文件加载它还是使用冻结的Protobuf模型。如果使用冻结模型,则不同格式的输入可以得到类似的结果。在
签出this。对于不同的应用程序,也提出了类似的问题。在
当您构建mobilenet时,有一个参数称为
is_training
。如果不将其设置为false,则dropout层和批处理规范化层将在不同的迭代中给出不同的结果。批处理规范化可能对值的更改很小,但由于删除了一些输入值,因此会对值进行很大的更改。在看看mobilnet的签名:
相关问题 更多 >
编程相关推荐