You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by rahul1 via Apache TVM Discuss <no...@discuss.tvm.ai> on 2020/10/13 13:41:32 UTC

[Apache TVM Discuss] [Application] 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<IncompleteTypeNode>() == nullptr: Cannot resolve type of Var(dense_1_input) at (nullptr)

Request help here, as I am stuck.





---
[Visit Topic](https://discuss.tvm.apache.org/t/compile-keras-neural-network-models/8164/1) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.apache.org/email/unsubscribe/ba11fc65fc2e90fba265e88dc0902922d3b6ca6a05303c29319ccaa5c5e49e7b).