|
- import numpy as np
- import cv2
- from rknn.api import RKNN
- import torchvision.models as models
- import torch
- if __name__ == '__main__':
- model = 'pt/feature.pt'
- input_size_list = [[3, 127, 127]]
- inp_z = np.ones(shape=[127, 127, 3], dtype=np.uint8)*255
- # rknn inference
- rknn = RKNN()
- rknn.config(reorder_channel='0 1 2')
- ret = rknn.load_pytorch(model=model, input_size_list=input_size_list)
- ret = rknn.build(do_quantization=False)
- ret = rknn.init_runtime()
- outputs = rknn.inference(inputs=[inp_z])
- rknn.release()
- # pytorch inference
- inp_z = np.ones([3, 127, 127], dtype=np.uint8)*255
- inp_z = torch.Tensor(inp_z).unsqueeze(0)
- module = torch.jit.load(model)
- out = module.forward(inp_z)
- out = out.data.cpu().numpy()
- # difference between rknn and pytorch
- print(np.sum(np.abs(out-outputs)))
- WARNING: Token 'COMMENT' defined, but not used
- WARNING: There is 1 unused token
- W The target_platform is not set in config, using default target platform rk1808.
- W [set_chip_platform_env:187]evaluate model on RK1808
- 1459.6528
环境:x86 pc,rknn-toolkit1.3.2,pytorch1.2
请问为什么同一个模型的输出结果差这么大?
|
|