こちらを参考にして、Neural Network Console×Python×USBカメラでリアルタイム推論を実現しようと思っています。
今こちらを参考にして実行するとエラーがでてきます。解決方法を教えてください。
https://teratail.com/questions/315660
#エラー文
File "C:\Users\username\Desktop\output\capture.py", line 79, in <module>
test_data = data_iterator_csv_dataset("C:\Users\username\Desktop\output\valu.csv",1,shuffle=False,normalize=True)
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_iterator.py", line 581, in data_iterator_csv_dataset
return data_iterator(ds,
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_iterator.py", line 406, in data_iterator
ds = DataSourceWithFileCache(data_source=data_source,
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_source.py", line 453, in init
self._create_cache()
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_source.py", line 326, in _create_cache
self._store_data_to_cache_buffer(self._position)
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_source.py", line 275, in _store_data_to_cache_buffer
self._save_cache_to_file()
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_source.py", line 209, in _save_cache_to_file
pool.map(get_data, [(pos, q) for pos in self._cache_positions])
File "C:\Users\username\anaconda3\lib\multiprocessing\pool.py", line 364, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
File "C:\Users\username\anaconda3\lib\multiprocessing\pool.py", line 771, in get
raise self._value
File "C:\Users\username\anaconda3\lib\multiprocessing\pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "C:\Users\username\anaconda3\lib\multiprocessing\pool.py", line 48, in mapstar
return list(map(*args))
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_source.py", line 198, in get_data
d = self._data_source._get_data(pos)
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_source_implements.py", line 430, in _get_data
return tuple(self._process_row(self._rows[self._order[position]]))
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_source_implements.py", line 407, in _process_row
values[variable] = self._get_value(
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_source_implements.py", line 425, in _get_value
with self._filereader.open(value) as f:
File "C:\Users\username\anaconda3\lib\contextlib.py", line 113, in enter
return next(self.gen)
File "C:\Users\username\anaconda3\lib\site-packages\nnabla\utils\data_source_loader.py", line 176, in open
f = open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\username\Desktop\output\A_1.png'
#CSVファイルの内容
#各データの保存場所
#プログラム
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 45class_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'] 46cap = cv2.VideoCapture(0) # 任意のカメラ番号に変更する 47 48 49new_dir_path = "./realtime/" 50os.makedirs(new_dir_path, exist_ok=True) 51 52 #カメラスタート 53while True: 54 55 ret, frame = cap.read() 56 cv2.imshow("camera", frame) 57 58 k = cv2.waitKey(1)&0xff # キー入力を待つ 59 if k == ord('p'): 60 61 # 「p」キーで画像を保存 62 63 date = datetime.now().strftime("%Y%m%d_%H%M%S") 64 path = new_dir_path + date +".png" 65 cv2.imwrite(path, frame) 66 image_gs = cv2.imread(path) 67 68 path = new_dir_path + date +".png" 69 dst = cv2.resize(image_gs,(250,250)) 70 cv2.imwrite(path, dst) 71 72 f = pd.DataFrame(columns=["x:data","y:data"]) 73 xdata = path 74 ydata = 0 75 new_name = pd.Series([xdata,ydata],index=f.columns) 76 f = f.append(new_name, ignore_index=True) 77 #f.to_csv('valu.csv',index=False,header = True ) 78 79 test_data = data_iterator_csv_dataset("C:\Users\username\Desktop\output\valu.csv",1,shuffle=False,normalize=True) 80 81 82 path = new_dir_path + "test" +".png" 83 cv2.imwrite(path, frame) 84 image_gs = cv2.imread(path) 85 86 path = new_dir_path + date +".png" 87 dst = cv2.resize(image_gs,(250,250)) 88 cv2.imwrite(path, dst) 89 90 f = pd.DataFrame(columns=["x:data","y:data"]) 91 xdata = path 92 ydata = 0 93 new_name = pd.Series([xdata,ydata],index=f.columns) 94 f = f.append(new_name, ignore_index=True) 95 #f.to_csv('valu.csv',index=False,header = True ) 96 97 test_data = data_iterator_csv_dataset("C:\Users\username\Desktop\output\valu.csv",1,shuffle=False,normalize=True) 98 99 100 #ネットワークの構築 101 nn.clear_parameters() 102 x = nn.Variable((1,3,250,250)) 103 t = nn.Variable((1,1)) 104 y = network(x, t, test=True) 105 106 nn.load_parameters('C:\Users\username\Desktop\output\yubidata.files\20210112_183426\results.nnp') 107 print("load model") 108 109 for i in range(test_data.size): 110 111 x.d, t.d = test_data.next() 112 y.forward() 113 print(y.d[0]) 114 print(np.argmax(y.d[0])) 115 print(class_names[np.argmax(y.d[0])]) 116 117 elif k == ord('q'): 118 # 「q」キーが押されたら終了する 119 120 break 121 122 # キャプチャをリリースして、ウィンドウをすべて閉じる 123cap.release() 124cv2.destroyAllWindows() 125
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/15 06:04
2021/01/15 06:17
2021/01/15 06:58
2021/01/15 07:05
2021/01/15 07:16
2021/01/15 07:23