I'm trying to import imageai
from imageai.Detection import VideoObjectDetection
but get error message below
ModuleNotFoundError: No module named 'keras.layers.advanced_activations'
My tensorflow version 2.9.1,
keras version 2.9.0,
keras-preprocessing version 1.1.2,
image ai version 2.1.5,
I installed the imageai via pip install imageai-2.0.2-py3-none-any.whl and download from here.
The following code is an example for calling several types of advanced activation, Try to call it by
from keras.layers import ELU, PReLU, LeakyReLU
The import works with keras version 2.9.0 as below.
from keras.layers import LeakyReLU
I encountered the same error today. Downgrading my keras to 2.1.0 and tensorflow to 2.2.0 got rid of the error.
I faced the same error. ModuleNotFoundError: No module named 'keras.layers.advanced_activations'
To solve this problem:
Try to install TensorFlow 2.8.2 which is compatible with Keras 2.8.0
pip install tensorflow==2.8.2
Please install imageai using this link or use below code as you must install few libraries before installing imageai.
pip install cython pillow>=7.0.0 numpy>=1.18.1 opencv-python>=4.1.2 torch>=1.9.0 --extra-index-url https://download.pytorch.org/whl/cpu torchvision>=0.10.0 --extra-index-url https://download.pytorch.org/whl/cpu pytest==7.1.3 tqdm==4.64.1 scipy>=1.7.3 matplotlib>=3.4.3 mock==4.0.3
pip install imageai --upgrade
then import VideoObjectDetection as below:
from imageai.Detection import VideoObjectDetection
Related
this is the code. im executing this using spyder. and tried many versions of tensorflow but unable to solve this
this is the error im getting. before i was gettng import error cannot import 'load_img'
I had a similar problem. I had tensorflow 2.6.0 installed but tensorflow-estimator 2.10.0. The problem was solved by downgrading tensorflow-estimator:
pip install --upgrade tensorflow-estimator==2.6.0
Download tensorflow before running your code.
pip install tensorflow
I'm trying to create object detection using tensorflow as an assignment.
ImportError: cannot import name 'dtensor' from 'tensorflow.compat.v2.experimental' (c:\Project\.venv\lib\site-packages\tensorflow\_api\v2\compat\v2\experimental\__init__.py)
I would appreciate any help!
I got the same error. I downgraded to Keras v2.6.0, which fixed the issue.
Hence, as of 16.05.2022, this seems to be caues by a bug in v2.9.*
To downgrade to v2.6.0, run:
!pip install keras==2.6.*
Please try again by upgrading the TensorFlow version to the latest version 2.9 and restart the kernel(runtime) to fix this issue.
!pip install tensorflow==2.9
#Or
!pip install --quiet --upgrade --pre tensorflow
For example:
import tensorflow as tf
from tensorflow.experimental import dtensor
print('TensorFlow version:', tf.__version__)
mesh_1d = dtensor.create_mesh([('x', 6)])#, devices=DEVICES)
print(mesh_1d)
Output:
TensorFlow version: 2.9.1
<tensorflow.dtensor.python.layout.Mesh object at 0x7f890d7ce690>
Please check this link for more details.
I have been trying to use the torch benchmark module for profiling the code. Verified that all required imports are in place:
import torch
import torchvision
import torch.utils.benchmark
Also, these are the versions installed:
torch -> 1.4.0
torchvision -> 0.2.1
tensorflow -> 1.12.0
tensorflow-gpu -> 1.12.0
tensorboard -> 2.5.0
But I still get error: ModuleNotFoundError: No module named 'torch.utils.benchmark' while importing torch.utils.benchmark. What could be the root cause?
Have you tried to upgrade torch? I see you are using 1.4.0 but currently 1.9.0 is available.
pip install torch --upgrade
I have tested import of modules as you describe with 1.9.0 and receive no errors.
I'm using python 3.8.2 , keras 2.3.1 and tensorflow 2.2.0rc4 .
just with the following code :
import keras
from keras.models import sequential
I have this error :
AttributeError: partially initialized module 'keras.backend' has no attribute 'eager' (most likely due to a circular import)
if I use :
import tensorflow
or
from tensorflow.keras import ....
new error :
AttributeError: partially initialized module 'tensorflow.python.framework.ops' has no attribute 'register_tensor_conversion_function' (most likely due to a circular import)
full traceback:
enter image description here
enter image description here
My suggestion is to reinstall the package. Sometimes this happens due to the installation problem.
Use the following code to do so
Uninstall tensorflow
pip uninstall tensorflow
Requires the latest pip
pip install --upgrade pip
To install keras as separate package
pip install Keras
Current stable release for CPU and GPU
pip install tensorflow
Try this and hope this helps you.
It's an install problem, most likely; K.eager was introduced in Keras 2.3.0 (and is included in Keras 2.3.1), so your Python interpreter is somehow reading code of 2.2.5 or earlier.
A possible culprit is an Anaconda mishap. First run conda uninstall keras. Then, in the anaconda3 directory, search "keras" and delete all results. Lastly, run conda install -c conda-forge keras, which should download version 2.3.1. You might need to run similar steps with TensorFlow (in fact, it's better you do, and first reinstall TensorFlow then Keras).
P.S., your code is probably from keras import Sequential, as sequential should error differently.
I want to run tensorflow for image recognition. I have followed all the steps for it and both keras and tensorflow are installed on my computer.
Steps in this post: https://github.com/OlafenwaMoses/ImageAI/
But when I try:
from imageai.Prediction import ImagePrediction
I keep getting the error:
from tensorflow.python.keras.preprocessing import image
ModuleNotFoundError: No module named 'tensorflow.python.keras'
I think the error comes from my installation of 'tensorflow'. When I tried the method:
pip3 install --upgrade tensorflow
I got the error:
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
So I used instead:
python3 -m pip install --upgrade https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.0-py3-none-any.whl
I got it from this post: TensorFlow not found using pip
My guess is that the first error drives me to the second, but I don't know how to fix any of them.
Any suggestions?
My code until the problem is:
import tensorflow
from imageai.Prediction import ImagePrediction
Try writing
from keras.preprocessing import image
Instead of
from tensorflow.python.keras.preprocessing import image
And do the same with all Keras calls.
Make sure you have the latest version of tensorflow (2.0)
import tensorflow as tf
print(tf.__version__)
from tensorflow.keras.preprocessessing.text import Tokenizer