I have a problem when I want to delete the last layer of InceptionV3 model from keras. Here’s the code I’m running:
from keras.src.applications.inception_v3 import InceptionV3
from keras.models import Model
model = InceptionV3(weights='imagenet')
model_new = Model(inputs=model.input, outputs=model.layers[-2].output)
When I run this code, I get the following error:
ModuleNotFoundError Traceback (most recent call last)
Cell In[90], line 2
1 # Tạo model mới, bỏ layer cuối từ inception v3
----> 2 model_new = Model(inputs=model.input, outputs=model.layers[-2].output)
File ~anaconda3envsmyenvlibsite-packageskerasenginetraining.py:193, in __new__(cls, *args, **kwargs)
File ~anaconda3envsmyenvlibsite-packageskerasenginetraining.py:195, in __new__(cls, *args, **kwargs)
File ~anaconda3envsmyenvlibsite-packageskerasutilsversion_utils.py:49, in __new__(cls, *args, **kwargs)
File ~anaconda3envsmyenvlibsite-packageskerasutilsgeneric_utils.py:1318, in __getattr__(self, item)
File ~anaconda3envsmyenvlibsite-packageskerasutilsgeneric_utils.py:1309, in _load(self)
File ~anaconda3envsmyenvlibimportlib__init__.py:127, in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
File <frozen importlib._bootstrap>:1030, in _gcd_import(name, package, level)
File <frozen importlib._bootstrap>:1007, in _find_and_load(name, import_)
File <frozen importlib._bootstrap>:984, in _find_and_load_unlocked(name, import_)
ModuleNotFoundError: No module named 'keras.engine.base_layer_v1'
I’m not sure why this is happening. I’ve tried reinstalling Keras and TensorFlow, but the issue persists. Any help would be greatly appreciated.
New contributor
thanh phan van is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.