How to initialize weight for convolution layers in Tensorflow Object Detection API?

被刻印的时光 ゝ 提交于 2019-12-08 05:02:49

问题


I followed this tutorial for implementing Tensorflow Object Detection API.

The preferred way is using pretrained models.

But for some cases, we need to train from scratch.

For that we just need to comment out two lines in the configuration file as

#fine_tune_checkpoint: "object_detection/data/mobilenet_v1_1.0_224/mobilenet_v1_1.0_224.ckpt"
#from_detection_checkpoint: true 

If I want to initialize weight with Xavier weight initialization, how can I do that?


回答1:


As you can see in the configuration protobuf definition, there are 3 initializers you can use:

  • TruncatedNormalInitializer truncated_normal_initializer
  • VarianceScalingInitializer variance_scaling_initializer
  • RandomNormalInitializer random_normal_initializer

The VarianceScalingInitializer is what you are looking for. It is general initializer which you can basically turn into Xavier initializer by setting factor=1.0, mode='FAN_AVG', as stated in the documentation.

So, by setting the initializers as

initializer {
    variance_scaling_initializer {
        factor: 1.0
        uniform: true
        mode: FAN_AVG
    }
}

in your configuration, you obtain Xavier initializer.

But also, even if you need to train on new data, consider using pretrained network as initialization instead of random initialization. For more details, see this article.




回答2:


The mobilenet_v1 feature extractor imports the backbone network from research/slim/nets:

25:   from nets import mobilenet_v1

The code of mobilenet instantiates the layers according to the specification like this:

net = slim.conv2d(net, depth(conv_def.depth), conv_def.kernel, stride=conv_def.stride, scope=end_point)

See https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.py#L264

As you can see, there are no kwargs passed to the conv2d call, so with the current code you cannot specify which weights_initializer will be used.

However, by default the initializer is Xavier anyway, so you are lucky.

I must say that training and object detection model without pre-training the feature extractor on some auxiliary task may simply fail.



来源:https://stackoverflow.com/questions/55178906/how-to-initialize-weight-for-convolution-layers-in-tensorflow-object-detection-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!