Собирал автокодировщик на pytorch. При подаче входных данных, получаю ошибку (conv2d(): argument 'input' (position 1) must be Tensor, not tuple). Архитектура сети:
Класс и экземпляр сети:
class Autocoder_network(nn.Module):
def __init__(self):
super(Autocoder_network, self).__init__()
self.block1 = nn.Sequential(
nn.Conv2d(1, 32, kernel_size=3),
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Conv2d(32, 32, kernel_size=3),
nn.ReLU(),
nn.BatchNorm2d(32),
nn.MaxPool2d(2)
)
self.block2 = nn.Sequential(
nn.Conv2d(32, 64, kernel_size=3),
nn.ReLU(),
nn.BatchNorm2d(64),
nn.Conv2d(64, 64, kernel_size=3),
nn.ReLU(),
nn.BatchNorm2d(64),
nn.MaxPool2d(2)
)
self.block_transpose1 = nn.Sequential(
nn.ConvTranspose2d(64, 64, kernel_size=2, stride=2),
nn.ReLU(),
nn.BatchNorm2d(64)
)
self.block3 = nn.Sequential(
nn.Conv2d(64, 64, kernel_size=3),
nn.ReLU(),
nn.BatchNorm2d(64),
nn.Conv2d(64, 64, kernel_size=3),
nn.ReLU(),
nn.BatchNorm2d(64)
)
self.block_transpose2 = nn.Sequential(
nn.ConvTranspose2d(64, 32, kernel_size=2, stride=2),
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Conv2d(32, 32, kernel_size=3),
nn.ReLU(),
nn.BatchNorm2d(32),
nn.Conv2d(32, 32, kernel_size=3),
nn.ReLU(),
nn.BatchNorm2d(32)
)
self.output = nn.Conv2d(32, 1, kernel_size=3)
def forward(self, k):
x = self.block1(k),
x = self.block2(x),
x = self.block_transpose1(x),
x = self.block3(x),
x = self.block_transpose2(x),
out = self.output(x)
return out
autocoder = Autocoder_network()
Вопрос в том, как это фиксить? На вход подается ДатаЛоадер, который работал в аналогичных ситуациях:
for epoch in range(epochs):
for i, (images, _) in enumerate(train_loader):
optimizer.zero_grad()
predict = autocoder(images) #conv2d(): argument 'input' (position 1) must be Tensor, not tuple
loss = error(predict, images)
loss.backward()
optimizer.step()
print(loss)