Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module 'keras.engine' #2993

Closed
lrpalmer27 opened this issue Sep 28, 2023 · 13 comments · May be fixed by #2997
Closed

No module 'keras.engine' #2993

lrpalmer27 opened this issue Sep 28, 2023 · 13 comments · May be fixed by #2997

Comments

@lrpalmer27
Copy link

trying to run the demo file to get started. Running into this error in the mrcnn/model.py file. Has anyone seen this before? I cant seem to find keras.engine to install.

21 import keras.backend as K
 22 import keras.layers as KL

---> 23 import keras.engine as KE
24 import keras.models as KM
26 from mrcnn import utils

ModuleNotFoundError: No module named 'keras.engine'

@453875726
Copy link

Have you found how to solve it?

@lrpalmer27
Copy link
Author

lrpalmer27 commented Oct 10, 2023

I did not solve this issue directly. I think it was regarding an installation error. I made a fork of an MRCNN repo compatible with TF2.0.0+ which works, I have included extra details on all dependency versions I am running (winOS).
https://github.com/lrpalmer27/Mask-RCNN-TF2/tree/iceShipBranch

@Rial-Ali
Copy link

This problem is caused by Keras version, the default requirement.txt does not detect version so you should specify version.
here you can find the edited requirement.txt

@AvivTahar
Copy link

It doesnt solve keras.engine module problem, unfortunately (for me on google colab)

@Rial-Ali
Copy link

What is the problem? can you give me more information? @AvivTahar

@AlicanAKCA
Copy link

I've faced with the same error as well.

You can run these commands which are in the readme.md file. Don't forget to try on colab.

Installation
Clone this repository

Install dependencies

pip3 install -r requirements.txt
Run setup from the repository root directory

 python3 setup.py install
 
python3 samples/coco/coco.py train --dataset= /content/Mask_RCNN/data/ --model=coco

The whole error traceback is here:

/content/Mask_RCNN
/usr/local/lib/python3.10/dist-packages/mask_rcnn-2.1-py3.10.egg/mrcnn/model.py:2359: SyntaxWarning: "is" with a literal. Did you mean "=="?
/usr/local/lib/python3.10/dist-packages/mask_rcnn-2.1-py3.10.egg/mrcnn/model.py:2359: SyntaxWarning: "is" with a literal. Did you mean "=="?
2023-12-02 14:32:17.879174: E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:9342] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2023-12-02 14:32:17.879225: E tensorflow/compiler/xla/stream_executor/cuda/cuda_fft.cc:609] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2023-12-02 14:32:17.879261: E tensorflow/compiler/xla/stream_executor/cuda/cuda_blas.cc:1518] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2023-12-02 14:32:17.887311: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-12-02 14:32:19.010510: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
Traceback (most recent call last):
  File "/content/Mask_RCNN/samples/coco/coco.py", line 56, in <module>
    from mrcnn import model as modellib, utils
  File "/usr/local/lib/python3.10/dist-packages/mask_rcnn-2.1-py3.10.egg/mrcnn/model.py", line 23, in <module>
ModuleNotFoundError: No module named 'keras.engine'

@Rial-Ali
Copy link

Rial-Ali commented Dec 4, 2023

This problem is caused by Keras version, the default requirement.txt does not detect version so you should specify version. here you can find the edited requirement.txt

Did you try to specify the Keras version?!!!

@benjamincerf57
Copy link

Hello,
I had the same problem with keras.engine, then updated with specified the versions you were mentionning to, and now I have an other ImportError:


ImportError Traceback (most recent call last)
Cell In[1], line 16
14 sys.path.append(ROOT_DIR) # To find local version of the library
15 from mrcnn import utils
---> 16 import mrcnn.model as modellib
17 from mrcnn import visualize
18 # Import COCO config

File c:\Users\benja\anaconda3\Lib\site-packages\mask_rcnn-2.1-py3.11.egg\mrcnn\model.py:20
18 import numpy as np
19 import tensorflow as tf
---> 20 import keras
21 import keras.backend as K
22 import keras.layers as KL

File c:\Users\benja\anaconda3\Lib\site-packages\keras_init_.py:4
1 from future import absolute_import
3 from . import utils
----> 4 from . import activations
5 from . import applications
6 from . import backend

File c:\Users\benja\anaconda3\Lib\site-packages\keras\activations.py:6
4 from . import backend as K
...
---> 15 from collections import Iterable
16 from .utils.generic_utils import Progbar
17 from . import backend as K

ImportError: cannot import name 'Iterable' from 'collections' (c:\Users\benja\anaconda3\Lib\collections_init_.py)

@Rial-Ali
Copy link

ImportError: cannot import name 'Iterable' from 'collections' (c:\Users\benja\anaconda3\Lib\collections__init__.py)

Sorry to hear that.
But I think, your Python Version is wrong.
check your version and downgrade it to 3.4.

@zimoradi76
Copy link

trying to run the demo file to get started. Running into this error in the mrcnn/model.py file. Has anyone seen this before? I cant seem to find keras.engine to install.

21 import keras.backend as K
 22 import keras.layers as KL

---> 23 import keras.engine as KE 24 import keras.models as KM 26 from mrcnn import utils

ModuleNotFoundError: No module named 'keras.engine'

hello, did you solve this issue? how?

@coderboyisongithub
Copy link

how to solve this on google colab?

@LiuxinYLX
Copy link

LiuxinYLX commented Jun 25, 2024

Hello everyone, I think I have solved this problem. My system is Linux. The version installed of Python is 3.8.19.
I installed :

requirements.txt
pip install keras==2.3.1 tensorflow==1.15.0
pip install protobuf==3.20.3
pip install pycocotools
pip install h5py==2.10.0

You could have a try!

trying to run the demo file to get started. Running into this error in the mrcnn/model.py file. Has anyone seen this before? I cant seem to find keras.engine to install.

21 import keras.backend as K
 22 import keras.layers as KL

---> 23 import keras.engine as KE 24 import keras.models as KM 26 from mrcnn import utils
ModuleNotFoundError: No module named 'keras.engine'

hello, did you solve this issue? how?

@gamugamu
Copy link

gamugamu commented Jul 2, 2024

Hello, I think the dependency are still buggy. So I made a clean install like your project asked:

Python 3.4, TensorFlow 1.3, Keras 2.0.8 and other common packages listed in requirements.txt.

For my part, I had to change protobuf==3.20 : seems missing.

ERROR: Could not find a version that satisfies the requirement **protobuf==3.20** (from versions: 2.0.0b0, 2.0.3, 2.3.0, 2.4.1, 2.5.0, 2.6.0, 2.6.1, 3.0.0a2, 3.0.0a3, 3.0.0b1, 3.0.0b1.post1, 3.0.0b1.post2, 3.0.0b2, 3.0.0b2.post1, 3.0.0b2.post2, 3.0.0b3, 3.0.0b4, 3.0.0, 3.1.0, 3.1.0.post1, 3.2.0rc1, 3.2.0rc1.post1, 3.2.0rc2, 3.2.0, 3.3.0, 3.4.0, 3.5.0.post1, 3.5.1, 3.5.2, 3.5.2.post1, 3.6.0, 3.6.1, 3.7.0rc2, 3.7.0rc3, 3.7.0, 3.7.1, 3.8.0rc1, 3.8.0, 3.9.0rc1, 3.9.0, 3.9.1, 3.9.2, 3.10.0rc1, 3.10.0, 3.11.0rc1, 3.11.0rc2, 3.11.0, 3.11.1, 3.11.2, 3.11.3, 3.12.0rc1, 3.12.0rc2, 3.12.0, 3.12.1, 3.12.2, 3.12.4, 3.13.0rc3, 3.13.0, 3.14.0rc1, 3.14.0rc2, 3.14.0rc3, 3.14.0, 3.15.0rc1, 3.15.0rc2, 3.15.0, 3.15.1, 3.15.2, 3.15.3, 3.15.4, 3.15.5, 3.15.6, 3.15.7, 3.15.8, 3.16.0rc1, 3.16.0rc2, 3.16.0, 3.17.0rc1, 3.17.0rc2, 3.17.0, 3.17.1, 3.17.2, 3.17.3, 3.18.0rc1, 3.18.0rc2, 3.18.0, 3.18.1, 3.18.3, 3.19.0rc1, 3.19.0rc2, 3.19.0, 3.19.1, 3.19.2, 3.19.3, 3.19.4, 3.19.5, **3.19.6, 4.0.0rc1**, 4.0.0rc2, 4.21.0rc1, 4.21.0rc2, 4.21.0)
**ERROR: No matching distribution found for protobuf==3.20**

So I Switched to protobuf 3.19.6
.
Python 3.4 is no longer maintained and doesn't work with pip3.

I Had to install pycocotools too. It is asked in the demo (# Mask R-CNN Demo). Installed pycocotools-2.0.7.

I post the correct version (who worked for me) on this thread since it's related to requirement.txt / version mismatch.

So the correct version for me is :
Python 3.9.6 (tested first with 3.9.15 and didn't work when load_weights() -> str encode utf8)
tensorflow==1.3.0 like you suggested
keras==2.1.2 for me. (havent retested with Keras 2.0.8 cause of lazyness)

here my requirment.txt:

numpy
scipy
Pillow
cython
matplotlib
scikit-image
**tensorflow==1.3.0**
protobuf==3.19.6
**keras==2.1.2**
h5py==2.10.0
opencv-python
h5py
imgaug
IPython[all]
**pycocotools==2.0.7**

I think you should do an image docker with the repo with the correct python version and the requirment.txt file with the strict version.

Beside that, great project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants