リンク内容
こちらのブログを参考にして、neural network consoleを使った画像の推論をしたいのですが以下のエラーがでます。どのように書き直せばよいでしょうか。
#エラーメッセージ
error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-wwma2wne\opencv\modules\imgproc\src\resize.cpp:3929: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
#プログラム
python
1 2 3# -*- coding: utf-8 -*- 4import nnabla as nn 5import nnabla.functions as F 6import nnabla.parametric_functions as PF 7import cv2 8def network(x, y, test=False): 9 # Input:x -> 3,250,250 10 # BinaryConnectAffine -> 100 11 h = PF.binary_connect_affine(x, (100), name='BinaryConnectAffine') 12 # BatchNormalization 13 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization') 14 # ReLU 15 h = F.relu(h, True) 16 # BinaryConnectAffine_2 17 h = PF.binary_connect_affine(h, (100), name='BinaryConnectAffine_2') 18 # BatchNormalization_2 19 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization_2') 20 # ReLU_2 21 h = F.relu(h, True) 22 # BinaryConnectAffine_3 23 h = PF.binary_connect_affine(h, (100), name='BinaryConnectAffine_3') 24 # BatchNormalization_3 25 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization_3') 26 # ReLU_3 27 h = F.relu(h, True) 28 # BinaryConnectAffine_4 -> 26 29 h = PF.binary_connect_affine(h, (26), name='BinaryConnectAffine_4') 30 # BatchNormalization_4 31 h = PF.batch_normalization(h, (1,), 0.9, 0.0001, not test, name='BatchNormalization_4') 32 # Softmax 33 h = F.softmax(h) 34 # CategoricalCrossEntropy -> 1 35 # h = F.categorical_cross_entropy(h, y) 36 return h 37 38 39 # load parameters 40nn.load_parameters('C:\Users\username\Desktop\output\yubidata.files\20210112_183426\results.nnp') 41 42# Prepare input variable 43x=nn.Variable((1,3,250,250)) 44 45IMAGE_SIZE = 250 46im = cv2.imread('C:\Users\username\Desktop\output\A\A_1.png') 47im = cv2.resize(im, (IMAGE_SIZE,IMAGE_SIZE)).transpose(2,0,1) 48x = nn.Variable((1, ) + im.shape) 49x.d = im.reshape(x.shape) 50 51# Build network for inference 52y = network(x, test=False) 53 54# Execute inference 55y.forward() 56print(y.d)
回答2件
あなたの回答
tips
プレビュー