1

I am using ResNet-50 model in tensorflow-slim to extract features. My question is do I need to centre the images according to some standard ResNets-50 mean values before feeding in the images? I know that for vgg-19 tf-slim provides options for centering using _mean_image_subtraction(image, means) defined in vgg_preprocessing.py . But I couldn't find any such files or functions for ResNets.

HIMANSHU RAI
  • 305
  • 1
  • 4
  • 13

2 Answers2

1

I believe you should use vgg_preprocessing as well. In get_preprocessing() from preprocessing_factory.py:

preprocessing_fn_map = {
  'cifarnet': cifarnet_preprocessing,
  'inception': inception_preprocessing,
  'inception_v1': inception_preprocessing,
  'inception_v2': inception_preprocessing,
  'inception_v3': inception_preprocessing,
  'inception_v4': inception_preprocessing,
  'inception_resnet_v2': inception_preprocessing,
  'lenet': lenet_preprocessing,
  'mobilenet_v1': inception_preprocessing,
  'resnet_v1_50': vgg_preprocessing,
  'resnet_v1_101': vgg_preprocessing,
  'resnet_v1_152': vgg_preprocessing,
  'resnet_v1_200': vgg_preprocessing,
  'resnet_v2_50': vgg_preprocessing,
  'resnet_v2_101': vgg_preprocessing,
  'resnet_v2_152': vgg_preprocessing,
  'resnet_v2_200': vgg_preprocessing,
  'vgg': vgg_preprocessing,
  'vgg_a': vgg_preprocessing,
  'vgg_16': vgg_preprocessing,
  'vgg_19': vgg_preprocessing,
}

You can also verify the use of preprocessing_factory.get_preprocessing() from train_image_classifier.py:

preprocessing_name = FLAGS.preprocessing_name or FLAGS.model_name
image_preprocessing_fn = preprocessing_factory.get_preprocessing(
    preprocessing_name,
    is_training=True)

...

image = image_preprocessing_fn(image, train_image_size, train_image_size)
Trisoloriansunscreen
  • 1,543
  • 1
  • 15
  • 27
Yu-Yang
  • 14,539
  • 2
  • 55
  • 62
  • Perfect. This is what I was looking for. Although It is so weird that they have vgg_preprocessing for ResNets as well. They should have put a generic name for this. – HIMANSHU RAI Aug 25 '17 at 20:01
0

Yes, you should center (normalize) images. It should be done for better model convergence.

If there is no default tf-slim method for for this image processing operation for ResNet, you may make your own implementation based on this variant

Also it is more useful to count means (from _mean_image_subtraction(image, means) ) for the whole training batch, not for the single image or for the whole dataset.

Dmitry
  • 91
  • 2
  • 7
  • That's exactly what I want to know, if there is a need for subtracting the means. A lot of frameworks tune the original models so that the same mean values can be subtracted from all ResNet models. So it makes sense to know that whether it has to be done in tf-slim and if yes then what are those mean values for the particular network. – HIMANSHU RAI Aug 25 '17 at 14:38
  • Means must be count for particular dataset, not for particular network. You may also look [here](http://docs.opencv.org/2.4/modules/core/doc/operations_on_arrays.html#cv2.normalize) for another way of doing normalization – Dmitry Aug 25 '17 at 16:09
  • By network mean, I meant mean of the images on which the network was originally trained on . It is a very standard practice in transfer learning to subtract the means from the original data-set. For your reference- https://github.com/vlfeat/matconvnet/issues/485 – HIMANSHU RAI Aug 25 '17 at 16:16