-
Notifications
You must be signed in to change notification settings - Fork 74k
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
TFLite 2.16.1 conversions fail with "AttributeError: 'Sequential' object has no attribute '_get_save_spec'" #63867
Comments
|
Hi @schwefeljm, I am trying to reproduce the code meanwhile I encountered some other error. Is it `args = argparser(). Please provide complete reproducible code/link to debug the issue. Thank You |
I updated to code to remove the depency on 'argsparser()' The dataset I used is from: https://www.kaggle.com/datasets/gpiosenka/100-bird-species Though, I expect it work on any dataset. Jason |
I went through and forced 'tf.keras.models.Sequential' and it had no effect. Thank you for the suggestions, though. Jason |
I was able to replicate on tf-nightly as well as 2.16.1. gist, I reduced the reproducible sample to what mattered i.e. the training process is actually irrelevant. This appears to happen when using Keras with the TFLite converter in 2.16.1 onward. Hi @haozha111, can you please take a look? |
I'm experiencing the same error here
Is it gonna help if I downgrade to an older version of Tensorflow? |
For me it did. |
Hi @Takudzwamz, it seems like 2.15 does not exhibit this behavior currently. |
@pkgoogle I downgraded to 2.15 and it worked, thanks. |
Referencing legacy Keras worked for me: https://blog.tensorflow.org/2024/03/whats-new-in-tensorflow-216.html |
As @Lerxp stated, using Legacy Keras is the preferred workaround for now:
|
I'm having the same issue, but Legacy Keras isn't working either. |
Hi @gusbernard, do you have a notebook or code snippet to share? Additionally have you tried using 2.15 for now? Thanks for any information you can provide. |
I met the same problem when I using tensorflow2.6.1 in python3.12.3, I tried to downgrade tensorflow to 2.15.0, while it not support python3.12.3. I am trying to downgrade python now... |
I have the same issue when trying to convert a keras model to TFLite exactly like in the docs.
|
I used model.export() to deal with the problem.
|
Hi @schwefeljm, have you heard of AI-Edge-Torch?, you can find more information here: googleblog. You will not run into this issue if you go this route. I have created a script for converting your model here: import torch
import torch.nn as nn
import ai_edge_torch
class CustomCVModel(nn.Module):
def __init__(self, num_classes, img_height, img_width, activation1=nn.SiLU, activation2=nn.ELU):
super().__init__()
self.feature_extractor = nn.Sequential(
nn.Conv2d(3, 32, kernel_size=3, padding="same"),
activation1(),
nn.MaxPool2d(2),
nn.Conv2d(32, 48, kernel_size=3, padding="same"),
activation2(),
nn.MaxPool2d(2),
nn.Conv2d(48, 64, kernel_size=3, padding="same"),
activation1(),
nn.MaxPool2d(2),
nn.Dropout(0.15),
nn.Flatten(),
)
self.classifier = nn.Sequential(
nn.Linear(64 * (img_height // 8) * (img_width // 8), 128),
activation2(),
nn.Linear(128, num_classes)
)
def forward(self, x):
x = self.feature_extractor(x)
x = self.classifier(x)
return x
img_height = 128
img_width = 128
model = CustomCVModel(1000, img_height, img_width, nn.SiLU, nn.ELU)
sample_inputs = (torch.randn(1, 3, img_height, img_width),)
edge_model = ai_edge_torch.convert(model.eval(), sample_inputs)
edge_model.export("custom_cv_model.tflite") You will still need to modify your training code but I have tested this and the conversion does work w/o issue. If you want to, you can actually try visualizing the result in model-explorer as well. Please try them out and let us know if this resolves your issue. If you still need further help, feel free to open a new issue at the respective repo. |
This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. |
|
I have the same issue with a Keras 3 model saved into
This is the error message:
|
1. System information
Debian 13 - Trixie
pip
2.16.0-rc0 & 2.16.1
I am brand new to TensorFlow and welcome any suggestions.
I tested the exact same code on 2.15.0.post1 and 2.16.x. It runs on 15 and errors out on 16
2. Code
Provide code to help us reproduce your issues using one of the following options:
Option B: Paste your code here or provide a link to a custom end-to-end colab
(You can paste links or attach files by dragging & dropping them below)
3. Failure after conversion
Conversion completely fails with "AttributeError: 'Sequential' object has no attribute '_get_save_spec'. Did you mean: '_set_save_spec'?" See below for complete log and traceback.
I have had to revert to 2.15.0.post1 to get model to convert and save as TFLite.
5. (optional) Any other info / logs
The text was updated successfully, but these errors were encountered: