Attention-Augmented-Conv2d
Attention-Augmented-Conv2d copied to clipboard
Output 0 of ReshapeAliasBackward0 is a view and is being modified inplace
I can't run the AA-conv net,which occured RuntimeError: Output 0 of ReshapeAliasBackward0 is a view and is being modified inplace. This view is the output of a function that returns multiple views. Such functions do not allow the output views to be modified inplace. You should replace the inplace operation by an out-of-place one.
the net structure is class AACNN(nn.Module): def init(self): super(AACNN, self).init() self.conv1_model = nn.Sequential(OrderedDict([ ('conv1', nn.Conv2d(1, 3, 3, padding=1)), ('relu1', nn.ReLU()), ]))
self.augmented_conv1 = AugmentedConv(in_channels=3, out_channels=20, kernel_size=3, dk=40, dv=4, Nh=4, relative=True,
stride=1, shape=64).to(device)
self.conv2_model = nn.Sequential(OrderedDict([
('conv2', nn.Conv2d(32, 16, 5, padding=2)),
('pool2', nn.MaxPool2d(2)),
('conv3', nn.Conv2d(16, 8, 5)),#out:8*12*12
('relu', nn.ReLU()),
]))
self.linear = nn.Sequential(OrderedDict([
('linear1', nn.Linear(8*12*12, 512)),
('linear2', nn.Linear(512, 128)),
('linear3', nn.Linear(128, 1)),
]))
def forward(self, x):
x = self.conv1_model(x)
print(x.shape)
x = self.augmented_conv1(x)
x = self.conv2_model(x)
x = self.linear(x)
return x
the print torch.Size([10, 3, 64, 64])
Thanks for any help
Maybe you can change q *= dkh ** -0.5 to q = q*(dkh ** -0.5) in line 80 of the file attention_augmented_conv.py .