model2.set_weights(model_weights)
// Test loaded model
X = gen.featuresA = gen.Aadjactual = model2.predict([X, A])
expected = np.ones((G.number_of_nodes(), self.layer_sizes[-1])) * (
1.0 / G.number_of_nodes()
)
assert expected == pytest.approx(actual)
After Change
def test_gat_serialize(self):
G = example_graph_1(feature_size=self.F_in)
gen = FullBatchNodeGenerator(G, sparse=False)
gat = GAT(
layer_sizes=self.layer_sizes,
activations=self.activations,
attn_heads=self.attn_heads,
generator=gen,
bias=True,
normalize="l2",
)
x_in, x_out = gat.node_model()
model = keras.Model(inputs=x_in, outputs=x_out)
ng = gen.flow(G.nodes())
// Save model
model_json = model.to_json()
// Set all weights to one
model_weights = [np.ones_like(w) for w in model.get_weights()]
// Load model from json & set all weights
model2 = keras.models.model_from_json(
model_json, custom_objects={"GraphAttention": GraphAttention}
)
model2.set_weights(model_weights)
// Test deserialized model
actual = model2.predict_generator(ng)
expected = np.ones((G.number_of_nodes(), self.layer_sizes[-1])) * (
1.0 / G.number_of_nodes()
)
assert np.allclose(expected, actual[0])