ValueError: not enough values to unpack (expected 4, got 0)

Traceback (most recent call last):
File “onnx_test_hls.py”, line 57, in
shape = shape_dict, params=params)
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/nnvm/python/nnvm/compiler/build_module.py”, line 305, in build
graph = graph.apply(“GraphCompile”)
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/nnvm/python/nnvm/graph.py”, line 234, in apply
check_call(_LIB.NNGraphApplyPasses(self.handle, npass, cpass, ctypes.byref(ghandle)))
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/nnvm/python/nnvm/_base.py”, line 75, in check_call
raise NNVMError(py_str(_LIB.NNGetLastError()))
nnvm._base.NNVMError: TVMCall CFunc Error:
Traceback (most recent call last):
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/python/tvm/_ffi/_ctypes/function.py”, line 55, in cfun
rv = local_pyfunc(*pyargs)
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/nnvm/python/nnvm/top/nn.py”, line 106, in compute_conv2d
inputs[0], kernel, strides, padding, layout, out_dtype=out_dtype)
File “”, line 2, in conv2d
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/python/tvm/target.py”, line 349, in dispatch_func
return dispatch_dict[k](*args, **kwargs)
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/topi/python/topi/x86/conv2d.py”, line 119, in _declaration_conv
wkl = _get_workload(data, kernel, stride, padding, out_dtype)
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/topi/python/topi/nn/conv2d.py”, line 79, in _get_workload
_, CI, IH, IW = [x.value for x in data.shape]
ValueError: not enough values to unpack (expected 4, got 0)

The code is as follow:
######################################################################

Build TVM Runtime on Device by hls

---------------------------

######################################################################

import nnvm
import tvm
import onnx
import numpy as np
from tvm import rpc
from tvm.contrib import util
from PIL import Image
import nnvm.compiler
from tvm.contrib import graph_runtime

######################## load the data ############################
img = Image.open(‘test.jpg’).resize((256, 192))
#img = img.cuda(async=True)
img_var = np.array(img)
x = img_var
#print(x)

######################## load raw onnx model ######################
onnx_model = onnx.load(’./onnx/posenet.onnx’)
net, params = nnvm.frontend.from_onnx(onnx_model)
#print(params)
input_name = net.list_input_names()[1]

shape_dict = {input_name: x.shape}

####################### set parameters #############################
batch_size = 1
image_shape = (3, 192, 256)
data_shape = (batch_size, ) + image_shape
out_shape = (batch_size, 2, 14, 192, 256) #[B, nStacks, 2*C, H, W] 14 is 14 feature maps and 14*3 points

##################################################################

local_demo = True
if local_demo:
target = ‘llvm’
target_host = “llvm”
else:
target_host = ‘llvm -target = aarch64-linux-gnu’
target = tvm.target.mali()

####################### save Model Func #############################
#print(data_shape)
with nnvm.compiler.build_config(opt_level=2):
graph, lib, params = nnvm.compiler.build(net, target=target,
shape = shape_dict, params=params)

tmp = util.tempdir()
lib_fname = tmp.relpath(‘net.tar’)
lib.export_library(lib_fname)

################# Deploy the Model Remotely by RPC #################

if local_demo:
remote = rpc.LocalSession()
else:
host = ‘’
port = 9091
remote = rpc.connect(host, port)

remote.upload(lib_fname)
rlib = remote.load_module(‘net.tar’)

ctx = remote.cpu(0) if local_demo else remote.cl(0)

upload the parameter

rparams = {k: tvm.nd.array(v, ctx) for k, v in params.items()}

create the remote runtime module

module = graph_runtime.create(graph, rlib, ctx)

set parameter

module.set_input(**rparams)

set input data

module.set_input(‘data’, tvm.nd.array(x.astype(‘float32’)))

run

module.run()

get output

out = module.get_output(0, tvm.nd.empty(out_shape, ctx=ctx))

So it failed both with local_demo and non-local_demo, right?

I think shape_dict, which you pass to nnvm.compiler.build is incorrect, should be {input_name: data_shape}. though not sure whether there’s any other problem with the model itself.

shape_dict = {input_name: x.shape}
Yes, it failed both with target=“cuda” and target=“llvm” with local_demo.

x.shape is 3-d, I believe your model requires 4-D input

I’m sorry. And I modified it. But as the same. Even shape_dict is 4D, the output is the same error. Just like follow:

{‘data’: (1, 3, 192, 256)} (Now my input is 4D)
_get_workload… (But the input “data” to this func is still null.)
Tensor(shape=[], op.name=input0)

Traceback (most recent call last):
File “onnx_test_hls.py”, line 57, in
shape = shape_dict, params=params)
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/nnvm/python/nnvm/compiler/build_module.py”, line 305, in build
graph = graph.apply(“GraphCompile”)
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/nnvm/python/nnvm/graph.py”, line 234, in apply
check_call(_LIB.NNGraphApplyPasses(self.handle, npass, cpass, ctypes.byref(ghandle)))
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/nnvm/python/nnvm/_base.py”, line 75, in check_call
raise NNVMError(py_str(_LIB.NNGetLastError()))
nnvm._base.NNVMError: TVMCall CFunc Error:
Traceback (most recent call last):
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/python/tvm/_ffi/_ctypes/function.py”, line 55, in cfun
rv = local_pyfunc(*pyargs)
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/nnvm/python/nnvm/top/nn.py”, line 106, in compute_conv2d
inputs[0], kernel, strides, padding, layout, out_dtype=out_dtype)
File “”, line 2, in conv2d
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/python/tvm/target.py”, line 349, in dispatch_func
return dispatch_dict[k](*args, **kwargs)
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/topi/python/topi/x86/conv2d.py”, line 119, in _declaration_conv
wkl = _get_workload(data, kernel, stride, padding, out_dtype)
File “/home/hls/Documents/MyWorkplace/sofeware/tvm/topi/python/topi/nn/conv2d.py”, line 80, in _get_workload
_, CI, IH, IW = [x.value for x in data.shape]
ValueError: not enough values to unpack (expected 4, got 0)