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

Fixing the wrong predictions in transfer_learning.ipynb #2314

Merged
merged 3 commits into from
Jun 26, 2024

Conversation

tilakrayal
Copy link
Contributor

In the Transfer_learning https://www.tensorflow.org/tutorials/images/transfer_learning,
After running the last cell for prediction on test data with fine-tuned model, the output at the end of the code cell predicts all 1, which is wrong prediction

Document:
#Apply a sigmoid since our model returns logits
predictions = tf.nn.sigmoid(predictions)
predictions = tf.where(predictions < 0.5, 0, 1)

This can be fixed by commenting/removing the part in the last cell where we apply the sigmoid function on the predictions,
#Apply a sigmoid since our model returns logits
predictions = tf.nn.sigmoid(predictions) ======> removed this line
predictions = tf.where(predictions < 0.5, 0, 1)

The original behavior is happening because we already applied a sigmoid activation in the classification head's prediction layer while we were making the model for feature extraction.

Kindly find the gist for the reference which was providing the correct output after removing/commenting the above mentioned(TF.nn.sigmoid) line. Thank you!

@tilakrayal tilakrayal requested a review from a team as a code owner June 17, 2024 07:11
Copy link

Preview

Preview and run these notebook edits with Google Colab: Rendered notebook diffs available on ReviewNB.com.

Format and style

Use the TensorFlow docs notebook tools to format for consistent source diffs and lint for style:
$ python3 -m pip install -U --user git+https://github.com/tensorflow/docs

$ python3 -m tensorflow_docs.tools.nbfmt notebook.ipynb
$ python3 -m tensorflow_docs.tools.nblint --arg=repo:tensorflow/docs notebook.ipynb
If commits are added to the pull request, synchronize your local branch: git pull origin patch-16

@@ -1051,7 +1051,6 @@
"predictions = model.predict_on_batch(image_batch).flatten()\n",
"\n",
"# Apply a sigmoid since our model returns logits\n",
Copy link

Choose a reason for hiding this comment

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

Maybe you should remove this comment since we're not applying a sigmoid anymore ...

MarkDaoust
MarkDaoust previously approved these changes Jun 25, 2024
Copy link
Member

@MarkDaoust MarkDaoust left a comment

Choose a reason for hiding this comment

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

Yes, thanks!

@MarkDaoust MarkDaoust added the ready to pull Start merge process label Jun 25, 2024
@copybara-service copybara-service bot merged commit 940d94c into tensorflow:master Jun 26, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready to pull Start merge process
Projects
None yet
4 participants