import numpy as np
import json
from tensorflow import keras
import sys, os
from mechanoChemML.src.idnn import IDNN
from mechanoChemML.src.transform_layer import Transform
[docs]idnn = keras.models.load_model(f'idnn_{rnd}',
custom_objects={'Transform': Transform(transforms)})
for layer in idnn.layers[1:]:
[docs] w = layer.get_weights()
if len(w)==2:
weights.append(w[0])
biases.append(w[1])
elif len(w)==1:
weights.append(w[0])
[docs]last = max(len(weights) - 1,len(biases) - 1)
for i,weight in enumerate(weights):
if i == last:
weight *= 0.01
np.savetxt('weights_'+str(i)+'.txt',weight,header=str(weight.shape[0])+' '+str(weight.shape[1]))
for i,bias in enumerate(biases):
if i == last:
bias *= 0.01
np.savetxt('bias_'+str(i)+'.txt',bias,header=str(bias.shape[0]))