So set your n00b bit as you read this please. I’m getting up to speed with TVM so dumb errors are likely.
Given:
import numpy as np
import pprint
import os
import tvm
import tvm.relay.testing
from PIL import Image
from tvm import relay
from tvm.contrib import graph_runtime
from tvm.contrib.download import download_testdata
batch_size = 1
input_tensor = "input"
# number of outputs (ie number of categories in the mobilenet model
num_class = 1000
image_shape = (3, 244,244)
input_dtype="float32"
data_shape = (batch_size, ) + image_shape
out_shape= (batch_size, num_class)
image_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true'
image_path = download_testdata(image_url, 'cat.png', module='data')
resized_image = Image.open(image_path).resize((224, 224))
image_data = np.asarray(resized_image).astype("float32")
print('input', image_data.shape)
image_data = np.expand_dims(image_data, axis=0)
print('input', image_data.shape)
image_data[:, :, :, 0] = 2.0 / 255.0 * image_data[:, :, :, 0] - 1
image_data[:, :, :, 1] = 2.0 / 255.0 * image_data[:, :, :, 1] - 1
image_data[:, :, :, 2] = 2.0 / 255.0 * image_data[:, :, :, 2] - 1
# NHWC -> NCHW
new_image_data = np.transpose(image_data, [0, 3, 1, 2])
print('fixed input', new_image_data.shape)
mod, params = relay.testing.mobilenet.get_workload(batch_size, num_class,image_shape, input_dtype, 'NCHW')
#create a runtime executor module
target='llvm'
with relay.build_config(opt_level=1): # 1, 2, 3 all result in the same issue
graph, lib, params = relay.build(mod, target, params=params)
runtime_module = graph_runtime.create(graph, lib, tvm.cpu())
# dies here in set_input
runtime_module.set_input(input_tensor, tvm.nd.array(new_image_data))
runtime_module.set_input(**params)
runtime_module.run()
tvm_output = module.get_output(0).asnumpy()
# Load label file
label_file_url = ''.join(['https://raw.githubusercontent.com/',
'tensorflow/tensorflow/master/tensorflow/lite/java/demo/',
'app/src/main/assets/',
'labels_mobilenet_quant_v1_224.txt'])
label_file = "labels_mobilenet_quant_v1_224.txt"
label_path = download_testdata(label_file_url, label_file, module='data')
# List of 1001 classes
with open(label_path) as f:
labels = f.readlines()
# Convert result to 1D data
predictions = np.squeeze(tvm_output)
# Get top 1 prediction
prediction = np.argmax(predictions)
# Convert id to class name and show the result
print("The image prediction result is: id " + str(prediction) + " name: " + labels[prediction])
When run I get the following output :
File /home/debian/.tvm_test_data/data/cat.png exists, skip.
input (224, 224, 3)
input (1, 224, 224, 3)
fixed input (1, 3, 224, 224)
(I presume a bunch of these messages aren't anything to worry about)
Cannot find config for target=llvm, 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, workload=('conv2d_NCHWc.x86', ('TENSOR', (1, 1024, 8, 8), '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, workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 1024, 8, 8), '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, workload=('conv2d_NCHWc.x86', ('TENSOR', (1, 512, 8, 8), '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, workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 512, 16, 16), '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, workload=('conv2d_NCHWc.x86', ('TENSOR', (1, 512, 16, 16), '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, workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 512, 16, 16), '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, workload=('conv2d_NCHWc.x86', ('TENSOR', (1, 256, 16, 16), '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, workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 256, 31, 31), '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, workload=('conv2d_NCHWc.x86', ('TENSOR', (1, 256, 31, 31), '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, workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 256, 31, 31), '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, workload=('conv2d_NCHWc.x86', ('TENSOR', (1, 128, 31, 31), '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, workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 128, 61, 61), '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, workload=('conv2d_NCHWc.x86', ('TENSOR', (1, 128, 61, 61), '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, workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 128, 61, 61), '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, workload=('conv2d_NCHWc.x86', ('TENSOR', (1, 64, 61, 61), '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, workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 64, 122, 122), '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, workload=('conv2d_NCHWc.x86', ('TENSOR', (1, 32, 122, 122), '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, workload=('depthwise_conv2d_NCHWc.x86', ('TENSOR', (1, 32, 122, 122), '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, workload=('conv2d_NCHWc.x86', ('TENSOR', (1, 3, 244, 244), '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.
[12:55:15] /home/debian/tvm/src/runtime/graph/graph_runtime.cc:93: Warning: cannot find "input" among input
Traceback (most recent call last):
File "firtgo-gen.py", line 51, in <module>
runtime_module.set_input(input_tensor, tvm.nd.array(new_image_data))
File "/home/debian/tvm/python/tvm/contrib/graph_runtime.py", line 157, in set_input
self._get_input(key).copyfrom(value)
File "/home/debian/tvm/python/tvm/_ffi/_ctypes/packed_func.py", line 216, in __call__
raise get_last_ffi_error()
tvm._ffi.base.TVMError: Traceback (most recent call last):
[bt] (3) /home/debian/tvm/build/libtvm.so(TVMFuncCall+0x4c) [0xffffb623925c]
[bt] (2) /home/debian/tvm/build/libtvm.so(+0xc4ec68) [0xffffb62a0c68]
[bt] (1) /home/debian/tvm/build/libtvm.so(+0xc4eaf8) [0xffffb62a0af8]
[bt] (0) /home/debian/tvm/build/libtvm.so(dmlc::LogMessageFatal::~LogMessageFatal()+0x38) [0xffffb59ffff8]
File "/home/debian/tvm/src/runtime/graph/graph_runtime.cc", line 445
TVMError: Check failed: in_idx >= 0 (-1 vs. 0) :
The error message is the same regardless of opt_level setting. The error also occurs both in intel and arm64.
Thanks for any suggestions including RTFM.