From 57216cb0fbeeb32101a3a4d2e11401cf1e7b5e3e Mon Sep 17 00:00:00 2001 From: ganler Date: Thu, 29 Jul 2021 21:05:24 +0800 Subject: [PATCH 1/3] fix: executor usage for keras tutorial --- tutorials/frontend/from_keras.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/frontend/from_keras.py b/tutorials/frontend/from_keras.py index 1c48aff799d4..ebea54e82b43 100644 --- a/tutorials/frontend/from_keras.py +++ b/tutorials/frontend/from_keras.py @@ -98,13 +98,13 @@ target = "cuda" dev = tvm.cuda(0) with tvm.transform.PassContext(opt_level=3): - executor = relay.build_module.create_executor("graph", mod, dev, target) + executor = relay.build_module.create_executor("graph", mod, dev, target).evaluate() ###################################################################### # Execute on TVM # --------------- dtype = "float32" -tvm_out = executor.evaluate()(tvm.nd.array(data.astype(dtype)), **params) +tvm_out = executor(tvm.nd.array(data.astype(dtype)), **params) top1_tvm = np.argmax(tvm_out.numpy()[0]) ##################################################################### From 3a2bf813ccc8a4c1eb3c54154dcc43b6df7f1003 Mon Sep 17 00:00:00 2001 From: ganler Date: Thu, 29 Jul 2021 21:06:01 +0800 Subject: [PATCH 2/3] fix: executor usage for onnx tutorial --- tutorials/frontend/from_onnx.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorials/frontend/from_onnx.py b/tutorials/frontend/from_onnx.py index 26aeb6ecaf38..2b905c397fd5 100644 --- a/tutorials/frontend/from_onnx.py +++ b/tutorials/frontend/from_onnx.py @@ -92,13 +92,13 @@ mod, params = relay.frontend.from_onnx(onnx_model, shape_dict) with tvm.transform.PassContext(opt_level=1): - intrp = relay.build_module.create_executor("graph", mod, tvm.cpu(0), target) + executor = relay.build_module.create_executor("graph", mod, tvm.cpu(0), target).evaluate() ###################################################################### # Execute on TVM # --------------------------------------------- dtype = "float32" -tvm_output = intrp.evaluate()(tvm.nd.array(x.astype(dtype)), **params).numpy() +tvm_output = executor(tvm.nd.array(x.astype(dtype)), **params).numpy() ###################################################################### # Display results From 2efd3c60af05ba0092f187c8db2fff0eff8d77a9 Mon Sep 17 00:00:00 2001 From: Junru Shao Date: Sun, 8 Aug 2021 12:08:25 -0700 Subject: [PATCH 3/3] [Tutorial][Executor] Fix executors in tutorials --- tutorials/dev/bring_your_own_datatypes.py | 4 ++-- tutorials/frontend/from_keras.py | 4 ++-- tutorials/frontend/from_onnx.py | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tutorials/dev/bring_your_own_datatypes.py b/tutorials/dev/bring_your_own_datatypes.py index 06d96e14d28c..bf09af9f3abe 100644 --- a/tutorials/dev/bring_your_own_datatypes.py +++ b/tutorials/dev/bring_your_own_datatypes.py @@ -262,9 +262,9 @@ def get_cat_image(): ###################################################################### # It's easy to execute MobileNet with native TVM: -ex = tvm.relay.create_executor("graph", mod=module) +ex = tvm.relay.create_executor("graph", mod=module, params=params) input = get_cat_image() -result = ex.evaluate()(input, **params).numpy() +result = ex.evaluate()(input).numpy() # print first 10 elements print(result.flatten()[:10]) diff --git a/tutorials/frontend/from_keras.py b/tutorials/frontend/from_keras.py index 1c48aff799d4..db1b3660ae31 100644 --- a/tutorials/frontend/from_keras.py +++ b/tutorials/frontend/from_keras.py @@ -98,13 +98,13 @@ target = "cuda" dev = tvm.cuda(0) with tvm.transform.PassContext(opt_level=3): - executor = relay.build_module.create_executor("graph", mod, dev, target) + executor = relay.build_module.create_executor("graph", mod, dev, target, params).evaluate() ###################################################################### # Execute on TVM # --------------- dtype = "float32" -tvm_out = executor.evaluate()(tvm.nd.array(data.astype(dtype)), **params) +tvm_out = executor(tvm.nd.array(data.astype(dtype))) top1_tvm = np.argmax(tvm_out.numpy()[0]) ##################################################################### diff --git a/tutorials/frontend/from_onnx.py b/tutorials/frontend/from_onnx.py index 26aeb6ecaf38..fd51d7a76992 100644 --- a/tutorials/frontend/from_onnx.py +++ b/tutorials/frontend/from_onnx.py @@ -92,13 +92,15 @@ mod, params = relay.frontend.from_onnx(onnx_model, shape_dict) with tvm.transform.PassContext(opt_level=1): - intrp = relay.build_module.create_executor("graph", mod, tvm.cpu(0), target) + executor = relay.build_module.create_executor( + "graph", mod, tvm.cpu(0), target, params + ).evaluate() ###################################################################### # Execute on TVM # --------------------------------------------- dtype = "float32" -tvm_output = intrp.evaluate()(tvm.nd.array(x.astype(dtype)), **params).numpy() +tvm_output = executor(tvm.nd.array(x.astype(dtype))).numpy() ###################################################################### # Display results