Skip to content
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

Migrating SimSiam Example to Keras-3 #1697

Merged
merged 2 commits into from
Dec 30, 2023
Merged

Conversation

aditya02shah
Copy link
Contributor

@aditya02shah aditya02shah commented Dec 26, 2023

This PR migrates the simsiam example to Keras 3.0 as requested in this GitHub issue and includes the following changes:

  1. Hardcoded the backend to TF-only to align with the fact that it's a TF-only example.
  2. Replaced the dependency on TensorFlow-based data augmentation with a Keras-based pipeline, involving:
    • Substitution of TensorFlow image preprocessing functions with equivalent keras and keras-cv layers.
    • Initialization of layers outside the function to resolve the "ValueError: tf.function only supports singleton tf.Variables created on the first call. Make sure the tf.Variable is only created once or created outside tf.function" issue after implementing the earlier mentioned changes.
    • Modification of arguments for the keras_cv.layers.RandomSaturation layer to ensure they fall within the range [0.0, 1.0].

Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@@ -41,15 +41,19 @@
4. We then train our encoder to maximize the cosine similarity between the two different
versions of our dataset.

This example requires TensorFlow 2.4 or higher.
This example requires TensorFlow 2.15 or higher.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this line.

return x


def random_apply(func, x, p):
if tf.random.uniform([], minval=0, maxval=1) < p:
if keras.random.uniform([], minval=0, maxval=1,seed=152) < p:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the seed argument, otherwise you'll get the same output at every call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I have made the necessary changes!

Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@fchollet fchollet merged commit e3c97a6 into keras-team:master Dec 30, 2023
1 of 3 checks passed
SuryanarayanaY pushed a commit to SuryanarayanaY/keras-io that referenced this pull request Jan 19, 2024
* Migrating SimSiam Example to Keras-3

* Removed Seed and Updated Formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants