下記のエラーが出て困っています。
ソースの改善のご指摘を頂けますでしょうか。
参考の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
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。