나는 신경 네트워크는 출력 output
. 고 싶 변환 output
하기 전에 손실 및 backpropogation 일어난다.
여기에는 나의 일반적인 코드:
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()
나는 변환 기능을 나를 통해서 출력:
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
내 문제는 나에 오류가 발생한 다음 마지막 줄:
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
어떤 방법이 있나요? 나가도를 사용하여"성화와 함께.no_grad():"(주석)하지만,이 결과에서 아주 가난한 교육 및 내가 믿는 것을 기울이지 않 backpropogate 제대로 후 변환 기능입니다.
감사합니다!