RuntimeError: Could not find 'input_1' in graph's inputs

The model can be converted to Relay and compiled very well. However, when use the statement module.set_input('input_1', x_test.astype(dtype)), I will crash.

image

How do I set the first parameter of module.set_input()?

Any comments are welcome. Thanks in advance.

My script is as follows:

import keras
from keras.utils import to_categorical
import tvm
import tvm.relay as relay
from tvm.contrib import graph_runtime
import numpy as np
import tensorflow as tf
try:
    tf_compat_v1 = tf.compat.v1
except ImportError:
    tf_compat_v1 = tf


def get_data(size):
    _, (x_test, y_test) = keras.datasets.cifar100.load_data()
    x_test = x_test.astype('float32') / 255.0
    w, h = 32, 32
    x_test = x_test.reshape(x_test.shape[0], w, h, 3)
    x_test, y_test = x_test[:size], y_test[:size]
    y_test = y_test.transpose([1, 0])[0]
    y_test = np.array(y_test)
    y_test = to_categorical(y_test)
    return x_test, y_test


model_path = "resnet20-cifar100_origin.pb"

with tf_compat_v1.gfile.GFile(model_path, "rb") as f:
    graph_def = tf_compat_v1.GraphDef()
    graph_def.ParseFromString(f.read())

batch_size = 10
x_test, y_test = get_data(batch_size)

input_shape = (batch_size, 32, 32, 3)
output_shape = (batch_size, y_test[0].size)
shape_dict = {'input_1': input_shape}
irmod, params = relay.frontend.from_tensorflow(graph_def, layout='NHWC', shape=shape_dict)

target = 'llvm'
ctx = tvm.cpu(0)
with tvm.transform.PassContext(opt_level=3):
    graph, lib, params = relay.build_module.build(
        irmod, target=target, params=params)

module = graph_runtime.create(graph, lib, ctx)
dtype = 'float32'
module.set_input('input_1', x_test.astype(dtype))
module.set_input(**params)  # Crash here!!!
module.run()
res_tvm = module.get_output(0, tvm.nd.empty(output_shape)).asnumpy()

Part of the model info:

@tqchen @masahi Could you give me some advice? Thanks very match.

Can you try print(graph) and see what input name it expects.

The graph content generated by relay.build_module.build() is as following:

I don’t know which field represents input name.

In addition, I added a few lines of code, which have a background color, to print the input layer information,

The printing contents show that the input name is input_1 with the shape (?, 32, 32,3) input_1 (<tf.Tensor 'input_1:0' shape=(?, 32, 32, 3) dtype=float32>,)

sorry what you need is print(irmod). Look for the name after main like below:

def @main(%input_tensor:0: Tensor[(1, 300, 300, 3), uint8]) -> (Tensor[(1, 100, 4), float32], Tensor[(1, 100), float32], Tensor[(1, 100), float32], Tensor[(1), float32]) {

The content of this irmod is not similar to the content you gave image

You can access the full content of irmod from the link:

the model resnet20-cifar100_origin.pb link: