How Implement a customized Keras models into TVM nnvm

Can someone please tell me what I am doing wrong here. I am trying to implement a keras model that I trained and saved the weight.I want to implement my own model. In the first part,I have defined the model which is model that is similar to lenet model. Then, in the second file I have imported the model and loaded the weights and did preprocessing. but I get an empty error and the model of the nnvm.frontend.from_keras() doesn’t run and I get an empty error.

def lenet_model(img_shape=(28, 28, 1), n_classes=10, l2_reg=0.,weights=None):

# Initialize model
lenet = Sequential()

# 2 sets of CRP (Convolution, RELU, Pooling)
lenet.add(Conv2D(20, (5, 5), padding="same",
    input_shape=img_shape, kernel_regularizer=l2(l2_reg)))
lenet.add(Activation("relu"))
lenet.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))

lenet.add(Conv2D(50, (5, 5), padding="same",
    kernel_regularizer=l2(l2_reg)))
lenet.add(Activation("relu"))
lenet.add(MaxPooling2D(pool_size=(2, 2), strides=(2, 2)))

# Fully connected layers (w/ RELU)
lenet.add(Flatten())
lenet.add(Dense(500, kernel_regularizer=l2(l2_reg)))
lenet.add(Activation("relu"))

# Softmax (for classification)
lenet.add(Dense(n_classes, kernel_regularizer=l2(l2_reg)))
lenet.add(Activation("softmax"))

if weights is not None:
    lenet.load_weights(weights)

# Return the constructed network
return lenet

and this is the code where I import the model to use it and pass it to nnvm:

def download_block_from_keras(args):
import keras
if args.model == "lenet":
    model_lenet = lenet.lenet_model(img_shape=(28, 28, 1), n_classes=10, l2_reg=0.,
                        weights=None)
    model_lenet.load_weights("lenet_mnist.hdf5")
    print("weights loaded")
    from PIL import Image
    from keras.applications.resnet50 import preprocess_input
    img_url = 'https://github.com/dmlc/mxnet.js/blob/master/data/cat.png?raw=true'
    download(img_url, 'cat.png')
    img = Image.open('cat.png').resize((28, 28))
    # input preprocess
    data = np.array(img)[np.newaxis, :].astype('float32')
    data = preprocess_input(data).transpose([0, 3, 1, 2])

    shape_dict = {'input_1': data.shape}
    sym, params = nnvm.frontend.from_keras(model_lenet)
    print("sym, parms received")               
    target = 'llvm'
    print("target is llvm")
else:
    print("not supported model; supported models:", supported_models)
    exit()

model_layers = get_dataflow(sym, target, shape_dict, params, args.batch_size)
return model_layers

This line doesn’t run " sym, params = nnvm.frontend.from_keras(model_lenet)", and I get an empty error "Error: "

NNVM is deprecated in tvm 4496. You should consider using relay https://tvm.apache.org/docs/tutorials/frontend/from_keras.html.

1 Like