Am si eu o rețea neuronală care emite output
. Vreau să se transforme output
înainte de pierderea și backpropogation se întâmple.
Aici este meu generale cod:
with torch.set_grad_enabled(training):
outputs = net(x_batch[:, 0], x_batch[:, 1]) # the prediction of the NN
# My issue is here:
outputs = transform_torch(outputs)
loss = my_loss(outputs, y_batch)
if training:
scheduler.step()
loss.backward()
optimizer.step()
Am o funcție de transformare care mi-am pus de ieșire prin:
def transform_torch(predictions):
torch_dimensions = predictions.size()
torch_grad = predictions.grad_fn
cuda0 = torch.device('cuda:0')
new_tensor = torch.ones(torch_dimensions, dtype=torch.float64, device=cuda0, requires_grad=True)
for i in range(int(len(predictions))):
a = predictions[i]
# with torch.no_grad(): # Note: no training happens if this line is kept in
new_tensor[i] = torch.flip(torch.cumsum(torch.flip(a, dims = [0]), dim = 0), dims = [0])
return new_tensor
Problema mea este ca am primit o eroare la ultima linie:
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
Orice sugestii? Deja am încercat, folosind "cu lanterna.no_grad():" (comentat), dar acest lucru duce la foarte slabă pregătire și cred că degradeuri nu backpropogate în mod corespunzător, după funcția de transformare.
Multumesc!!!