Skip to content

Commit fc340b9

Browse files
Update import statement in mobilevit tutorial for TF>=2.13v (#1546)
* Update import statement in mobilevit tutorial for TF>=2.13v The mobile vit tutorial will break due to import statement which was changed from Tf2.13V onwards.This works fine upto Tf2.12 versions. Hence I changed the import statement to make it work for Tf2.13 and higher versions. Also added a note regarding this to make users aware of how to change the import for TF<=2.12 versions. * Update mobilevit.py * Correcting formatting errors in new code of mobilevit.py Correcting formatting errors in new code of mobilevit.py * Update import statement in mobilevit tutorial for TF>=2.13v The mobile vit tutorial will break due to import statement which was changed from Tf2.13V onwards.This works fine upto Tf2.12 versions. Hence I changed the import statement to make it work for Tf2.13 and higher versions. Also added a note regarding this to make users aware of how to change the import for TF<=2.12 versions. * Update mobilevit.ipynb Added Note in new line. * Update import statement in mobilevit.md tutorial for TF>=2.13v The mobile vit tutorial will break due to import statement which was changed from Tf2.13V onwards.This works fine upto Tf2.12 versions. Hence I changed the import statement to make it work for Tf2.13 and higher versions. Also added a note regarding this to make users aware of how to change the import for TF<=2.12 versions.
1 parent d6b54b7 commit fc340b9

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

examples/vision/ipynb/mobilevit.ipynb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
"MobileViT as a general-purpose mobile-friendly backbone for different image recognition\n",
3535
"tasks. Their findings suggest that, performance-wise, MobileViT is better than other\n",
3636
"models with the same or higher complexity ([MobileNetV3](https://arxiv.org/abs/1905.02244),\n",
37-
"for example), while being efficient on mobile devices."
37+
"for example), while being efficient on mobile devices.\n",
38+
"\n",
39+
"Note: This example should be run with Tensorflow 2.13 and higher."
3840
]
3941
},
4042
{
@@ -56,7 +58,9 @@
5658
"source": [
5759
"import tensorflow as tf\n",
5860
"\n",
59-
"from keras.applications import imagenet_utils\n",
61+
"from keras.src.applications import imagenet_utils\n",
62+
"# For versions <TF2.13 change the above import to:\n",
63+
"# from keras.applications import imagenet_utils\n",
6064
"from tensorflow.keras import layers\n",
6165
"from tensorflow import keras\n",
6266
"\n",
@@ -540,4 +544,4 @@
540544
},
541545
"nbformat": 4,
542546
"nbformat_minor": 0
543-
}
547+
}

examples/vision/md/mobilevit.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,19 @@ tasks. Their findings suggest that, performance-wise, MobileViT is better than o
2727
models with the same or higher complexity ([MobileNetV3](https://arxiv.org/abs/1905.02244),
2828
for example), while being efficient on mobile devices.
2929

30+
Note: This example should be run with Tensorflow 2.13 and higher.
31+
3032
---
3133
## Imports
3234

3335

3436
```python
3537
import tensorflow as tf
3638

37-
from keras.applications import imagenet_utils
39+
from keras.src.applications import imagenet_utils
40+
# For versions <TF2.13 change the above import to:
41+
# from keras.applications import imagenet_utils
42+
3843
from tensorflow.keras import layers
3944
from tensorflow import keras
4045

@@ -840,4 +845,4 @@ open("mobilevit_xxs.tflite", "wb").write(tflite_model)
840845
To learn more about different quantization recipes available in TFLite and running
841846
inference with TFLite models, check out
842847
[this official resource](https://www.tensorflow.org/lite/performance/post_training_quantization).
843-
You can use the trained model hosted on [Hugging Face Hub](https://huggingface.co/keras-io/mobile-vit-xxs) and try the demo on [Hugging Face Spaces](https://huggingface.co/spaces/keras-io/Flowers-Classification-MobileViT).
848+
You can use the trained model hosted on [Hugging Face Hub](https://huggingface.co/keras-io/mobile-vit-xxs) and try the demo on [Hugging Face Spaces](https://huggingface.co/spaces/keras-io/Flowers-Classification-MobileViT).

examples/vision/mobilevit.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
tasks. Their findings suggest that, performance-wise, MobileViT is better than other
2323
models with the same or higher complexity ([MobileNetV3](https://arxiv.org/abs/1905.02244),
2424
for example), while being efficient on mobile devices.
25+
26+
Note: This example should be run with Tensorflow 2.13 and higher.
2527
"""
2628

2729
"""
@@ -30,7 +32,10 @@
3032

3133
import tensorflow as tf
3234

33-
from keras.applications import imagenet_utils
35+
from keras.src.applications import imagenet_utils
36+
37+
# For versions <TF2.13 change the above import to:
38+
# from keras.applications import imagenet_utils
3439
from tensorflow.keras import layers
3540
from tensorflow import keras
3641

0 commit comments

Comments
 (0)