-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Notebook 05: load_weights results in "Incompatible tensor with shape (1280, 10)..." #544
Comments
Hi @ivanthecrazy, Investigating this issue myself. I'm going through the following resources:
Looks like it's an issue with newer versions of TensorFlow and My current solution is installing TensorFlow 2.9.0 (as suggested by the links above) and running it from there. For example: # Install TensorFlow 2.9.0 to avoid issues (later versions may work)
# -U stands for "update" and "-q" stands for "quiet"
!pip install -U -q tensorflow==2.9.0
import tensorflow as tf
print(f"TensorFlow version: {tf.__version__}") I will make sure this works and investigate it further if something is wrong. I'll post another comment here once I've fixed the notebook: https://github.com/mrdbourke/tensorflow-deep-learning/blob/main/05_transfer_learning_in_tensorflow_part_2_fine_tuning.ipynb |
Update: I've confirmed that running notebook 05 works end-to-end with TensorFlow 2.9.0 (as per the links above). Install TensorFlow 2.9.0 with: # Install TensorFlow 2.9.0 to avoid issues (later versions may work)
# -U stands for "update" and "-q" stands for "quiet"
!pip install -U -q tensorflow==2.9.0
import tensorflow as tf
print(f"TensorFlow version: {tf.__version__}") I'm not quite sure what's happening with later versions (e.g. 2.10.0+), the issues above seem to be long standing. The notebook code has been updated to reflect installing TensorFlow 2.9.0 at the start. See the updated code here and let me know how it goes: https://github.com/mrdbourke/tensorflow-deep-learning/blob/main/05_transfer_learning_in_tensorflow_part_2_fine_tuning.ipynb |
I had the same problem. I can verify that the new Daniel's notebook (tf version 2.9.0) works fine. Furthermore all these “Model failed to serialize as JSON” warnings, while fitting the various models have been disappeared. |
Hi @filipposkar , glad to hear you got it fixed! Looks like this should also be fixed further in upcoming versions of TensorFlow (e.g. 2.13+). For now, it looks like TensorFlow 2.9.0 works. See this comment here: keras-team/tf-keras#383 |
Update: looks like TensorFlow 2.9.0 is still the most stable here, see: #553 TL;DR tried |
Thank you @mrdbourke |
i have issiue with changing verion of tensorflow, '!pip install -U -q tensorflow==2.9.0' doesn't work |
Here is my temporary work around. The contributing factor seems to be stemming from line of code at [29] from @mrdbourke 05_transfer_learning where the install of TF is upgrading to latest version of TF, however, some of the dependencies are deprecated in the latest version of TF since we are working with tensorflow 2.9.0.
**(notes on protobuf below as the dependency is incompatible; however, the results have compiled the same as predicted.)
The Protobuf dependency used in TensorFlow is used to serialize and deserialize data. This means that it can be used to convert data from one format to another, such as from a Python object to a binary file. This is useful for TensorFlow because it allows models to be saved and loaded easily, and it also allows for communication between different TensorFlow components. Specifically, Protobuf is used in TensorFlow for the following purposes:
Overall, the Protobuf dependency used in TensorFlow is a valuable tool that allows TensorFlow models to be saved, loaded, and communicated with other components. It is a versatile data format that is widely used in the industry, and it makes TensorFlow more accessible to other libraries and frameworks. - Source: Bard |
Your version of protobuf will most likely result in errors with tensorflow-datasets
|
Hi @mrdbourke . I run the line suggested,
But it showed this.
|
Did you restart the runtime? Iirc tensorflow tells you it will only take effect after restarting it |
Hi all, After much troubleshooting, I've found the best fix for You can see a full write-up of the fix here: #575 |
It worked for me if i recompile the model before loading weights it may be because the model was training and it changed some layers and the tensor shape was no longer compatible |
@talha-0 Great catch! Thank you for the update! |
I got the same issue with trying to customize my model for Image Classification. |
I tried the solution here but it doesn't seem to work for me |
Oh dam! What error are you getting now? Did you try to reference the updated Notebook 05? See: https://github.com/mrdbourke/tensorflow-deep-learning/blob/main/05_transfer_learning_in_tensorflow_part_2_fine_tuning.ipynb |
I recompiled the model:
and got rid of .ckpt from the checkpoint_path: |
Using |
getting the same error in 2024 as well "ValueError: Received incompatible tensor with shape (1280, 10) when attempting to restore variable with shape (1, 1, 1152, 48) and name Adam/m/block6h_se_reduce/kernel:0.", i tried downloading the 2.9 version but it doesnt work, any help @mrdbourke? |
Actually this issue caused because model is recompiling between weights are saved and loaded. |
When creating
model_2
and trying to load the weights byI'm getting the following error:
I tried to download the notebook from this repo, but have the same result.
The text was updated successfully, but these errors were encountered: