简体   繁体   中英

ImportError: cannot import name 'BatchNormalization' from 'tensorflow.python.keras.layers'

I have a script that runs well on google collab and kaggle, but regarding their memory limitation, I'm now trying to run it on my jupyter notebook in my laptop but then the error message shows.

ImportError: cannot import name 'BatchNormalization' from 'tensorflow.python.keras.layers' 

It called from the line:

from pixellib.tune_bg import alter_bg

I alreaddy imported what seems to be required:

from tensorflow.keras.layers import (Input, Dense, Flatten, Dropout, Conv2D, MaxPooling2D, GlobalAveragePooling2D, Activation, Concatenate, LeakyReLU, BatchNormalization, concatenate)

And also installed:

!pip install pixellib

My Specification:
No GPU
keras version 2.8.0
tensorflow version 2.8.0
Python version '3.10.1 (tags/v3.10.1:2cd268a, Dec 6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)]'

IPython: not installed
ipykernel: 6.8.0
ipywidgets: not installed

jupyter_client: 7.1.2
jupyter_core: 4.9.1
jupyter_server: not installed
jupyterlab: not installed
nbclient: 0.5.10

Any suggestion please?

Go to Pixellib folder -> semantic -> deeplab.py and replace this line from tensorflow.python.keras.layers import BatchNormalization with this one from keras.layers.normalization.batch_normalization import BatchNormalization

I think it is because you are importing BatchNormalization here: from tensorflow.keras.layers import (Input, Dense, Flatten, Dropout, Conv2D, MaxPooling2D, GlobalAveragePooling2D, Activation, Concatenate, LeakyReLU, BatchNormalization, concatenate)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM