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

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

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

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

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

Q&A

解決済

1回答

1002閲覧

python Fine Tuneingコードについて

watchdogs

総合スコア54

機械学習

機械学習は、データからパターンを自動的に発見し、そこから知能的な判断を下すためのコンピューターアルゴリズムを指します。人工知能における課題のひとつです。

Python

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

0グッド

0クリップ

投稿2020/12/22 02:23

下記のエラーが出て困っています。
ソースの改善のご指摘を頂けますでしょうか。

参考のURLは下記になります。
https://torusblog.org/toru-hyperastunningdence/

エラー内容
info(val_acc, val_loss,hist)
TypeError: info() missing 1 required positional argument: 'hist'

Python

1import keras 2import matplotlib.pyplot as plt 3from keras import models, optimizers 4from keras.datasets import mnist 5from keras.layers import Dense, Dropout 6from keras.models import Sequential 7from keras.optimizers import SGD 8 9 10def get_data() : 11 12 (x_train, y_train), (x_test, y_test) = mnist.load_data() 13 14 x_train = x_train.reshape(60000, 784) 15 x_test = x_test.reshape(10000, 784) 16 17 x_train = x_train.astype('float32') 18 x_test = x_test.astype('float32') 19 20 x_train /= 255 21 x_test /= 255 22 23 print(x_train.shape[0], 'train samples') 24 print(x_test.shape[0], 'test samples') 25 26 y_train = keras.utils.to_categorical(y_train, 10) 27 y_test = keras.utils.to_categorical(y_test, 10) 28 29 return x_train, y_train, x_test, y_test 30 31def model(x_train, y_train, x_test, y_test) : 32 33 model = Sequential() 34 model.add(Dense(256, activation = 'relu', input_shape = (784,))) 35 model.add(Dropout(0.2)) 36 model.add(Dense(128, activation = 'relu')) 37 model.add(Dropout(0.2)) 38 model.add(Dense(10, activation = 'softmax')) 39 model.summary() 40 41 model.compile(loss = 'categorical_crossentropy', optimizer = \ 42 SGD(lr = 0.05, clipnorm = 1., nesterov = True), 43 metrics = ['accuracy']) 44 hist = model.fit(x_train, y_train, batch_size = 128, epochs = 20, 45 verbose = 1, validation_data = (x_test, y_test)) 46 val_loss, val_acc = model.evaluate(x_test, y_test, verbose = 1) 47 48 return val_loss, val_acc, hist 49 50def info(val_acc, val_loss, start_time, hist) : 51 52 print(" ") 53 print("===============================") 54 print("Accuracy:{:.2f}".format(val_acc * 100), "%") 55 print('loss:{:.2f}'.format(val_loss * 100), "%") 56 57 #Accuracy Graph 58 plt.rc('font', family = 'serif') 59 fig = plt.figure(figsize = (13, 6)) 60 plt.subplot(1, 2, 1) 61 plt.xlim([0, 20]) 62 plt.plot(hist.history['accuracy'], label = 'Train Acc', color = 'red') 63 plt.plot(hist.history['val_accuracy'], label = 'Test Acc', color = 'm') 64 plt.title('Model Accuracy') 65 plt.xlabel('Epochs') 66 plt.ylabel('accuracy') 67 plt.legend(bbox_to_anchor = (0.7, 0.5), loc = 'center left', borderaxespad = 0,\ 68 fontsize = 8) 69 70 #Loss Graph 71 plt.rc('font', family = 'serif') 72 plt.subplot(1, 2, 2) 73 plt.xlim([0, 20]) 74 plt.plot(hist.history['loss'], label = 'Train Loss', color = 'blue') 75 plt.plot(hist.history['val_loss'], label = 'Test Loss', color = 'c') 76 plt.title('Model Loss') 77 plt.xlabel('Epochs') 78 plt.ylabel('loss') 79 plt.legend(bbox_to_anchor = (0.7, 0.5), loc = 'center left', borderaxespad = 0, fontsize = 8) 80 #plt.savefig ('mnist_graph.png') 81 plt.show() 82 83#===Learning=== 84 85x_train, y_train, x_test, y_test = get_data() 86val_loss, val_acc, hist = model(x_train, y_train, x_test, y_test) 87info(val_acc, val_loss,hist) 88 89#============== 90 91

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

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

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

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

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

guest

回答1

0

ベストアンサー

info()の定義が

python

1def info(val_acc, val_loss, start_time, hist) :

となってるけど、「start_time」はinfo()内では使われてないので、そこを

python

1def info(val_acc, val_loss, hist) :

と変えるか、あるいは、info()を使う方(コードの最後)を

python

1info(val_acc, val_loss, 0, hist)

とするか、どちらか

投稿2020/12/22 03:14

jbpb0

総合スコア7651

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

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

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問