yolo v8模型推理问题
收藏回复举报
yolo v8模型推理问题
t('forum.solved') 已解决
发表于2025-11-04 11:06:22
0 查看

①  om模型在推理过程中:

onnx模型本身的精度是float32

我用了以下两种方式进行模型转换:

模型① atc --model=/media/hole.onnx --framework=5 --output=/media/hole --soc_version=Ascend310B4

模型② atc --model=/media/hole_1100_ospet14.onnx --framework=5 --output=/media/holefp6 --soc_version=Ascend310B4 --precision_mode=force_fp16

问题一:第二种是强制将模型的数据类型指定为fp16,但是我的第二种的推理速度还没有第一种快是什么原因呢?

问题二:   推理时数据类型转换的问题

第一个小问题:

def get_result(self, output_data):

dataset = []

for temp in output_data:

size = temp["size"]

ptr = temp["buffer"]

data = acl.util.ptr_to_numpy(ptr, (size,), 1)

print("模型推理获取结果的数据类型----", data.dtype)

dataset.append(data)

return dataset

上述的代码中   模型推理获取结果的数据类型---  为什么是int8类型?

第二个小问题:

self.img = cv2.imread(img_path)

img, ratio, (dw, dh) = self.letterbox(self.img)

self.img_height, self.img_width = self.img.shape[:2]

# img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# image_data = np.transpose(img, (2, 0, 1))

# image = np.expand_dims(image_data, axis=0).astype(np.float32)

# image = np.ascontiguousarray(image) / 255.0 # 转换为内存连续存储的数组

img = img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, HWC to CHW

img = np.expand_dims(img, 0).astype(np.float32) # 将形状转换为 channel first (1, 3, 640, 640),即扩展第一维为 batchsize

img = np.ascontiguousarray(img) / 255.0 # 转换为内存连续存储的数组

img_bytes = np.frombuffer(img.tobytes(), np.float16)

return img_bytes, self.img.shape, (ratio, dw, dh)

图像在前处理的过程中,    img_bytes = np.frombuffer(img.tobytes(), np.float16)  转换为字节流这个地方,np.float16  和np.float32我应该设置哪一个,这个是根据什么设置呢?

第三个小问题:

image_bytes, _, (ratio,dw, dh) = self.preprocess(img_path)

result = self.net.run([image_bytes])

pred = np.frombuffer(bytearray(result[0]), dtype=np.float32)

图像在推理完成之后的结果,pred = np.frombuffer(bytearray(result[0]), dtype=np.float32)  地方的dtype应该怎么设置,是根据什么设置?  期待您的回复。

我要发帖子