Hi,
I use an RNN model to process video frame by frame such that the forward looks something like this:
for frame in range(x.shape[1]):
out1, hidden = self.rnn_layer1(x[:,frame,:,:], hidden)
return out1
But that code returns error “one of the variables needed for gradient computation has been modified by an inplace operation”
After some trial and error i realized that the problem is that the sliced frame still holds gradient information of the whole video. I use an ugly hack that works just fine but i’m looking for a cleaner way to do this… here is the hack:
for frame in range(x.shape[1]):
out1, hidden = self.rnn_layer1(torch.cat([x[:, frame, :, :]], dim=1).unsqueeze_(1), hidden)
return out1
Essentially concatenating the tensor to nothing…