-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
RandomHeight Preprocessing Layer #7483
RandomHeight Preprocessing Layer #7483
Conversation
…ctins for preprocessing layers Co-authored-by: Silvia Kocsis <[email protected]> Co-authored-by: Natalie Umanzor <[email protected]>
Co-authored-by: Silvia Kocsis <[email protected]> Co-authored-by: Natalie Umanzor <[email protected]>
…d handles randomization of width Co-authored-by: Silvia Kocsis <[email protected]> Co-authored-by: Natalie Umanzor <[email protected]>
Co-authored-by: Silvia Kocsis <[email protected]> Co-authored-by: Natalie Umanzor <[email protected]>
Co-authored-by: Silvia Kocsis <[email protected]> Co-authored-by: Natalie Umanzor <[email protected]>
Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
…ss, got rid of rng_types as all random distribution functions seem to be stateless Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
…nd stores random distribution functions as properties Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
…mLayer Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
Co-authored-by: Silvia Kocsis <[email protected]> Co-authored-by: Natalie Umanzor <[email protected]>
Co-authored-by: Silvia Kocsis <[email protected]> Co-authored-by: Natalie Umanzor <[email protected]>
Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
…, and added test for RandomSeed Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
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 looks good. I just have one change to better match Keras's behavior. Thanks!
override computeOutputShape(inputShape: Shape|Shape[]): Shape|Shape[] { | ||
inputShape = getExactlyOneShape(inputShape); | ||
const numChannels = inputShape[2]; | ||
return [this.adjustedHeight, this.imgWidth, numChannels]; |
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.
The Keras implementation sets the height index to None
.
>>> random_height = keras.layers.RandomHeight([0.5, 0.7])
>>> random_height.compute_output_shape([1, 224, 224, 3])
TensorShape([1, None, 224, 3])
I think this is to indicate that the height of a generic tensor that this layer could create is unknown. I don't think it should be specific to the last tensor the layer created. The equivalent to None
in a shape in TFJS is -1
, so the above code, if written in TFJS, should return [1, -1, 224, 3]
. For your code, you can just return [-1, this.imgWidth, numChannels]
.
This should also let you remove the this.adjustedHeight
variable from the class and make it local to the call
function.
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 think I missed this in my review of RandomWidth
. Could you add the change there as well? Thanks!
this.adjustedHeight = this.heightFactor.dataSync()[0] * imgHeight; | ||
this.adjustedHeight = Math.round(this.adjustedHeight); |
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.adjustedHeight = this.heightFactor.dataSync()[0] * imgHeight; | |
this.adjustedHeight = Math.round(this.adjustedHeight); | |
let adjustedHeight = this.heightFactor.dataSync()[0] * imgHeight; | |
adjustedHeight = Math.round(this.adjustedHeight); |
this.adjustedHeight = this.heightFactor.dataSync()[0] * imgHeight; | ||
this.adjustedHeight = Math.round(this.adjustedHeight); | ||
|
||
const size:[number, number] = [this.adjustedHeight, this.imgWidth]; |
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.
const size:[number, number] = [this.adjustedHeight, this.imgWidth]; | |
const size:[number, number] = [adjustedHeight, this.imgWidth]; |
…OutputShape. Co-authored-by: Natalie Umanzor <[email protected]> Co-authored-by: Ryan Wallace <[email protected]>
Hey @mattsoulanille! Made the changes in |
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.
Looks great! LGTM!
RandomHeight Preprocessing Layer
Co-authored-by:
Natalie Umanzor (@numanzor) [email protected]
Silvia Kocsis (@Silvia42) [email protected]
Ryan Wallace (@RWallie) [email protected]
This change is