मैं एक तंत्रिका नेटवर्क है जो outputs 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 ठीक से परिवर्तन के बाद समारोह ।
धन्यवाद!