TypeError: 'module' object is not callable when using Keras

TypeError: 'module' object is not callable when using Keras

关于 TensorFlow 和 Keras,我一直遇到很多导入问题,现在我偶然发现了这个错误:

TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_17880/703187089.py in <module>
     75 #model.compile(loss="categorical_crossentropy",optimizers.rmsprop(lr=0.0001),metrics=["accuracy"])
     76 
---> 77 model.compile(optimizers.rmsprop_v2(lr=0.0001, decay=1e-6),loss="categorical_crossentropy",metrics=["accuracy"])
     78 
     79 STEP_SIZE_TRAIN=train_generator.n//train_generator.batch_size

TypeError: 'module' object is not callable

这些是进口商品:

from tensorflow import keras
from keras_preprocessing.image import ImageDataGenerator
from keras.layers import Dense, Activation, Flatten, Dropout, BatchNormalization
from keras.layers import Conv2D, MaxPooling2D
from keras import regularizers, optimizers
from keras.models import Sequential
from keras import optimizers
from keras.optimizers import rmsprop_v2, adadelta_v2

kerns.optimizers.rmsprop_v2kerns.optimizers.adadelta_v2 是模块。你想要:

from keras.optimizers import RMSprop, Adadelta

并且:

optimizers.RMSprop(lr=0.0001, decay=1e-6)(或 RMSprop(lr=0.0001, decay=1e-6))而不是 optimizers.rmsprop_v2(lr=0.0001, decay=1e-6)