Commit 937e3d3c authored by Eva Lina Fesefeldt's avatar Eva Lina Fesefeldt
Browse files

Trainingsdaten aus hessianlearn übernommen

parent f2760cf0

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.
import tensorflow as tf
import numpy as np
def gradient(model, x_train, y_train, loss_fn):
with tf.GradientTape() as tape:
# make a prediction using the model and then calculate the
# loss
pred = model(x_train)
loss = loss_fn(y_train, pred)
# calculate the gradients using our tape and then update the
# model weights
grads = tape.gradient(loss, model.trainable_variables)
return grads
def reelles_skalarprodukt_trainable_shape(v_1, v_2):
......
......@@ -244,24 +244,19 @@ print("Initialer Loss: ", loss_fn(model(x_train), y_train))
gamma = np.array([0.1]).astype('float32')
for epoch in range(number_of_epochs):
x = model.get_weights()
# Gradienten ausrechnen
layer1 = model.layers[0]
layer2 = model.layers[1]
filename_trainset = "train_set/hessianlearn_trainset_newton" + str(epoch) +"_gamma_" + str(gamma[0]) + ".npy"
filename_trainlabels = "train_labels/hessianlearn_trainlabels_newton" + str(epoch) +"_gamma_" + str(gamma[0]) + ".npy"
x_train = np.load(filename_trainset)
y_train = np.load(filename_trainlabels)
watch = x_train
# Hesse-Matrix ausrechnen
with tf.GradientTape() as t2:
with tf.GradientTape() as t1:
watch = layer1(watch)
watch = layer2(watch)
loss = loss_fn(watch, y_train)
g = gradient(model, x_train, y_train, loss_fn)
g = t1.gradient(loss, [layer1.kernel, layer1.bias, layer2.kernel, layer2.bias])
loss = loss_fn(model(x_train), y_train)
b = []
for i in range(len(g)):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment