So I was writing my first ever autoencoder, here is the code (it can be a little bit goofy, but I believe I written all of it right):
class Autoencoder(nn.Module): def __init__(self): super(Autoencoder, self).__init__() self.flatten = nn.Flatten() self.enc_conv0 = nn.Sequential( nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3, padding=(1, 1)), nn.ReLU(), nn.BatchNorm2d(64), nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, padding=(1, 1)), nn.ReLU(), nn.BatchNorm2d(128) ) self.enc_conv1 = nn.Sequential( nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, padding=(1, 1)), nn.ReLU(), nn.BatchNorm2d(256), nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, padding=(1, 1)), nn.ReLU(), nn.BatchNorm2d(512) ) self.enc_fc = nn.Sequential( nn.Linear(in_features=512*64*64, out_features=4096), nn.ReLU(), nn.BatchNorm1d(4096), nn.Linear(in_features=4096, out_features=2048), nn.ReLU(), nn.BatchNorm1d(2048), nn.Linear(in_features=2048, out_features=dim_code) ) self.dec_fc = nn.Sequential( nn.Linear(in_features=dim_code, out_features=2048), nn.ReLU(), nn.BatchNorm1d(2048), nn.Linear(in_features=2048, out_features=4096), nn.ReLU(), nn.BatchNorm1d(4096), nn.Linear(in_features=4096, out_features=512*64*64), nn.ReLU(), nn.BatchNorm1d(512*64*64) ) self.dec_conv0 = nn.Sequential( nn.ConvTranspose2d(in_channels=512, out_channels=256, kernel_size=(3,3), padding=1), nn.ReLU(), nn.BatchNorm2d(256), nn.ConvTranspose2d(in_channels=256, out_channels=128, kernel_size=(3,3), padding=1), nn.ReLU(), nn.BatchNorm2d(128), ) self.dec_conv1 = nn.Sequential( nn.ConvTranspose2d(in_channels=128, out_channels=64, kernel_size=(3,3), padding=1), nn.ReLU(), nn.BatchNorm2d(64), nn.ConvTranspose2d(in_channels=64, out_channels=3, kernel_size=(3,3), padding=1) ) def forward(self, x): e0 = self.enc_conv0(x) e1 = self.enc_conv1(e0) latent_code = self.enc_fc(self.flatten(e1)) d0 = self.dec_fc(latent_code) d1 = self.dec_conv0(d0.view(-1, 512, 64, 64)) reconstruction = self.dec_conv1(d1) return reconstruction, latent_code And then I was preparing to train it with the next cell of code:
`device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') print(device) criterion = nn.BCELoss() print('crit') autoencoder = Autoencoder().to(device) print('deviced')` Cell prints: cuda 'crit'
And then just stalks infinitely, filling the RAM and CPU at its full (im doing everything on kaggle notebook). And I dont get why.
Tried to launch the same notebook in Google colab instead of Kaggle, but it just crashed with error about trying to allocate resources that are not accessable.
Also I thought the issue could had something to do with the first line after initiation of a class, so I replaced
def __init__(self): super().__init__() with
def __init__(self): super(Autoencoder, self).__init__() like I saw in some tutorials (honestly I don't know what this lines do, it just written in every other similar cases) But it also didnt worked
Источник: https://stackoverflow.com/questions/781 ... e-todevice