Replies: 1 comment 1 reply
-
may be ncnn.Mat.from_pixels work with values 0..255 and not float use ncnn with opencv ? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
我尝试用python的NCNN库验证我通过onnx转化的ncnn模型的有效性,但转化后的ncnn模型效果精度大幅低于原始的onnx模型。
我使用的转化方法是直接利用网站进行转化:https://convertmodel.com。之前用过是有效的。
我尝试使用同一张图片,同时通过onnx和ncnn模型,计算最后输出的相似度,但相似度极低。尝试了很多很多种ncnn图片读取方法,均不不理想,其中一个验证方法如下:
def convert(img_path, net,sess):
image = cv2.imread(img_path)
image = cv2.resize(image, (224, 224))
image = np.transpose(image, (2, 0, 1))
image1=image.astype(np.float32)
image = image.astype(np.float32) / 255.0 # 将图像数据转换为 float 类型并进行归一化
image = np.expand_dims(image, axis=0)
input_name = sess.get_inputs()[0].name
output_name = sess.get_outputs()[0].name
outputs = sess.run([output_name], {input_name: image})
feature1 = outputs[0][0]
image = image[0]
image = cv2.cvtColor(image1, cv2.COLOR_BGR2RGB) #加与不加效果差别均不理想
mat_in = ncnn.Mat.from_pixels(image, ncnn.Mat.PixelType.PIXEL_RGB,224,224)
后来我尝试验证np.array(ncnn.Mat(image1))-image1
但返回值并不是0矩阵。似乎与pytorch-numpy之间的任意转化有非常显著的差异。
不知道是python 的ncnn库有问题,还是我使用ncnn加载图片的方式有问题?
Beta Was this translation helpful? Give feedback.
All reactions