[Bug] VirtualMachin.run() error: Check failed: ret == 0 (-1 vs. 0) : Assert fail: (((tir.tvm_struct_get(arg.p0, 0, 5) == (uint8)1)

Good afternoon I’m having a problem when running VirtualMachine.run(). I’m trying to run the ssd_mobilenetv1_coco model from the official tf repository (tf1 model) https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tf1_detection_zoo.md

Expected behavior

Array of the form [BOXES_NAME, CLASSES_NAME, SCORES_NAME, NUM_DETECTIONS_NAME]

Actual behavior

Reading an image in float32 format: Check failed: ret == 0 (-1 vs. 0) : Assert fail: (((tir.tvm_struct_get(arg.p0, 0, 5) == (uint8)1) && (tir.tvm_struct_get(arg.p0, 0, 6) == (uint8)8)) && (tir.tvm_struct_get(arg.p0, 0, 7) == (uint16)1)), arg.p0.dtype is expected to be uint8 I also tried to read an image in uint8 format and got the following error: Check failed: ret == 0 (-1 vs. 0) : Assert fail: (int32(arg.p0.shape[1]) == 300), Argument arg.p0.shape[1] has an unsatisfied constraint: (300 == int32(arg.p0.shape[1]))

Environment

Python 3.7.12 tvm==0.11.1(This error also occurs on 0.14dev) tensorflow 1.14.0 opencv-python 4.8.1.78

Steps to reproduce

import numpy as np
import tvm
import cv2
from tvm import te
import tvm.relay as relay
from tvm.contrib.download import download_testdata

from tvm.runtime import vm as _vm
from tvm.relay import vm as rly_vm
import tensorflow as tf
import tvm.relay.testing.tf as tf_testing
import tensorflow as tf

from tvm.runtime import vm as _vm
from tvm.relay import vm as rly_vm

model_path = 'ssd_mobilenet_v1_coco_2018_01_28/frozen_inference_graph.pb'
with tf.gfile.GFile(model_path, "rb") as f:
    graph_def = tf.GraphDef()
    graph_def.ParseFromString(f.read())
    graph = tf.import_graph_def(graph_def, name="")
    # Call the utility to import the graph definition into default graph.
    graph_def = tf_testing.ProcessGraphDefParam(graph_def)
BOXES_NAME = 'detection_boxes'
CLASSES_NAME = 'detection_classes'
SCORES_NAME = 'detection_scores'
NUM_DETECTIONS_NAME = 'num_detections'
out_names = [BOXES_NAME, CLASSES_NAME, SCORES_NAME, NUM_DETECTIONS_NAME]

input_name = "image_tensor"
input_shape = (1, 300, 300, 3)
mod, params = relay.frontend.from_tensorflow(
    graph_def, outputs=out_names, shape={input_name: input_shape}
)

target = tvm.target.Target("llvm")
dev = tvm.cpu(0)
with tvm.transform.PassContext(opt_level=1, disabled_pass=["AlterOpLayout"]):
    executable = rly_vm.compile(mod, target=target, params=params)
des_vm = _vm.VirtualMachine(executable, dev)

img = cv2.imread('../../img/apple.JPEG').astype("float32")
img = cv2.resize(img, (300, 300))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = np.transpose(img, [2, 0, 1])
img = np.expand_dims(img, axis=0)
des_vm.run(img)

I also tried running it like this:

data = {'image_tensor': np.expand_dims(img_data, axis=0)}
des_vm.set_input('main', **data)

P.S. I use TensorFlow version < 2, because on versions greater than 2 the relay.frontend.from_tensorflow(...) function crashes.

Have you sovled this problem? I met the same

I figure mine out. I forget to set the dtype of the output tvm array.