Closed mrdbourke closed 11 months ago
There is a way to edit the efficientnet.py file directly to correct this issue, letting us use efficientnet with tf 2.10 and above. It is advised to create a backup of this file before proceeding with the changes.
That being out of the way, here are the steps:
x = layers.Rescaling(1.0 / tf.math.sqrt(IMAGENET_STDDEV_RGB))(x)
(it will be around line 367, depending on version, of course)x = layers.Rescaling( [1.0 / math.sqrt(stddev) for stddev in IMAGENET_STDDEV_RGB] )(x)
that's basically it! If you managed to do these steps correctly, you will now have gotten rid of this annoying error!
One extra info for Docker containers - if you work within the Docker container, you will likely have to install an editor first using apt-get install vim or apt-get install nano or whatever else you want to use.
thanks to Mik0ri in Discord for bringing this to my attention!
There is a bug in TensorFlow versions 2.10, 2.11 and 2.11. You need to upgrade tensorflow to the 2.13 version or downgrade to 2.9.
Here is the tensorflow issue link with the same problem. https://github.com/tensorflow/tensorflow/issues/61366
Hi all,
After much troubleshooting, I've found the best fix for tf.keras.applications.EfficientNetB0
problems is to simply upgrade to tf.keras.applications.efficientnet_v2.EfficientNetV2B0
.
You can see a full write-up of the fix here: https://github.com/mrdbourke/tensorflow-deep-learning/discussions/575
Update for August 2023
If you're using TensorFlow 2.10+, I've found the best fix for
tf.keras.applications.efficient.EfficientNetB0
problems is to simply upgrade totf.keras.applications.efficientnet_v2.EfficientNetV2B0
.You can see a full write-up of the fix here: https://github.com/mrdbourke/tensorflow-deep-learning/discussions/575
In short:
New:
Old:
If for some reason, you'd like to keep using
tf.keras.applications.efficientnet.X
models, keep reading below.If you're trying to save
tf.keras.applications.efficientnet.X
models in TensorFlow 2.10+, you may see the following issue:According to the Keras GitHub issues thread (see: https://github.com/keras-team/tf-keras/issues/383) this is an issue with one of the rescaling layers.
There are several solutions in the linked thread above, however, a consistent fix I've found (as of May 2023) is to use TensorFlow 2.9.0:
If you're using Google Colab, you can run the code at the top of your notebook and run the rest of Notebook 05: https://github.com/mrdbourke/tensorflow-deep-learning/blob/main/05_transfer_learning_in_tensorflow_part_2_fine_tuning.ipynb without errors.
I tried to run this gist which claims fixes in
tf-nightly(2.13.0-dev20230409)
, however, I found that the fix didn't work in a later versiontf-nightly(2.14.0-dev20230520)
.Hopefully it gets fixed in future versions of TensorFlow.
See a thread about possible fixes here: https://github.com/mrdbourke/tensorflow-deep-learning/issues/544
Another alternative if you're using a later version of TensorFlow (2.10+) may be to try another model from
tf.keras.applications.efficientnet_v2
.