0
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.

manav.tix
  • 101
  • 2
  • I have no problem running. – giser_yugang Sep 17 '18 at 08:16
  • what line throws this error? – Imtinan Azhar Sep 17 '18 at 08:38
  • model.fit causes error. Trackback details are as follows:Traceback (most recent call last): File "", line 1, in File "/home/intern2/anaconda3/lib/python3.6/site-packages/Keras-2.1.6-py3.6.egg/keras/engine/training.py", line 950, in fit File "/home/intern2/anaconda3/lib/python3.6/site-packages/Keras-2.1.6-py3.6.egg/keras/engine/training.py", line 787, in _standardize_user_data File "/home/intern2/anaconda3/lib/python3.6/site-packages/Keras-2.1.6-py3.6.egg/keras/engine/training_utils.py", line 61, in standardize_input_data – manav.tix Sep 17 '18 at 08:43
  • I was able to solve the problem by changing "losses" keyword in model.compile ot "loss". However I still don't know why "losses" was first accepted if it's not a keyword at all. – manav.tix Sep 17 '18 at 09:02
  • If it is not one of the predefined parameters of the `.compile()` function, then it might still have been accepted as *arg or **kwarg – Daneel R. Sep 17 '18 at 12:06

0 Answers0