RangiLyu / nanodet

NanoDet-Plusāš”Super fast and lightweight anchor-free object detection model. šŸ”„Only 980 KB(int8) / 1.8MB (fp16) and run 97FPS on cellphonešŸ”„
Apache License 2.0
5.78k stars 1.04k forks source link

The onnx model(which is transfor by export_onnx.py) out put is differ from pytoch model #478

Open Genlk opened 1 year ago

Genlk commented 1 year ago

def image_preprocess(img_path): img = cv2.imread(img_path).astype("float32")/255

mean = [103.53, 116.28, 123.675] # Image net values

# std = [57.375, 57.12, 58.395]
mean = [113.533554, 118.14172, 123.63607]
std = [21.405144, 21.405144, 21.405144]
mean = np.array(mean, dtype=np.float32).reshape(1, 1, 3) / 255
std = np.array(std, dtype=np.float32).reshape(1, 1, 3) / 255
img = (img - mean) / std
img = np.transpose(img, (2, 0, 1))
img = np.expand_dims(img, axis=0)
return img

def test_onnx_model(onnx_model,img_path=None): if img_path is None: img_path = "path for img" imgdata = image_preprocess(img_path) sess = rt.InferenceSession(onnx_model) input_name = sess.get_inputs()[0].name output_detect_name = sess.get_outputs()[0].name pred_onnx0= sess.run([output_detect_name], {input_name: imgdata}) print("outputs:") print(np.array(pred_onnx0))