ブログ
こちらのブログを参考にして、NNCを使った画像の推論をしたいのですが以下のエラーがでます。どのように書き直せばよいでしょうか。
#エラー文
runfile('C:/Users/username/Desktop/output/タイトル無し0.py', wdir='C:/Users/username/Desktop/output')
2021-01-15 17:25:34,520 [nnabla][INFO]: Parameter load (<built-in function format>): C:\Users\username\Desktop\output\yubidata.files\20210112_183426\results.nnp
Traceback (most recent call last):
File "C:\Users\username\Desktop\output\タイトル無し0.py", line 50, in <module>
y = network(x, test=True)
TypeError: network() missing 1 required positional argument: 'y'
python
1# -*- coding: utf-8 -*- 2import nnabla as nn 3import nnabla.functions as F 4import nnabla.parametric_functions as PF 5import cv2 6def network(x, y, test=False): 7 # Input:x -> 3,250,250 8 # BinaryConnectAffine -> 100 9 h = PF.binary_connect_affine(x, (100), name='BinaryConnectAffine') 10 # BatchNormalization 11 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization') 12 # ReLU 13 h = F.relu(h, True) 14 # BinaryConnectAffine_2 15 h = PF.binary_connect_affine(h, (100), name='BinaryConnectAffine_2') 16 # BatchNormalization_2 17 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization_2') 18 # ReLU_2 19 h = F.relu(h, True) 20 # BinaryConnectAffine_3 21 h = PF.binary_connect_affine(h, (100), name='BinaryConnectAffine_3') 22 # BatchNormalization_3 23 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization_3') 24 # ReLU_3 25 h = F.relu(h, True) 26 # BinaryConnectAffine_4 -> 26 27 h = PF.binary_connect_affine(h, (26), name='BinaryConnectAffine_4') 28 # BatchNormalization_4 29 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization_4') 30 # Softmax 31 h = F.softmax(h) 32 # CategoricalCrossEntropy -> 1 33 # h = F.categorical_cross_entropy(h, y) 34 return h 35 36 37 # load parameters 38nn.load_parameters('C:\Users\username\Desktop\output\yubidata.files\20210112_183426\results.nnp') 39 40# Prepare input variable 41x=nn.Variable((1,3,250,250)) 42 43IMAGE_SIZE = 250 44im = cv2.imread('C:\Users\username\Desktop\output\A\A_1.png') 45im = cv2.resize(im, (IMAGE_SIZE,IMAGE_SIZE)).transpose(2,0,1) 46x = nn.Variable((1, ) + im.shape) 47x.d = im.reshape(x.shape) 48 49# Build network for inference 50y = network(x, test=False) 51 52# Execute inference 53y.forward() 54print(y.d)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/15 09:14 編集