-
Notifications
You must be signed in to change notification settings - Fork 74.2k
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
Efficientnet B7 classification conversion from tf to tflite fails tflite imagenet evaluation test #60053
Comments
@suyash-narain Thank you ! |
Hi, i tried to convert the model using if i use the below method:
the input shape becomes (1,600,600,3) as desired, and has the output shape (1,1000). The official ImageNetLabels.txt available at https://storage.googleapis.com/download.tensorflow.org/data/ImageNetLabels.txt has total of 1001 labels ranging from (0-1000). So in that way, the output shape for this model should be (1,1001). When I run it against tflite imagenet evaluation tool, i get the same error I get similar error results if i use |
@suyash-narain Thank you! |
@tiruk007 Please find the detailed steps I exercised towards building the provided tflite imagenet evaluation tool:
|
Sorry for the delayed response. As the tool for evaluation is based on ILSVRC 2012 task, the classes with shape [1,1001] are only accepted for the evaluation. The tensorflow hub provides modules trained on ImageNet (ILSVRC-2012-CLS) which return the output shapes as Please find the list of models here. Thanks. |
Hi @pjpratik
i get output model shape as [1.1000]. I run this model against imagenet labels having 1000 classes from 1-1000 (removing 0-background), and it works. Same way, if i run efficientnetlite4 downloaded from https://tfhub.dev/tensorflow/efficientnet/lite4/classification/2, and run it against imagenet labels having 1000 classes from 1-1000 after removing 0-background class, it still works. thanks
|
Hi @suyash-narain Thanks for the clarification. Sorry for the delayed response. I was able to reproduce this issue. Please find the screenshot here. @sachinprasadhs Could you please look into this? Thanks. |
Hi @suyash-narain , we're wondering if you may be able to resolve your issue by using AI-Edge-Torch, you can find more information here: googleblog. I have actually created a simple script for converting your efficientnet_b7 model here and verified the input shape of the generated tflite model: import ai_edge_torch
import torch
import torchvision
efficientnet_model = torchvision.models.efficientnet_b7(pretrained=True)
sample_inputs = (torch.randn(1, 3, 600, 600),)
edge_model = ai_edge_torch.convert(efficientnet_model.eval(), sample_inputs)
edge_model.export("efficientnet_model_b07.tflite") 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. |
This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further. |
System information
provided in TensorFlow): No
happens on a mobile device: No
Describe the problem
I am trying to convert efficientnet_b7_classification model available in tfhub: https://storage.googleapis.com/tfhub-modules/tensorflow/efficientnet/b7/classification/1.tar.gz to tflite
I use the below code snippet to convert the saved model to tflite:
on visualizing the model on netron, i saw that the input to the model is of shape (1,1,1,3). whereas, the input to efficientnet_b7 is 600x600. So the converted model should have the shape (1,600,600,3), but i don't see this.
The output of the model is of the shape (1,1000).
But on visualizing the model, i still see the input shape as (1,1,1,3), and output shape is (1,1000). The model has been trained on imagenet so output shape should be fine with the label file consisting of 1000 labels starting from 1-1000 instead of 0-1000 which includes the dummy as well.
so from my labelfile, i removed the dummy, and it then used the same labelfile to evaluate the tflite model using the imagenet_image_classification run_eval binary. On running it against the converted tflite model, i get the below error log, which seemingly says that the model output shape is wrong. What is the correct way to go about converting and testing efficientnet_b7 model?
The output shape of mobilenets is (1,1001), whereas that of efficientnets is (1,1000) even though both are trained on imagenet dataset. why is that so?
thanks!
Source code / logs
The text was updated successfully, but these errors were encountered: