本書の「7.5 CNNの実装」でCNNの精度を確認するため(ch7/train_convnet.pyのソースコード)にMNISTを使っているのですが、そのMNISTのデータを動物のBGR画像データに変えて実行したところ、エラーが出てしまいました。
これを何とか学習することは出来るのでしょうか?
画像データは
x_train : サイズ(1000,3,50,50), 型 Array of uint8
t_train : サイズ(1000,), 型 Array of int32 (犬は1、猫は2、など…)
x_test : サイズ(500,3,50,50), 型 Array of uint8
t_test : サイズ(500,), 型 Array of int32 (上と同様)
です。
##エラーメッセージ
python
1Reloaded modules: simple_convnet, common, common.layers, common.functions, common.util, common.gradient, common.trainer, common.optimizer 2Traceback (most recent call last): 3 4 File "C:\Users\hatae.spyder-py3\タイトル無し1.py", line 92, in <module> 5 trainer.train() 6 7 File "..\common\trainer.py", line 71, in train 8 self.train_step() 9 10 File "..\common\trainer.py", line 44, in train_step 11 grads = self.network.gradient(x_batch, t_batch) 12 13 File "C:\Users\hatae\OneDrive\デスクトップ\deep-learning-from-scratch\ch07\simple_convnet.py", line 126, in gradient 14 self.loss(x, t) 15 16 File "C:\Users\hatae\OneDrive\デスクトップ\deep-learning-from-scratch\ch07\simple_convnet.py", line 72, in loss 17 return self.last_layer.forward(y, t) 18 19 File "..\common\layers.py", line 79, in forward 20 self.loss = cross_entropy_error(self.y, self.t) 21 22 File "..\common\functions.py", line 57, in cross_entropy_error 23 return -np.sum(np.log(y[np.arange(batch_size), t] + 1e-7)) / batch_size 24 25IndexError: index 10 is out of bounds for axis 1 with size 10
最後の「index 10 is out of ~」のindex後の数字は実行したときによって違います。
##コード
python
1import sys, os 2sys.path.append(os.pardir) # 親ディレクトリのファイルをインポートするための設定 3import numpy as np 4import matplotlib.pyplot as plt 5os.chdir(r"C:/Users/hatae/OneDrive/デスクトップ/deep-learning-from-scratch/ch07") 6from simple_convnet import SimpleConvNet 7from common.trainer import Trainer 8 9max_epochs = 20 10 11network = SimpleConvNet(input_dim=(3,50,50), 12 conv_param = {'filter_num': 30, 'filter_size': 5, 'pad': 0, 'stride': 1}, 13 hidden_size=100, output_size=10, weight_init_std=0.01) 14 15trainer = Trainer(network, x_train, t_train, x_test, t_test, 16 epochs=max_epochs, mini_batch_size=100, 17 optimizer='Adam', optimizer_param={'lr': 0.001}, 18 evaluate_sample_num_per_epoch=1000) 19trainer.train() 20 21# パラメータの保存 22network.save_params("params.pkl") 23print("Saved Network Parameters!") 24 25# グラフの描画 26markers = {'train': 'o', 'test': 's'} 27x = np.arange(max_epochs) 28plt.plot(x, trainer.train_acc_list, marker='o', label='train', markevery=2) 29plt.plot(x, trainer.test_acc_list, marker='s', label='test', markevery=2) 30plt.xlabel("epochs") 31plt.ylabel("accuracy") 32plt.ylim(0, 1.0) 33plt.legend(loc='lower right') 34plt.show() 35
ご教授頂けると幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/30 13:12 編集
2020/08/30 14:39
2020/08/31 12:39
2020/08/31 15:44