(image_train,label_train),(image_test,label_test)=mnist.load_data() print('Image\n',image_train[0]) print("画像データの要素数",image_train.shape) print("ラベルデータの要素数",label_train.shape) #ラベルと画像データを表示 for i in range(0,10): print("ラベル",label_train[i]) plt.imshow(image_train[i].reshape(28,28)) plt.show() print('Train: num of imeges, width,height:',image_train.shape) print('Test: num of imeges, width,height:',image_test.shape) image_train=image_train.reshape(60000,784) image_train=image_train/255.0 image_test=image_test.reshape(10000,784) image_test=image_test/255.0 print('Train: num of labeled images:',label_train.shape) print('Test: num of labeled images:',label_test.shape) for i in range(0,9): print('Train Case:',i,'Label:',label_train[i]) for i in range(0,9): print('Test Case:',i,'Label:',label_test[i]) import numpy as np from tensorflow.python.keras.utils.np_utils import to_categorical from matplotlib import pyplot as plt label_train=to_categorical(label_train,10) label_test=to_categorical(label_test,10) print('Onehot Label:',label_train[7]) print('Onehot Label:',label_test[1]) from tensorflow.python.keras.models import Sequential from tensorflow.python.keras.layers import Dense model=Sequential() model.add( Dense(units=64,input_shape=(748,),activation='relu') ) model.add( Dense(units=10, activation='softmax') ) model.compile( optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'] ) history_adam=model.fit( image_train,label_train,batch_size=32, epochs=10,validation_split=0.2 )
MNISTの画像で画像分類のコードを作成しています.
エラーコードでどうしても原因がわからないので教えてください.
ValueError Traceback (most recent call last)
<ipython-input-11-98660863e952> in <module>()
54 history_adam=model.fit(
55 image_train,label_train,batch_size=32,
---> 56 epochs=10,validation_split=0.2
57 )
ValueError: Input 0 of layer sequential_6 is incompatible with the layer: expected axis -1 of input shape to have value 748 but received input with shape [32, 784]
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/05/17 09:04