Potential bug about optimizing IRModule

Before transforming tvm.IRModule into runtime.Module, I use tvm.relay.optimize() to optimize IRModule. However, an exception was thrown. The involving model vgg16-cifar10.h5 can be installed through google drive: https://drive.google.com/file/d/1CQOtLADOOjNwm34OfHc7IiPKBikS3NT7/view?usp=sharing Below are my code and the exception.

import keras
import os
import tvm
from tvm import te
import tvm.relay as relay
import tvm.relay.transform as transform
import numpy as np
from PIL import Image
import tvm.runtime as runtime
from tvm.contrib import graph_runtime

input_tensor = 'input_4'

def image_resize(x, shape):
   x_return = []
   for x_test in x:
       tmp = np.copy(x_test)
       img = Image.fromarray(tmp.astype('uint8')).convert('RGB')
       img = img.resize(shape, Image.ANTIALIAS)
   return np.array(x_return)

input_precessor = keras.applications.vgg16.preprocess_input
input_shape = (224,224) #excption (299,299)
dataset_dir =  "/tensorflow/data/tvm/dataset"
data_path = os.path.join(dataset_dir,"imagenet-val-1500.npz")
data = np.load(data_path)
x, y = data['x_test'], data['y_test']

x_resize = image_resize(np.copy(x),input_shape)
x_test = input_precessor(x_resize)
y_test = keras.utils.to_categorical(y, num_classes=1000)

model_path = 'your_path/vgg16-cifar10.h5'
predict_model = keras.models.load_model(model_path)
shape_dict = {input_tensor: (1,3,224,224)}
irmod, params = relay.frontend.from_keras(predict_model, shape_dict)
target = 'llvm'
ctx = tvm.cpu(0)
irmod, params = relay.optimize(irmod,target=target,params=params)
with transform.PassContext(opt_level=3):
   graph, lib, params = relay.build_module.build(irmod, target, params=params)

I cannot figure out what happened and wonder if it’s a bug of TVM. Thank you in advance!!

latest master should resolve this issue. Please install the latest master code.

1 Like

OK, thank you for your reply

I have upgraded tvm to 0.7.dev1, but still encountered this problem. Maybe its a bug of TVM. -.-||

Do you build from source? Because recent pr : https://github.com/apache/incubator-tvm/pull/5938 has fixed this issue. If still exist, pr is more welcome.

1 Like

Thanks! I will learn about this.