Compile Keras Neural Network Models

Hi,

I have written very simple Keras Neural Network

from numpy import loadtxt
from keras.models import Sequential
from keras.layers import Dense

# load the dataset
dataset = loadtxt('pima-indians-diabetes.csv', delimiter=',')

# split into input (X) and output (y) variables
X = dataset[:,0:8]
y = dataset[:,8]
print("X Shape", X.shape)
print("Y shape", y.shape)

# define the keras model
model = Sequential()
model.add(Dense(12, input_dim=8, activation='relu'))
model.add(Dense(8, activation='relu'))
model.add(Dense(1, activation='sigmoid'))

# compile the keras model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

# fit the keras model on the dataset
model.fit(X, y, epochs=150, batch_size=10, verbose=0)

model.save("my_model2.h5")

print("Saved model to disk")

To compile this with TVM I have written following code

data = np.array([6, 148, 72, 35, 0, 33.6, 0.627, 50]) 
print("input_1", data.shape) # (8,) (1,8)
data = data.reshape(1,8)
reconstructed_model = keras.models.load_model("my_model2.h5")
shape_dict = {"X": data.shape}
mod, params = relay.frontend.from_keras(reconstructed_model, shape_dict)

Which result s in following error

File "/home/kpit/tvm/tvm/src/relay/transforms/type_infer.cc", line 611

TVMError: Check failed: checked_type.as() == nullptr: Cannot resolve type of Var(dense_1_input) at (nullptr)

Request help here, as I am stuck.

here you need to feed the input of the graph.

i.e. shape_dict = {“X”: data.shape} , x should be replaced with dense_1_input

2 Likes

I think it is normally due to input type or input name you missed or entered incorrectly

Thanks guys for reply, I have corrected the input size and input name. Now able to compile model correctly.