質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

3752閲覧

epochsのError???

tadapolice

総合スコア21

Keras

Kerasは、TheanoやTensorFlow/CNTK対応のラッパーライブラリです。DeepLearningの数学的部分を短いコードでネットワークとして表現することが可能。DeepLearningの最新手法を迅速に試すことができます。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

1クリップ

投稿2020/05/17 08:15

(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]

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

image_train=image_train.reshape(60000,784)

Dense(units=64,input_shape=(748,),activation='relu')

784748が異なっているのが原因ではないでしょうか?

投稿2020/05/17 08:40

meg_

総合スコア10594

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

tadapolice

2020/05/17 09:04

ありがとうございました!! 申し訳ございませんでした.
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問