Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Which one is expected by channel_shift? #17

Closed
wakame1367 opened this issue Jun 18, 2018 · 4 comments
Closed

Which one is expected by channel_shift? #17

wakame1367 opened this issue Jun 18, 2018 · 4 comments

Comments

@wakame1367
Copy link

Hello! While runnning keras-preprocessing(master)/image.py/random_channel_shift, I thought it was different from the expected channel_shift behavior.

I think that the expected channel shift movement is old.

Original Images(cifar10)

from keras.datasets import cifar10
from keras.preprocessing.image import random_channel_shift
import numpy as np
import matplotlib.pyplot as plt


def plot_tiles(images, rows=5, columns=5):
    pos = 1
    for idx in range(rows*columns):
        plt.subplot(rows, columns, pos)
        img = images[idx]
        plt.imshow(img)
        plt.axis("off")
        pos += 1
    plt.show()


(x_train, y_train), (x_test, y_test) = cifar10.load_data()
sample_images = x_train[:9]/255
channel_shift_range = 0.3
plot_tiles(sample_images, rows=3, columns=3)

Latest Channel_Shift Images(cifar10)

channel_shift_images_latest = []
for _ in sample_images:
    channel_shift_images_latest.append(_random_channel_shift(_, channel_shift_range, 2))
channel_shift_images_latest = np.array(channel_shift_images_latest)
plot_tiles(channel_shift_images_latest, rows=3, columns=3)

keras-preprocessing(master)/image.py/random_channel_shift

Old Channel_Shift Images(cifar10)

channel_shift_images_old = []
for _ in sample_images:
    channel_shift_images_old.append(random_channel_shift(_, channel_shift_range, 2))
channel_shift_images_old = np.array(channel_shift_images_old)
plot_tiles(channel_shift_images_old, rows=3, columns=3)

keras-preprocessing(old)/image.py/random_channel_shift

@Dref360
Copy link
Contributor

Dref360 commented Jun 19, 2018

The current behaviour has been in place for more than 2 years now.
See PR : keras-team/keras#2446

@zhenglilei
Copy link

Hi Frédéric,

I think some changes were unintentionally made to the "random_channel_shift" function from Keras 2.1.6 to Keras 2.2.0 (the separate preprocessing lib). Please check this PR if I am wrong. Thanks.

@rragundez
Copy link
Contributor

@Dref360 can we close this issue? It does not seem relevant.

@jingprism
Copy link

I think there was a mistake with the code. If you input some large value like 200.0, it will produce real channel shifts like mentioned here under "Old Channel_Shift Images(cifar10)": #223

However, it should be using a float between 0 and 1 rather than a large absolute value.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants