-
Notifications
You must be signed in to change notification settings - Fork 19.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ImageDataGenerator samplewise_center standardize method subtracting mean over image channels #2559
Comments
I am also confused about meaning of zero-mean for each pixel over channels. In my opinion, standardize can have several form: # channelwise x samplewise
if self.samplewise_center:
x = np.rollaxis(x, img_channel_index, 0)
for i in range(x.shape[0]):
x[i] -= np.mean(x[i])
x = np.rollaxis(x, 0, img_channel_index+1)
if self.samplewise_std_normalization:
x = np.rollaxis(x, img_channel_index, 0)
for i in range(x.shape[0]):
x[i] /= np.std(x[i])
x = np.rollaxis(x, 0, img_channel_index+1) or # imagewise x samplewise
if self.samplewise_center:
x -= np.mean(x)
if self.samplewise_std_normalization:
x /= np.std(x) @Liyang90 can you give me some advice? |
For now I changed the code I'm using to def standardize(self, x):
# x is a single image, so it doesn't have image number at index 0
img_row_index = self.row_index - 1
img_col_index = self.col_index - 1
img_channel_index = self.channel_index - 1
if self.samplewise_center:
x -= np.mean(x, axis=(img_channel_index,img_row_index,img_col_index), keepdims=True)
if self.samplewise_std_normalization:
x /= (np.std(x, axis=(img_channel_index,img_row_index,img_col_index), keepdims=True) + 1e-7)
...
...
return x which is totally equivalent to your second example. And it works fine. By removing img_channel_index from the axis tuples, it will be equivalent to your first example. |
@Liyang90 @joelthchao Can I ask what your understanding of the
What were you expecting each of these methods to do? |
|
Cool, that makes sense. The Featurwise Supposing we have images that are 224 x 224 x 3:
With samplewise, we have the same options, but calculating the mean across the sample instead of the image. It seems like we would want to be able to do On a related note, I personally find the use of |
You probably need to take care of function signature. A huge change may break lots of code. |
I fixed for grayscale images but leave RGB images as they are. See #4482 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, but feel free to re-open it if needed. |
i believe this is still an issue |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed. |
Dont close bot |
In the standardize method of ImageDataGenerator:
The mean for samplewise_center and std for samplewise_std_normalization are calculated only over the image channel axis instead of the whole image (all pixels and all channels).
As an example (test code attached), if the input image has only one channel (gray scale image), after performing
x -= np.mean(x, axis=img_channel_index, keepdims=True)
The image will be all 0!
According to the definition of
samplewise_center: set each sample mean to 0.
samplewise_std_normalization: divide each input by its std.
I think calculating mean and std over the whole input image (Global Contrast Normalization), by removing "axis=img_channel_index, " would make more sense.
Test code:
Please make sure that the boxes below are checked before you submit your issue. Thank you!
pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps
pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
The text was updated successfully, but these errors were encountered: