Chainerで学習させたモデルを読み込んでpredictしようとしているのですがタイトルのようなエラーが出てしまいます。
引数の数もあっているはずなので原因がわかりません。
どこがまずいのでしょうか?
python
1def predict(model, dataset): 2 img, label = dataset 3 y = 0 4 with chainer.using_config('train', False), chainer.using_config('enable_backprop', False): 5 y = model(img) #ここでエラー 6 print("Predict : ", y.argmax(axis=1)[0], "Answer : ", label) 7 if y.argmax(axis=1)[0] == label: 8 return 1 9 else: 10 return 0 11 12def main(): 13 model = L.Classifier(NIN(args.classes)) 14 serializers.load_npz(args.model, model) 15 p_imgs = ######## #chainer用に画像を読み込む処理(tuple_dataset) 16 correct, total = 0, 0 17 for dataset in p_imgs: 18 correct += predict(model, dataset) 19 total += 1 20 print("Accuracy : ", correct*1.0/total) 21 return
python
1class NIN(chainer.Chain): 2 3 def __init__(self, n_out): 4 super(NIN, self).__init__() 5 conv_init = I.HeNormal() # MSRA scaling 6 self.n_out = n_out 7 with self.init_scope(): 8 self.mlpconv1 = L.MLPConvolution2D( 9 None, (96, 96, 96), 11, stride=4, conv_init=conv_init) 10 self.mlpconv2 = L.MLPConvolution2D( 11 None, (256, 256, 256), 5, pad=2, conv_init=conv_init) 12 self.mlpconv3 = L.MLPConvolution2D( 13 None, (384, 384, 384), 3, pad=1, conv_init=conv_init) 14 self.mlpconv4 = L.MLPConvolution2D( 15 None, (1024, 1024, self.n_out), 3, pad=1, conv_init=conv_init) 16 17 def __call__(self, x): 18 h = F.max_pooling_2d(F.relu(self.mlpconv1(x)), 3, stride=2) 19 h = F.max_pooling_2d(F.relu(self.mlpconv2(h)), 3, stride=2) 20 h = F.max_pooling_2d(F.relu(self.mlpconv3(h)), 3, stride=2) 21 h = self.mlpconv4(F.dropout(h)) 22 h = F.reshape(F.average_pooling_2d(h, 6), (len(x), self.n_out)) 23 return h
error
1Traceback (most recent call last): 2 File "predict.py", line 98, in <module> 3 main() 4 File "predict.py", line 91, in main 5 print(model(dataset[0])) 6 File "/Users/username/.pyenv/versions/3.7.0/lib/python3.7/site-packages/chainer/links/model/classifier.py", line 134, in __call__ 7 self.y = self.predictor(*args, **kwargs) 8TypeError: __call__() missing 1 required positional argument: 'x'
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/06 04:05