'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?
Solution 1:[1]
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
Solution 2:[2]
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Abo_nosa |
| Solution 2 | ?? ?????? |
