from tvm import relay
from tvm.relay import testing
import numpy as np
from infrastructure import get_ref_result

batch_size = 1
num_class = 1000
image_shape = (3, 224, 224)
data_shape = (batch_size,) + image_shape
out_shape = (batch_size, num_class)
dtype="float32"

mod, params = relay.testing.mobilenet.get_workload(
    batch_size=batch_size, num_classes=num_class, image_shape=image_shape, 
layout='NCHW'
)

#print(mod.astext(show_meta_data=False))

data = np.random.uniform(size=data_shape).astype(dtype)
print(data)

ref_out = get_ref_result(data, mod, params, out_shape, dtype)
print(ref_out)


get_ref_result looks like:
def get_ref_result(data, mod, params, out_shape, dtype):
    target = "llvm"
    with tvm.transform.PassContext(opt_level=3, 
disabled_pass=["AlterOpLayout"]):
        lib  = relay.build(mod, target, params=params)
    cpu_mod = graph_runtime.GraphModule(lib["default"](tvm.cpu()))
    cpu_mod.set_input("data", data)
    cpu_mod.run()
    cpu_out = cpu_mod.get_output(0, tvm.nd.empty(out_shape, dtype))
    return cpu_out


output:
================================================================
[[[[0.48127168 0.2018001  0.71724653 ... 0.0441279  0.57116777
    0.1731153 ]
   [0.40417442 0.3016946  0.74636394 ... 0.3417648  0.718218
    0.28890228]
   [0.7683302  0.17131594 0.9016031  ... 0.5153679  0.74072677
    0.03374053]
   ...
   [0.6947896  0.6551721  0.85114497 ... 0.35421443 0.20508686
    0.6471268 ]
   [0.09923462 0.61146086 0.08773897 ... 0.53768474 0.31748652
    0.64678025]
   [0.31008628 0.56266195 0.83621436 ... 0.9968801  0.4973068
    0.09383171]]

  [[0.73113763 0.17166294 0.5789204  ... 0.03240918 0.0247721
    0.89045954]
   [0.46058905 0.3739123  0.56078994 ... 0.38859197 0.36561185
    0.7287658 ]
   [0.8079502  0.39894798 0.6348208  ... 0.56089103 0.58005774
    0.52373666]
   ...
   [0.4517257  0.8520253  0.40640992 ... 0.1651029  0.22171977
    0.35451823]
   [0.9394899  0.7759206  0.5117806  ... 0.99209446 0.24618751
    0.57113916]
   [0.6102327  0.08231816 0.7101693  ... 0.77034265 0.9671634
    0.5752965 ]]

  [[0.3101213  0.192366   0.22534423 ... 0.828487   0.59424293
    0.21207647]
   [0.8794648  0.09954574 0.30758655 ... 0.051931   0.03809953
    0.3480195 ]
   [0.81616604 0.92345166 0.36221072 ... 0.93277586 0.79536366
    0.42082992]
   ...
   [0.621181   0.4233806  0.83933717 ... 0.44883785 0.4910011
    0.3370444 ]
   [0.9489613  0.7982109  0.709624   ... 0.6371652  0.5758706
    0.6982647 ]
   [0.36476108 0.2929088  0.49834147 ... 0.87037426 0.40084326
    0.3614452 ]]]]
Cannot find config for target=llvm -keys=cpu, workload=('dense_nopack.x86', 
('TENSOR', (1, 1024), 'float32'), ('TENSOR', (1000, 1024), 'float32'), None, 
'float32'). A fallback configuration is used, which may bring great performance 
regression.
Cannot find config for target=llvm -keys=cpu, workload=('conv2d_NCHWc.x86', 
('TENSOR', (1, 1024, 7, 7), 'float32'), ('TENSOR', (1024, 1024, 1, 1), 
'float32'), (1, 1), (0, 0, 0, 0), (1, 1), 'NCHW', 'NCHW', 'float32'). A 
fallback configuration is used, which may bring great performance regression.
Cannot find config for target=llvm -keys=cpu, 
workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 1024, 7, 7), 'float32'), 
('TENSOR', (1024, 1, 3, 3), 'float32'), (1, 1), (1, 1, 1, 1), (1, 1), 'NCHW', 
'NCHW', 'float32'). A fallback configuration is used, which may bring great 
performance regression.
Cannot find config for target=llvm -keys=cpu, workload=('conv2d_NCHWc.x86', 
('TENSOR', (1, 512, 7, 7), 'float32'), ('TENSOR', (1024, 512, 1, 1), 
'float32'), (1, 1), (0, 0, 0, 0), (1, 1), 'NCHW', 'NCHW', 'float32'). A 
fallback configuration is used, which may bring great performance regression.
Cannot find config for target=llvm -keys=cpu, 
workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 512, 14, 14), 
'float32'), ('TENSOR', (512, 1, 3, 3), 'float32'), (2, 2), (1, 1, 1, 1), (1, 
1), 'NCHW', 'NCHW', 'float32'). A fallback configuration is used, which may 
bring great performance regression.
Cannot find config for target=llvm -keys=cpu, workload=('conv2d_NCHWc.x86', 
('TENSOR', (1, 512, 14, 14), 'float32'), ('TENSOR', (512, 512, 1, 1), 
'float32'), (1, 1), (0, 0, 0, 0), (1, 1), 'NCHW', 'NCHW', 'float32'). A 
fallback configuration is used, which may bring great performance regression.
Cannot find config for target=llvm -keys=cpu, 
workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 512, 14, 14), 
'float32'), ('TENSOR', (512, 1, 3, 3), 'float32'), (1, 1), (1, 1, 1, 1), (1, 
1), 'NCHW', 'NCHW', 'float32'). A fallback configuration is used, which may 
bring great performance regression.
Cannot find config for target=llvm -keys=cpu, workload=('conv2d_NCHWc.x86', 
('TENSOR', (1, 256, 14, 14), 'float32'), ('TENSOR', (512, 256, 1, 1), 
'float32'), (1, 1), (0, 0, 0, 0), (1, 1), 'NCHW', 'NCHW', 'float32'). A 
fallback configuration is used, which may bring great performance regression.
Cannot find config for target=llvm -keys=cpu, 
workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 256, 28, 28), 
'float32'), ('TENSOR', (256, 1, 3, 3), 'float32'), (2, 2), (1, 1, 1, 1), (1, 
1), 'NCHW', 'NCHW', 'float32'). A fallback configuration is used, which may 
bring great performance regression.
Cannot find config for target=llvm -keys=cpu, workload=('conv2d_NCHWc.x86', 
('TENSOR', (1, 256, 28, 28), 'float32'), ('TENSOR', (256, 256, 1, 1), 
'float32'), (1, 1), (0, 0, 0, 0), (1, 1), 'NCHW', 'NCHW', 'float32'). A 
fallback configuration is used, which may bring great performance regression.
Cannot find config for target=llvm -keys=cpu, 
workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 256, 28, 28), 
'float32'), ('TENSOR', (256, 1, 3, 3), 'float32'), (1, 1), (1, 1, 1, 1), (1, 
1), 'NCHW', 'NCHW', 'float32'). A fallback configuration is used, which may 
bring great performance regression.
Cannot find config for target=llvm -keys=cpu, workload=('conv2d_NCHWc.x86', 
('TENSOR', (1, 128, 28, 28), 'float32'), ('TENSOR', (256, 128, 1, 1), 
'float32'), (1, 1), (0, 0, 0, 0), (1, 1), 'NCHW', 'NCHW', 'float32'). A 
fallback configuration is used, which may bring great performance regression.
Cannot find config for target=llvm -keys=cpu, 
workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 128, 56, 56), 
'float32'), ('TENSOR', (128, 1, 3, 3), 'float32'), (2, 2), (1, 1, 1, 1), (1, 
1), 'NCHW', 'NCHW', 'float32'). A fallback configuration is used, which may 
bring great performance regression.
Cannot find config for target=llvm -keys=cpu, workload=('conv2d_NCHWc.x86', 
('TENSOR', (1, 128, 56, 56), 'float32'), ('TENSOR', (128, 128, 1, 1), 
'float32'), (1, 1), (0, 0, 0, 0), (1, 1), 'NCHW', 'NCHW', 'float32'). A 
fallback configuration is used, which may bring great performance regression.
Cannot find config for target=llvm -keys=cpu, 
workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 128, 56, 56), 
'float32'), ('TENSOR', (128, 1, 3, 3), 'float32'), (1, 1), (1, 1, 1, 1), (1, 
1), 'NCHW', 'NCHW', 'float32'). A fallback configuration is used, which may 
bring great performance regression.
Cannot find config for target=llvm -keys=cpu, workload=('conv2d_NCHWc.x86', 
('TENSOR', (1, 64, 56, 56), 'float32'), ('TENSOR', (128, 64, 1, 1), 'float32'), 
(1, 1), (0, 0, 0, 0), (1, 1), 'NCHW', 'NCHW', 'float32'). A fallback 
configuration is used, which may bring great performance regression.
Cannot find config for target=llvm -keys=cpu, 
workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 64, 112, 112), 
'float32'), ('TENSOR', (64, 1, 3, 3), 'float32'), (2, 2), (1, 1, 1, 1), (1, 1), 
'NCHW', 'NCHW', 'float32'). A fallback configuration is used, which may bring 
great performance regression.
Cannot find config for target=llvm -keys=cpu, workload=('conv2d_NCHWc.x86', 
('TENSOR', (1, 32, 112, 112), 'float32'), ('TENSOR', (64, 32, 1, 1), 
'float32'), (1, 1), (0, 0, 0, 0), (1, 1), 'NCHW', 'NCHW', 'float32'). A 
fallback configuration is used, which may bring great performance regression.
Cannot find config for target=llvm -keys=cpu, 
workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 32, 112, 112), 
'float32'), ('TENSOR', (32, 1, 3, 3), 'float32'), (1, 1), (1, 1, 1, 1), (1, 1), 
'NCHW', 'NCHW', 'float32'). A fallback configuration is used, which may bring 
great performance regression.
Cannot find config for target=llvm -keys=cpu, workload=('conv2d_NCHWc.x86', 
('TENSOR', (1, 3, 224, 224), 'float32'), ('TENSOR', (32, 3, 3, 3), 'float32'), 
(2, 2), (1, 1, 1, 1), (1, 1), 'NCHW', 'NCHW', 'float32'). A fallback 
configuration is used, which may bring great performance regression.
[[0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001 0.001
  0.001 0.001 0.001 0.001]]





---
[Visit 
Topic](https://discuss.tvm.apache.org/t/why-the-mobilenet-workload-result-is-all-0-001/8420/1)
 to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click 
here](https://discuss.tvm.apache.org/email/unsubscribe/b47f7234fdfe9346d9242f3f911cb6bf93d64344d7625b75f239eb035e325a54).

Reply via email to