I am trying to play around with a custom object detection model that builds of a pretrained model. All I want is for my model is to detect a specific logo in a picture. The problem is, the guide that I am following is having problems with the libraries.
import tensorflow as tf
from imageai.Detection.Custom import DetectionModelTrainer
trainer = DetectionModelTrainer()
trainer.setModelTypeAsYOLOv3()
trainer.setDataDirectory(data_directory="/content/drive/MyDrive/Logo_Model2/")
trainer.setTrainConfig(object_names_array=["logo"], batch_size=4, num_experiments=122, train_from_pretrained_model="/content/drive/MyDrive/pretrained-yolov3.h5")
trainer.trainModel()
My error is coming when I import imageai.Detection.Custom import DetectionModelTrainer. I am doing this on google colab and I checked the versions and they seem to be all up to date.
ModuleNotFoundError: No module named 'tensorflow.keras'
Any ideas? I have looked around stack for similar problems yet I haven't been able to resolve my issue. It doesn't seem to be a tensorflow problem since I am able to build my models just fine until I add imageai.
Seems to be an issue with the latest tensorflow==2.8.0. git issue
For now, you can revert back to the older version of tensorflow
pip install tensorflow==2.7
And upgrade imageAI :
pip install imageai --upgrade
Related
I am using some code based on Tensorflow 1.x and I am using the latest version of TensorFlow (2.8).
I have run tf_upgrade_v2 (following these migration instructions) on the python file to generate a new compatible file.
However, this doesn't work with the line of code; from TensorFlow.contrib import training as contrib_training.
Getting the error ModuleNotFoundError: No module named 'tensorflow.contrib'
I understand that contrib has been deprecated, so the modules have been moved around. But I haven't been able to find where this training module has moved to or if it has been deleted. I have looked for information first on this document on the status of tf.contrib and after this spreadsheet on TF2.0 Symbols map and haven't found any information on the fate of this training module;
I have also tried looking around TensforFlow/tf.compat.v1 but with no success.
Of course uninstalling this version of TensorFlow and instead installing an earlier version is an option. But not an option that I am overly keen on.
I feel like I may be missing something fairly obvious here...
Thanks in advance!!
The reason behind this error - ModuleNotFoundError: No module named 'tensorflow.contrib' is, tf.contrib has been deprected to use in Tensorflow 2.x. You can use Tensorflow Addons or Tensorflow Slim in the pace of tf.contrib api.
Please check this link for more details.
I am trying to implement https://github.com/ec-jrc/GHS-S2Net this project (in google colab). A week ago it was working by installing the requirements:
!pip install tensorflow-gpu==2.0.0
!pip install Keras==2.3.1
Unfortunately, from this week it is showing me module 'tensorflow_core.compat.v2' has no attribute '__internal__' for import keras.
Ok, I wanted to try with the latest versions of tensor and keras (both 2.5.0), but now I am getting following error:
AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'slice'
How can I handle this?
AttributeError: module 'tensorflow.python.keras.backend' has no
attribute 'slice'
It looks like an installation issue. Please try to uninstall and reinstall Keras
pip uninstall keras
pip install keras --upgrade
module 'tensorflow_core.compat.v2' has no attribute 'internal'
Due to incompatibility between Tensorflow and Keras you get this issue.
As mentioned above, if you upgrade to latest keras version and import keras or import keras from tensorflow as from tensorflow import keras will resolve this issue. For more information you can refer here.
Keras.backend doesnt have a slice operation. Instead, you can go to the location where the crf.py file is stored locally on your machine (this you can find mentioned in the error dialogue, i.e.(myenv\Lib\site-packages\keras_contrib\layers\crf.py) and do the following:
add the line --> import tensorflow as tf.
Goto line number where it is mentioned K.slice,
It is in the function: def step(self, input_energy_t, states, return_logZ=True.
You can do a search for "slice".
Then replace K.slice by tf.slice.
Restart the jupyter notebook session. This should work.
Change the line 463 in crf.py as import tensorflow as tf; tf.slice. Then save the crf.py.
I tried running this command but i get erros that i dont have tenserflow 2.2 or higher. But I checked and I have the correct version of tenserflow. I also did pip3 install keras command
I know for a fact that all of the code is correct because it worked for my teacher the other day and nothing has changed. I just need to run his commands but i keep running into problems
I am doing this course following everything he does in a recorded video so there must be no issue there but for some reason it just doesn't work
just install tensorflow as requested in the last line of the error message: pip install tensorflow. It is needed as backend for Keras.
Also, since keras is part of tensorflow now, I recommend to write imports as from tensorflow.keras.[submodule name] import instead of from keras.[submodule name] import
I have been getting multiple errors which are due to conflicts in the TensorFlow version installed in my system and the version used to write the code in Tensorflow API.
I am using python 3.6.7 and Tensorflow 2.0 to get started with the code https://github.com/tensorflow/models/blob/master/research/deeplab/g3doc/installation.md
But I am getting several errors :
flags = tf.app.flags
AttributeError: module 'tensorflow' has no attribute 'app.
As I am using 2.0 , I replaced tf.app.flags with tf.compat.v1.flags.
from tensorflow.contrib import slim as contrib_slim
ModuleNotFoundError: No module named 'tensorflow.contrib'
I am not able to solve the second one.
Can I get help to know which python and tensorflow version should be used to run DeepLab v3+?
You should use the Tensorflow version 1.x to run the DeepLabV3+ model because it uses a session to run and also the slim library which is based on the TensorFlow 1.x. And so your two problems can be solved as:
Do not need to replace tf.app.flags with tf.compat.v1.flags.
To run DeepLabV3+ model, you need to put deeplab and slim folder in a folder (deeplab_slim),
and export them by running following export commands from this parent folder (deeplab_slim):
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/deeplab
I am currently following the tutorial by EdjeElectronics: https://github.com/EdjeElectronics/TensorFlow-Object-Detection-API-Tutorial-Train-Multiple-Objects-Windows-10#1-install-anaconda-cuda-and-cudnn and I am in the step no:6. Run the Training. I had certain errors before but I cleared them so I have generated the TFrecords and I am stuck here.image
If there are any files that I need to attach for your convenience pls let me know.
The contrib attribute has moved out of Tesnsorflow version 2.
To use version 1, replace the 'import tensorflow as tf' line as follows:
#import tensorflow as tf
import tensorflow.compat.v1 as tf #using v1 of tf
Actually, when looking at this link - https://www.tensorflow.org/guide/migrate, there is a line -
It is still possible to run 1.X code, unmodified (except for contrib), in TensorFlow 2.0
The link goes to page - https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md which explains what happened to each contrib module.
You can try to migrate code to Tensorflow 2 or whatever version you are using.
Another alternative is to uninstall your Tensorflow installation and install Tensorflow with version 1.x.