Home > Software design >  My keras is not getting compiled when I train my neural network model,
My keras is not getting compiled when I train my neural network model,

Time:02-17

The libraries are imported as as shown below

import tensorflow
from tensorflow.keras.models import Sequential
from keras.models import Sequential
from keras.layers import Dense, Conv2D , MaxPool2D , Flatten , Dropout

I am using tensorflow 2.6.2 and keras version is 2.6.0. Please guide to solve the error. The output is

Traceback (most recent call last):
File "/home/nvidia/finalproject/test1.py", line 5, in <module>
from tensorflow.keras.models import Sequential
File "/usr/local/lib/python3.6/dist-packages/keras/api/_v2/keras/__init__.py", line 
10, in <module>
from keras import __version__
File "/usr/local/lib/python3.6/dist-packages/keras/__init__.py", line 25, in <module>
from keras import models
File "/usr/local/lib/python3.6/dist-packages/keras/models.py", line 20, in <module>
from keras import metrics as metrics_module
File "/usr/local/lib/python3.6/dist-packages/keras/metrics.py", line 27, in <module>
from keras import activations
File "/usr/local/lib/python3.6/dist-packages/keras/activations.py", line 20, in 
<module>
from keras.layers import advanced_activations
File "/usr/local/lib/python3.6/dist-packages/keras/layers/__init__.py", line 24, in 
<module>
from keras.engine.input_layer import Input
File "/usr/local/lib/python3.6/dist-packages/keras/engine/input_layer.py", line 21, 
in <module>
from keras.engine import base_layer
File "/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py", line 41, in 
<module>
from keras.mixed_precision import loss_scale_optimizer
File "/usr/local/lib/python3.6/dist- 
packages/keras/mixed_precision/loss_scale_optimizer.py", line 1180, in <module>
mixed_precision._register_wrapper_optimizer_cls(optimizer_v2.OptimizerV2,
AttributeError: module 'tensorflow.python.training.experimental.mixed_precision' has 
no attribute '_register_wrapper_optimizer_cls'

CodePudding user response:

This is because of a compatibility issue. Try to use the tf.keras API instead:

import tensorflow
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Conv2D , MaxPool2D , Flatten , Dropout

CodePudding user response:

Importing Sequential from both tensorflow and keras does not make any sense.
Use this instead:

import tensorflow
from keras.models import Sequential
from keras.layers import Dense, Conv2D , MaxPool2D , Flatten , Dropout
  • Related