ฉันมี neural เครือข่ายซึ่งแสดงผล 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 เหมาะสมหลังจากการเปลี่ยนแปรงฟังก์ชัน.
ขอบคุณ!