()
| 13 | return str(stdout) |
| 14 | |
| 15 | def run_torchscript(): |
| 16 | import torchvision.models as models |
| 17 | import onnxruntime as ort |
| 18 | import torch |
| 19 | resnet18 = models.resnet18(pretrained=True) |
| 20 | x = torch.rand(1, 3, 224, 224) |
| 21 | resnet18_ts = torch.jit.trace(resnet18, x) |
| 22 | resnet18_ts.save(ts_module) |
| 23 | torch.onnx.export(resnet18, x, onnx_module) |
| 24 | on_module = ort.InferenceSession(onnx_module) |
| 25 | inputs = {} |
| 26 | for inp in on_module.get_inputs(): |
| 27 | inputs[inp.name] = x.numpy() |
| 28 | y = on_module.run(None, inputs)[0] |
| 29 | nx = x.numpy().reshape(-1) |
| 30 | ny = y.reshape(-1) |
| 31 | np.savetxt(input_file, nx, fmt='%f') |
| 32 | np.savetxt(output_file, ny, fmt='%f') |
| 33 | |
| 34 | def run_mnn(): |
| 35 | # convert to mnn module |
no test coverage detected