keras-team / keras

Deep Learning for humans
http://keras.io/
Apache License 2.0
61.73k stars 19.44k forks source link

tf.keras compatibility: Convert Node Classification with GNN to Keras Core #18432

Open prateekgargX opened 1 year ago

prateekgargX commented 1 year ago

In my attempt to port Node Classification with Graph Neural Networks to keras_core, I hit an issue when trying to pass a list of indices to the gnn_model line 613: image

produces the error: image

It seems that instead of considering [1,10,100] as argument, it just considers 1 as argument.

diff.txt

Colab-Notebook

prateekgargX commented 1 year ago

I also tried to cast input into keras_core.KerasTensor object but that throws the error: image

AakashKumarNain commented 1 year ago

Two things:

  1. Pass a tensor/ndarray as an input argument to gnn_model(...) and not a list
  2. The second error suggests that your has some inbuilt state. For each layer in the final model, can you check if the layers that you are using in call(...) has been built? You can check it using the built attribute
prateekgargX commented 1 year ago

Tried ndarray as well image Interestingly, input_node_indices is being cast into tf.Tensor(shape=(3,), dtype=float32) here with the error thrown for a layer inside Model.

I'll try to make it work with your suggestions, but it should be noted that I started with code that had no issues using Keras. So something is broken with keras_core

And no graph_conv1 is not built. image these print statements are inside call(...) for gnn_model(...)

AakashKumarNain commented 1 year ago

Interestingly, input_node_indices is being cast into tf.Tensor(shape=(3,), dtype=float32)

That is fine. Depending upon the backend, the inputs would be converted to the corresponding tensors.

And no graph_conv1 is not built.

Can you build it and try again?

prateekgargX commented 1 year ago

Not sure how to do that