'Why is keras and BatchNormalization underlined?
I am trying to run a CNN python code, but at the top of the code, the following line has keras and BatchNormalization underline in red.
from keras.layers.normalization import BatchNormalization
I don't know why there are underline. I confirmed that I have python, keras and tensorflow installed
>>> import keras
>>> keras.__version__
'2.8.0'
>>>
>>> import tensorflow as tf
>>> print(tf. __version__)
2.8.0
>>>
(venv) PS C:\Users\PycharmProjects\Local-Binary-Patterns> python --version
Python 3.10.4
>>
Am I missing something?
Computer specs: HP Omen with Ryzen 7 CPU and GEFORCE RTX 3080 GPU.
Solution 1:[1]
As far as I know you should import BatchNormalization like so -
from tensorflow.keras.layers import BatchNormalization
Solution 2:[2]
If the code works, don't worry about the underline.
TensorFlow uses some late-import and aliasing tricks that sometimes confuse PyCharm's code completion system.
Solution 3:[3]
I found the solution. I had to revert to old versions of Python, Keras and Tensorflow
Python: 3.9.0
Keras: 2.4.3
Tensorflow: 2.5.0
I then copied my python code and ran it with the new versions and it worked like a charm.
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 | Yoel Nisanov |
| Solution 2 | AKX |
| Solution 3 | Josh |
