Is there way to add normalization to conv2d in tensorflow

早过忘川 提交于 2019-12-26 02:09:34

问题


in order to do pattern matching properly convolutions require normalization https://en.wikipedia.org/wiki/Cross-correlation#Normalized_cross-correlation

unfortunately I can't find a way how to make input normalization for conv2d function.

is it hidden in implementation?


回答1:


If I'm not mis-reading that, it's in the image library in TF 1.x:

tf.image.per_image_standardization

https://www.tensorflow.org/api_guides/python/image

By the way, that particular function is a little annoying in that it only takes a single image as an input (3D), but you usually have a 4D tensor representing [batch, height, width, channels] for images. To apply that function to a batch of images you can do this:

imgs4d = tf.map_fn(tf.image.per_image_standardization, imgs4d_float32)




回答2:


tf.image.per_image_standardization does exactly what you want.

Linearly scales image to have zero mean and unit norm.

This op computes (x - mean) / adjusted_stddev, where mean is the average of all values in image, and adjusted_stddev = max(stddev, 1.0/sqrt(image.NumElements())).

stddev is the standard deviation of all values in image. It is capped away from zero to protect against division by 0 when handling uniform images.

You need to do this normalization in a preprocessing step (similar to the place where you would do resizing). Also take a look at other image-related functions.




回答3:


It turned out, I was looking for tf.local_response_normalization (https://www.tensorflow.org/versions/r0.11/api_docs/python/nn/normalization) for some strange reason it goes after conv2 layers and used not very often in examples



来源:https://stackoverflow.com/questions/43700282/is-there-way-to-add-normalization-to-conv2d-in-tensorflow

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