https://teratail.com/questions/315284#reply-439497
URLを参考にして、プログラムを実行すると、以下のエラー文がでて推論できません。考えられる原因はなんでしょうか。
#エラー文
File "C:\Users\username\Desktop\output\capture.py", line 106, in <module>
y = network(x, t)
File "C:\Users\username\Desktop\output\capture.py", line 16, in network
h = PF.binary_connect_affine(x, name='BinaryConnectAffine')
TypeError: binary_connect_affine() missing 1 required positional argument: 'n_outmaps'
#プログラム
python
1import nnabla as nn 2import nnabla.functions as F 3import nnabla.parametric_functions as PF 4from nnabla.utils.data_iterator import data_iterator_csv_dataset 5import os 6import cv2 7from datetime import datetime 8import pandas as pd 9import matplotlib.pyplot as plt 10import numpy as np 11from PIL import Image 12 13 14def network(x, y, test=False): 15 # Input:x -> 3,250,250 16 # BinaryConnectAffine -> 100 17 h = PF.binary_connect_affine(x,(100), name='BinaryConnectAffine') 18 # BatchNormalization 19 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization') 20 # ReLU 21 h = F.relu(h, True) 22 # BinaryConnectAffine_2 23 h = PF.binary_connect_affine(h,(100), name='BinaryConnectAffine_2') 24 # BatchNormalization_2 25 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization_2') 26 # ReLU_2 27 h = F.relu(h, True) 28 # BinaryConnectAffine_3 29 h = PF.binary_connect_affine(h,(100), name='BinaryConnectAffine_3') 30 # BatchNormalization_3 31 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization_3') 32 # ReLU_3 33 h = F.relu(h, True) 34 # BinaryConnectAffine_4 -> 26 35 h = PF.binary_connect_affine(h, (26), name='BinaryConnectAffine_4') 36 # BatchNormalization_4 37 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization_4') 38 # Softmax 39 h = F.softmax(h) 40 # CategoricalCrossEntropy -> 1 41 #h = F.categorical_cross_entropy(h, y) 42 return h 43 44 45 46 47class_names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] 48cap = cv2.VideoCapture(0) # 任意のカメラ番号に変更する 49 50 51new_dir_path = "./realtime/" 52os.makedirs(new_dir_path, exist_ok=True) 53 54 #カメラスタート 55while True: 56 57 ret, frame = cap.read() 58 cv2.imshow("camera", frame) 59 60 k = cv2.waitKey(1)&0xff # キー入力を待つ 61 if k == ord('p'): 62 63 # 「p」キーで画像を保存 64 65 date = datetime.now().strftime("%Y%m%d_%H%M%S") 66 path = new_dir_path + date +".png" 67 cv2.imwrite(path, frame) 68 image_gs = cv2.imread(path) 69 70 path = new_dir_path + date +".png" 71 dst = cv2.resize(image_gs,(250,250)) 72 cv2.imwrite(path, dst) 73 74 f = pd.DataFrame(columns=["x:data","y:data"]) 75 xdata = path 76 ydata = 0 77 new_name = pd.Series([xdata,ydata],index=f.columns) 78 f = f.append(new_name, ignore_index=True) 79 f.to_csv('valu.csv',index=False,header = True ) 80 81 test_data = data_iterator_csv_dataset("C:\Users\username\Desktop\output\valu.csv",1,shuffle=False,normalize=True) 82 83 84 path = new_dir_path + "test" +".png" 85 cv2.imwrite(path, frame) 86 image_gs = cv2.imread(path) 87 88 path = new_dir_path + date +".png" 89 dst = cv2.resize(image_gs,(250,250)) 90 cv2.imwrite(path, dst) 91 92 f = pd.DataFrame(columns=["x:data","y:data"]) 93 xdata = path 94 ydata = 0 95 new_name = pd.Series([xdata,ydata],index=f.columns) 96 f = f.append(new_name, ignore_index=True) 97 f.to_csv('valu.csv',index=False,header = True ) 98 99 test_data = data_iterator_csv_dataset("C:\Users\username\Desktop\output\valu.csv",1,shuffle=False,normalize=True) 100 101 102 #ネットワークの構築 103 nn.clear_parameters() 104 x = nn.Variable((1,3,250,250)) 105 t = nn.Variable((1,1)) 106 y = network(x, t) 107 108 nn.load_parameters('C:\Users\username\Desktop\output\yubidata.files\20210113_161413\results.nnp') 109 print("load model") 110 111 for i in range(test_data.size): 112 113 x.d, t.d = test_data.next() 114 y.forward() 115 print(y.d[0]) 116 print(np.argmax(y.d[0])) 117 print(class_names[np.argmax(y.d[0])]) 118 119 elif k == ord('q'): 120 # 「q」キーが押されたら終了する 121 122 break 123 124 # キャプチャをリリースして、ウィンドウをすべて閉じる 125cap.release() 126cv2.destroyAllWindows()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/13 05:50
2021/01/13 06:03 編集
2021/01/13 06:20
2021/01/13 06:29
2021/01/13 08:02
2021/01/13 08:04
2021/01/13 08:32 編集
2021/01/13 08:43
2021/01/13 10:16
2021/01/13 10:30 編集
2021/01/13 10:29 編集
2021/01/14 03:59
2021/01/14 04:07
2021/01/14 04:12 編集
2021/01/14 04:19
2021/01/14 04:21
2021/01/14 04:29
2021/01/14 04:29
2021/01/14 04:55
2021/01/14 05:37
2021/01/14 05:43
2021/01/14 06:46
2021/01/14 07:07 編集
2021/01/14 07:56
2021/01/14 09:23