D
D
Daniel24112021-12-24 20:24:39
Python
Daniel2411, 2021-12-24 20:24:39

ImportError: cannot import name 'BatchNormalization' from 'keras.layers.normalization' (C:\Users\HP\AppData\Roaming\Python\Python39\site-packages\ker?

Good afternoon! I wrote the code for the video (link to the video, if necessary https://www.youtube.com/watch?v=Uj4O2_dwRiA ), but when I run it, I get an error

Traceback (most recent call last):
  File "C:\Users\HP\Desktop\python\__pycache__\parsing\musik\test.py", line 1, in <module>
    from imageai.Detection import ObjectDetection
  File "C:\Users\HP\AppData\Roaming\Python\Python39\site-packages\imageai\Detection\__init__.py", line 17, in <module>
    from imageai.Detection.YOLOv3.models import yolo_main, tiny_yolo_main
  File "C:\Users\HP\AppData\Roaming\Python\Python39\site-packages\imageai\Detection\YOLOv3\models.py", line 8, in <module>
    from keras.layers.normalization import BatchNormalization
ImportError: cannot import name 'BatchNormalization' from 'keras.layers.normalization' (C:\Users\HP\AppData\Roaming\Python\Python39\site-packages\keras\layers\normalization\__init__.py)

Something related to modules, but I did not understand. I ask for your help.

The code itself:
from imageai.Detection import ObjectDetection
import os

exect_path=os.getcwd()

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(exect_path,  "resnet50_coco_best_v2.1.0.h5"))
detector.loadModel()
list_ = detector.detectObjectsFromImage(
    input_image=os.path.join(exect_path, "scale_1200.jpg"),
    output_image_path=os.path.join(exect_path, "img.png") 
                                        )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
desaki, 2021-12-24
@desaki

I think here is the answer to your question - link

F
Footer_pro, 2022-01-08
@Footer_pro

Author, have you already overcome the problem?) I also came from YouTube
UPD: Everything works fine with this config

  • Python 3.7.6
  • pip install tensorflow==2.7.0
  • pip install tensorflow-gpu==2.7.0 optional if on vidyuha with CUDA
  • pip install keras==2.4.3 numpy==1.19.3 pillow==7.0.0 scipy==1.4.1 h5py==2.10.0 matplotlib==3.3.2 opencv-python keras-resnet==0.2.0
  • pip install imageai --upgrade

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question