Getting keras ValueError during fitting of the model(loss and losses keyword issue)

128 Views Asked by At
num_classes=10
(d_tr,l_tr),(d_val,l_val) = mnist.load_data()
l_tr = to_categorical(l_tr,num_classes)
l_val = to_categorical(l_val,num_classes)
d_tr = np.reshape(d_tr,(len(d_tr),28,28,1))
d_val = np.reshape(d_val,(len(d_val),28,28,1))
#d_tr = np.reshape(d_tr,(len(d_tr),784))
#d_val = np.reshape(d_val,(len(d_val),784))

print(l_tr.shape)
print(l_val.shape)
print(d_tr.shape)
print(d_val.shape)

m_0 = Input(shape=(28,28,1,))
m = Conv2D(25,(3,3),input_shape=(28,28,1),padding="same")(m_0)
m = Dropout(.3)(m)
m = Conv2D(40,(3,3),strides=2,padding="same")(m)
m = Dropout(.4)(m)
m = Conv2D(60,(3,3),kernel_regularizer=l2(.025),padding="same")(m)
m = Dropout(.4)(m)
m = Conv2D(60,(3,3),kernel_regularizer=l2(.025),strides=2,padding="same")(m)
m = BatchNormalization()(m)
m = Flatten()(m)
m = Dropout(.45)(m)
out = Dense(num_classes,activation="softmax")(m)
model = Model(inputs=m_0,outputs=out)
model.summary()
model.compile("adam",metrics=["accuracy"],losses="categorical_crossentropy")
model.fit(x=d_tr,y=l_tr,epochs=20,batch_size=64,validation_data=(d_val,l_val),callbacks=[CSVLogger('log_mnist.csv')])

I'm trying to make a simple model for MNIST using functional API(code attached above). I'm trying to figure out what I did wrong but I cant find any way to resolve the following error:

ValueError: ('Error when checking model target: expected no data, but got:', array([[0., 0., 0., ..., 0., 0., 0.],
       [1., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       ...,
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 1., 0.]], dtype=float32))

EDIT: It turns out the issue can be resolved when you turn "losses" keyword in model.compile to "loss". But why losses was accepted by interpreter if it's not a keyword is still unknown ot me. Please answer that if you have any information on it.

0

There are 0 best solutions below