-
Notifications
You must be signed in to change notification settings - Fork 331
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
Fix ChannelShuffle
#418
Fix ChannelShuffle
#418
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
|
||
import tensorflow as tf | ||
|
||
import keras_cv | ||
|
||
|
||
@tf.keras.utils.register_keras_serializable(package="keras_cv") | ||
class ChannelShuffle(tf.keras.__internal__.layers.BaseImageAugmentationLayer): | ||
|
@@ -52,6 +54,11 @@ def __init__(self, groups=3, seed=None, **kwargs): | |
self.groups = groups | ||
self.seed = seed | ||
|
||
tf.random.set_seed(self.seed) | ||
self.rand_uniform = keras_cv.UniformFactorSampler( | ||
lower=0, upper=1, seed=self.seed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add unit test for this gradient fix? |
||
) | ||
|
||
def augment_image(self, image, transformation=None): | ||
shape = tf.shape(image) | ||
height, width = shape[0], shape[1] | ||
|
@@ -65,10 +72,10 @@ def augment_image(self, image, transformation=None): | |
) | ||
|
||
channels_per_group = num_channels // self.groups | ||
image = tf.reshape(image, [height, width, self.groups, channels_per_group]) | ||
image = tf.transpose(image, perm=[2, 0, 1, 3]) | ||
image = tf.random.shuffle(image, seed=self.seed) | ||
image = tf.transpose(image, perm=[1, 2, 3, 0]) | ||
|
||
rand_indices = tf.argsort(self.rand_uniform(shape=[self.groups])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Just another one to add to the list. But as you can see with the master implementation we have already So one in, one out. |
||
image = tf.reshape(image, [height, width, channels_per_group, self.groups]) | ||
image = tf.gather(image, rand_indices, axis=-1) | ||
image = tf.reshape(image, [height, width, num_channels]) | ||
|
||
return image | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LukeWood cc @bhack
This line is only set to satisfy the shuffle-net's requirements. By this, it will produce a static shuffled operation.
But for random operation,
seed=None
.But this may also be a bit in conflict with other KPLs from implementation perspective. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the point in my last comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be modifying seed inside of any layer.