-
Notifications
You must be signed in to change notification settings - Fork 158
copy layers error? #286
Comments
@tony-dd check if all configurations are the same for the two models. For example in the Set2Set layer the number of steps T maybe different, which does not change the number of trainable weights, but will give different results. |
check from xxx.hdf5.json or somewhere else? thanks |
No when you have the model you can get the model config. Or you can loop all layers in model and use layer’s get_config method to get the layer config parameters |
I have followed your suggestion. Indeed, the configurations of the two models are different. Could you please tell me how can I init the model that have the same configurations with the xxx.hdf5? |
You can check the |
Thank you very much for your suggestions. Could you please tell me why I use the same method to init ‘G.hdf5’, but there is a 'ValueError'. Example code is below: from megnet.models import MEGNetModel #load data gc = CrystalGraph(bond_converter=GaussianDistance( model_replace_layers = MEGNetModel(100, 2, nvocal=95, graph_converter=gc) model_free_energy = MEGNetModel.from_file('G.hdf5') #replace layers Err: File "D:/megnet/test_model.py", line 28, in |
The QM9 model does not use 95 elements. Also, your code assumes that the layers of the two models are placed in the same order, which is not necessarily true. Please just use https://github.com/materialsvirtuallab/megnet/blob/master/notebooks/qm9_pretrained.ipynb for pretrained qm9 models. |
Hello! I found that the 'formation_energy.hdf5' model downloaded from github gave different prediction results with a copied layers model. Very strange... any idea to fix it?
Example code is below:
from megnet.models import MEGNetModel
from megnet.data.graph import GaussianDistance
from megnet.data.crystal import CrystalGraph
import numpy as np
from monty.serialization import loadfn
#load data
data = loadfn('bulk_moduli.json')
structures = data['structures']
gc = CrystalGraph(bond_converter=GaussianDistance(
np.linspace(0, 5, 100), 0.5), cutoff=4)
model_replace_layers = MEGNetModel(100, 2, nblocks=3, nvocal=95, embedding_dim=16, graph_converter=gc)
model_formation_energy = MEGNetModel.from_file('formation_energy.hdf5')
#replace layers
for index, layer in enumerate(model_replace_layers.layers):
weights_trained_model = model_formation_energy.layers[index].get_weights()
model_replace_layers.layers[index].set_weights(weights_trained_model)
predicte_1 = model_formation_energy.predict_structure(structures[0])
print(predicte_1) # [-0.27339065]
predicte_2 = model_replace_layers.predict_structure(structures[0])
print(predicte_2) # [0.17409758]
The text was updated successfully, but these errors were encountered: