Issue
I imported these packages
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.models import Model
from keras.layers import Dense, Dropout, Flatten
from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K
from keras.utils import np_utils
from keras import optimizer_v2
from keras.optimizer_v2 import adam
the data, split between train and test sets
(x_train, y_train), (x_test, y_test) = mnist.load_data()
print(x_train.shape, y_train.shape)
x_train = x_train.reshape(x_train.shape[0], 28, 28, 1)
x_test = x_test.reshape(x_test.shape[0], 28, 28, 1)
input_shape = (28, 28, 1)
# convert class vectors to binary class matrices
y_train = keras.utils.np_utils.to_categorical(y_train, 10)
y_test = keras.utils.np_utils.to_categorical(y_test, 10)
x_train = x_train.astype('float32')
x_test = x_test.astype('float32')
x_train /= 255
x_test /= 255
print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')
batch_size = 128
num_classes = 10
epochs = 10
model = Sequential()
model.add(Conv2D(32, kernel_size=(5, 5),activation='relu',input_shape=input_shape))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.3))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation='softmax'))
This is where I am getting the error
model.compile(loss=keras.losses.categorical_crossentropy,optimizer=keras.optimizer_v2.adam(learning_rate=0.01),metrics=['accuracy'])
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-64ffa4d65c71> in <module>
----> 1 model.compile(loss=keras.losses.categorical_crossentropy,optimizer=keras.optimizer_v2.adam(learning_rate=0.01),metrics=['accuracy'])
TypeError: 'module' object is not callable
How do I get through this error?
Solution
keras.optimizer_v2.adam
is a module. Replace it with keras.optimizer_v2.adam.Adam
Answered By - Yevhen Kuzmovych
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.