Reputation: 178
I am trying to use ImageAI’s model training to train an AI model.
This is the code:
from imageai.Prediction.Custom import ModelTraining
model_trainer = ModelTraining()
model_trainer.setModelTypeAsResNet()
model_trainer.setDataDirectory("idenprof")
model_trainer.trainModel(num_objects=2, num_experiments=3, enhance_data=True,
batch_size=32, show_network_summary=True)
This is the error I get when running:
Traceback (most recent call last):
File ".../FirstTraining.py", line 1, in <module>
from imageai.Prediction.Custom import ModelTraining
File ".../lib/python2.7/site-packages/imageai/Prediction/Custom/__init__.py", line 4, in <module>
from ..DenseNet.densenet import DenseNetImageNet121
File ".../PycharmProjects/bonez/venv/lib/python2.7/site-packages/imageai/Prediction/DenseNet/densenet.py", line 21, in <module>
from tensorflow.python.keras.utils import convert_all_kernels_in_model
ImportError: cannot import name convert_all_kernels_in_model
I have searched all over but I could not find the same issue or a way to solve the problem. I have the following dependencies installed: Tensorflow, OpenCV, Keras, and ImageAI.
Upvotes: 4
Views: 9842
Reputation: 1572
Update: It turns out ImageAI does not support Tensorflow 2 yet. This issue does not happen with following tensorflow version: pip install tensorflow==1.15.2
I had the same issue and resolved it by replacing all tensorflow.python.keras
imports with tensorflow.keras
in ImageAI library. After this, from imageai.Prediction.Custom import ModelTraining
import works fine.
If you want to follow, there is an open issue for problem in ImageAI: https://github.com/OlafenwaMoses/ImageAI/issues/494
Upvotes: 6