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

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

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

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

Python

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

Q&A

解決済

1回答

7228閲覧

python エラーの意味が解りません.

tadapolice

総合スコア21

Keras

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

Python

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

0グッド

1クリップ

投稿2020/05/17 02:04

編集2020/05/17 02:18
コード ```### 前提・実現したいこと 教科書にしたがって,MNISTの画像をつかって,pythonを勉強しています. 調べてもどうしてもわからないエラーメッセージが出てくるので教えていただけますでしょうか? ### 発生している問題・エラーメッセージ RuntimeError Traceback (most recent call last) <ipython-input-38-209da1a055ab> in <module>() 3 history_adam=model.fit( 4 image_train,label_train,batch_size=32, ----> 5 epochs=10,validation_split=0.2 6 ) 2 frames /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs) 64 def _method_wrapper(self, *args, **kwargs): 65 if not self._in_multi_worker_mode(): # pylint: disable=protected-access ---> 66 return method(self, *args, **kwargs) 67 68 # Running inside `run_distribute_coordinator` already. /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing) 786 # Legacy graph support is contained in `training_v1.Model`. 787 version_utils.disallow_legacy_graph('Model', 'fit') --> 788 self._assert_compile_was_called() 789 self._check_call_args('fit') 790 /usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in _assert_compile_was_called(self) 1633 # (i.e. whether the model is built and its inputs/outputs are set). 1634 if not self._is_compiled: -> 1635 raise RuntimeError('You must compile your model before ' 1636 'training/testing. ' 1637 'Use `model.compile(optimizer, loss)`.') RuntimeError: You must compile your model before training/testing. Use `model.compile(optimizer, loss)`.

エラーメッセージ

### 該当のソースコード Python ソースコード ```from tensorflow.python.keras.datasets import mnist (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=['acuuracy'] ) history_adam=model.fit( image_train,label_train,batch_size=32, epochs=10,validation_split=0.2 ) コード

コード

### 試したこと summaryで中身を確認したとこと,Paramが47,936でした. 28*28*(64+1)=50.960になるはずですが... Model: "sequential" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense (Dense) (None, 64) 47936 _________________________________________________________________ dense_1 (Dense) (None, 10) 650 ================================================================= Total params: 48,586 Trainable params: 48,586 Non-trainable params: 0 _________________________________________________________________ ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。

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

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

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

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

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

y_waiwai

2020/05/17 02:06

このままではコードが読めないので、質問を編集し、<code>ボタンを押し、出てくる’’’の枠の中にコードを貼り付けてください
coco_bauer

2020/05/17 02:37

エラーメッセージには、以下のように書かれています。 "RuntimeError: You must compile your model before training/testing. Use model.compile(optimizer, loss)" ([直訳]モデルを訓練/試験する前には、コンパイルしなくてはならない。 model.compile(optimizer, loss)を使え。) モデルのコンパイルは、したのでしょうか?
tadapolice

2020/05/17 02:42

ありがとうございます. model.compile( optimizer='adam', loss='categorical_crossentropy', metrics=['acuuracy'] ) ではcompileできていないとおうことでしょうか?
guest

回答1

0

ベストアンサー

kerasは触ったことないですが・・・

RuntimeError: You must compile your model before training/testing. Use model.compile(optimizer, loss).

実行時エラー: あなたは training/testing する前に あなたのモデルをコンパイルしなければならない。model.compile(optimizer, loss) を使え。

とのことです。
心当たりはありませんか?

もしかしてスペルミスが原因?

誤: 'acuuracy'
正: 'accuracy'

投稿2020/05/17 02:38

編集2020/05/17 03:05
shiracamus

総合スコア5406

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

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

shiracamus

2020/05/17 02:41

coco_bauer さんのコメントとかぶってました。すみません。
shiracamus

2020/05/17 03:06

スペルミスの指摘を追記しました。
tadapolice

2020/05/17 05:14

ありがとうございます. スペルミスでした,申し訳ございません.
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問