| 58 | return coremltools.models.MLModel(builder.spec) |
| 59 | |
| 60 | def verify(coreml_model, model_path, dev): |
| 61 | coreml_model = create_coreml_model() |
| 62 | |
| 63 | out_spec = coreml_model.output_description._fd_spec |
| 64 | out_names = [spec.name for spec in out_spec] |
| 65 | |
| 66 | # inference via coremltools |
| 67 | inputs = {} |
| 68 | for in_spec in coreml_model.input_description._fd_spec: |
| 69 | name = in_spec.name |
| 70 | shape = in_spec.type.multiArrayType.shape |
| 71 | inputs[name] = np.random.random_sample(shape) |
| 72 | |
| 73 | coreml_outputs = [coreml_model.predict(inputs)[name] for name in out_names] |
| 74 | |
| 75 | # inference via tvm coreml runtime |
| 76 | runtime = coreml_runtime.create("main", model_path, dev) |
| 77 | for name in inputs: |
| 78 | runtime.set_input(name, tvm.runtime.tensor(inputs[name], dev)) |
| 79 | runtime.invoke() |
| 80 | tvm_outputs = [runtime.get_output(i).numpy() for i in range(runtime.get_num_outputs())] |
| 81 | |
| 82 | for c_out, t_out in zip(coreml_outputs, tvm_outputs): |
| 83 | np.testing.assert_almost_equal(c_out, t_out, 3) |
| 84 | |
| 85 | def check_remote(coreml_model): |
| 86 | temp = utils.tempdir() |