您好,我在板子上用单帧数据进行推理,代码如下
`import os
import argparse
import numpy as np
from hbm_runtime import HB_HBMRuntime
`import os
import argparse
import numpy as np
from hbm_runtime import HB_HBMRuntime
=========================
Quant / Dequant
=========================
def quant_s16(x, scale):
x = np.round(x / scale)
x = np.clip(x, -32768, 32767)
return x.astype(np.int16)
x = np.round(x / scale)
x = np.clip(x, -32768, 32767)
return x.astype(np.int16)
def dequant(x, scale):
return x.astype(np.float32) * scale
return x.astype(np.float32) * scale
def dequant_pred_action(x, scales):
scales = np.asarray(scales, dtype=np.float32)
return x.astype(np.float32) * scales.reshape(1, 1, 1, -1)
scales = np.asarray(scales, dtype=np.float32)
return x.astype(np.float32) * scales.reshape(1, 1, 1, -1)
def ensure_shape(x, target_shape):
if list(x.shape) == list(target_shape):
return x
if x.ndim + 1 == len(target_shape) and list(x.shape) == list(target_shape[1:]):
return x[None, …]
raise ValueError(f"shape mismatch: got {x.shape}, expect {target_shape}")
if list(x.shape) == list(target_shape):
return x
if x.ndim + 1 == len(target_shape) and list(x.shape) == list(target_shape[1:]):
return x[None, …]
raise ValueError(f"shape mismatch: got {x.shape}, expect {target_shape}")
def load_npy(path, shape=None):
x = np.load(path)
if shape is not None:
x = ensure_shape(x, shape)
return x
x = np.load(path)
if shape is not None:
x = ensure_shape(x, shape)
return x
=========================
Fixed scales from txt
=========================
ENC_SCALES = {
“imgs”: 8.05689e-05,
“depths”: 3.13559e-05,
“pixels”: 0.00927763,
“projection_mat_inv”: 4.12e-05,
“hist_robot_state”: 8.79283e-05,
“joint_scale_shift”: 4.214e-05,
}
“imgs”: 8.05689e-05,
“depths”: 3.13559e-05,
“pixels”: 0.00927763,
“projection_mat_inv”: 4.12e-05,
“hist_robot_state”: 8.79283e-05,
“joint_scale_shift”: 4.214e-05,
}
ENC_OUT_SCALES = {
“image_feature”: 0.000160504,
“robot_feature”: 0.000148256,
}
“image_feature”: 0.000160504,
“robot_feature”: 0.000148256,
}
DEC_SCALES = {
“noisy_action”: 0.000109733,
“image_feature”: 0.000123757,
“robot_feature”: 0.000240683,
}
“noisy_action”: 0.000109733,
“image_feature”: 0.000123757,
“robot_feature”: 0.000240683,
}
DEC_OUT_SCALES = {
“pred_action”: [
1.2237e-07, 1.2983e-07, 1.32331e-07, 1.23848e-07,
2.87956e-07, 5.22757e-07, 2.07495e-07, 3.08358e-07,
]
}
“pred_action”: [
1.2237e-07, 1.2983e-07, 1.32331e-07, 1.23848e-07,
2.87956e-07, 5.22757e-07, 2.07495e-07, 3.08358e-07,
]
}
=========================
Main
=========================
def main():
ap = argparse.ArgumentParser()
ap.add_argument(“–encoder”, required=True)
ap.add_argument(“–decoder”, required=True)
ap.add_argument(“–case_dir”, required=True)
ap.add_argument(“–save_dir”, default=“./dump_manual”)
args = ap.parse_args()
ap = argparse.ArgumentParser()
ap.add_argument(“–encoder”, required=True)
ap.add_argument(“–decoder”, required=True)
ap.add_argument(“–case_dir”, required=True)
ap.add_argument(“–save_dir”, default=“./dump_manual”)
args = ap.parse_args()
if name == “main”:
main()`
main()`
然后我在开发机上用hbdk4-compiler== 4.2.11,horizon_tc_ui==3.3.22对hbm进行推理,代码如下
然后和onnx的做对比,发现板子上cos是0.99+,但是开发机上就是0.79,输入和对比文件一样,这是为什么呀,麻烦各位大佬看一下
