1

recently i am trying the PINN, i have read some codes, in this code, he didn't define the "model", the losses are directly applied on the weights and biases, so i want to ask if anybody know how to save weights and biases in this situation? Thanks! Here is some code:

def neural_net(X, weights, biases, A):
    num_layers = len(weights) + 1    
    H = X 
    for l in range(0,num_layers-2):
        W = weights[l]
        b = biases[l]
        H = tf.keras.activations.swish(20*A[l]*tf.add(tf.matmul(H, W), b)) 
    W = weights[-1]
    b = biases[-1]
    Y = tf.add(tf.matmul(H, W), b)
    return Y

 grads1 = tape.gradient(loss,   W   +  b    +  A, unconnected_gradients=tf.UnconnectedGradients.ZERO)
    
 opt.apply_gradients(zip(grads1, W   +  b    +  A))

 optimizer = tf.optimizers.Adam(learning_rate=0.0001)

we can see there is no define of model, so i dont know how to save the weigths and biases.

I want to save the weights and biases and then re use of them.

A-T
  • 342
  • 2
  • 14
P. Zh.
  • 11
  • 2

1 Answers1

1

You could just save them by writing to a .csv file? The weights and biases that you're passing to your function seem like numpy arrays or tensors which can be written to a CSV file.

There are already enough examples of how to write python arrays to csv files. Here's a link to an associated stack overflow question - link

A-T
  • 342
  • 2
  • 14