Hi, dear community.
I’m fairly new in the field of M.L. and I’m trying to build a 1D autoencoder.
My data consist of 100 rows with 21 columns. In this scenario, each row is an individual sample.
My goal is to create a 1D autoencoder able to map these lines into a 19 collums representation, and after this back to 21 columns, but I’m getting the following channel mismatch error:
Code by: Caue Evangelista
Fully based on the code by Sebastian Raschka
Link: https://github.com/rasbt/stat453-deep-learning-ss21/tree/main/L16
Torch version: 2.0.1
Device: CPU
Dataset size: 100
Train size: 80
Teste size: 20
Training Set:
Tracksjets batch dimensions: torch.Size([32, 21])
Label dimensions: torch.Size([32])
Testing Set:
Tracksjets batch dimensions: torch.Size([20, 21])
Label dimensions: torch.Size([20])
[W NNPACK.cpp:64] Could not initialize NNPACK! Reason: Unsupported hardware.
Epoch: 001/020 | Batch 0000/0003 | Loss: 14.0723
Traceback (most recent call last):
File "/home/ecaue/JetTrack/AutoEncoder/AutoencoderJetTrack/autoencoder.py", line 110, in <module>
log_dict = train_autoencoder_v1(num_epochs=NUM_EPOCHS, model=model,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ecaue/JetTrack/AutoEncoder/AutoencoderJetTrack/helpers/helper_train.py", line 36, in train_autoencoder_v1
logits = model(features)
^^^^^^^^^^^^^^^
File "/home/ecaue/.conda/envs/AnalysisEnv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ecaue/JetTrack/AutoEncoder/AutoencoderJetTrack/autoencoder.py", line 98, in forward
x = self.encoder(x)
^^^^^^^^^^^^^^^
File "/home/ecaue/.conda/envs/AnalysisEnv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ecaue/.conda/envs/AnalysisEnv/lib/python3.11/site-packages/torch/nn/modules/container.py", line 217, in forward
input = module(input)
^^^^^^^^^^^^^
File "/home/ecaue/.conda/envs/AnalysisEnv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ecaue/.conda/envs/AnalysisEnv/lib/python3.11/site-packages/torch/nn/modules/conv.py", line 313, in forward
return self._conv_forward(input, self.weight, self.bias)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ecaue/.conda/envs/AnalysisEnv/lib/python3.11/site-packages/torch/nn/modules/conv.py", line 309, in _conv_forward
return F.conv1d(input, weight, bias, self.stride,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: Given groups=1, weight of size [32, 32, 2], expected input[1, 16, 21] to have 32 channels, but got 16 channels instead
I’m very confused because I have a Google Colab notebook for quick testings and there the code runs ok, but every time I try to run my official scrip, I got these messages.
This is the code on my “official script”:
# Hyperparameters
RANDOM_SEED = 123
LEARNING_RATE = 0.0005
BATCH_SIZE = 32
NUM_EPOCHS = 20
NUM_CLASSES = 3
#Kernel and Stride
kernel=2
stride=1
set_deterministic
set_all_seeds(RANDOM_SEED)
##########################
### DATASET
##########################
ds = JetTrackDataset()
train_loader, test_loader = get_dataloaders_jetrack(ds,batch_size=32,num_workers=2)
# Checking the dataset
print('Training Set:')
for tracksjets, labels in train_loader:
print('Tracksjets batch dimensions:', tracksjets.size())
print('Label dimensions:', labels.size())
break
print(" ")
# Checking the dataset
print('Testing Set:')
for tracksjets, labels in test_loader:
print('Tracksjets batch dimensions:', tracksjets.size())
print('Label dimensions:', labels.size())
break
print(" ")
##########################
### MODEL
##########################
class AutoEncoder(nn.Module):
def __init__(self):
super().__init__()
self.encoder = nn.Sequential(
nn.Conv1d(BATCH_SIZE, BATCH_SIZE, kernel_size=kernel, stride=stride),
nn.LeakyReLU(0.01)
)
self.decoder = nn.Sequential(
nn.ConvTranspose1d(BATCH_SIZE, BATCH_SIZE, kernel_size=kernel, stride=stride),
nn.LeakyReLU(0.01),
)
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x
and the code on my colab notebook:
#Number of samples
batch_size = 32
#Number of collums in each sample
collumns = 21
kernel = 2
stride = 1
encoder = nn.Sequential(
nn.Conv1d(batch_size, batch_size, kernel_size=kernel, stride=stride),
nn.LeakyReLU(0.01),
nn.Conv1d(batch_size, batch_size, kernel_size=kernel, stride=stride)
)
decoder = nn.Sequential(
nn.ConvTranspose1d(batch_size, batch_size, kernel_size=kernel, stride=stride),
nn.LeakyReLU(0.01),
nn.ConvTranspose1d(batch_size, batch_size, kernel_size=kernel, stride=stride)
)
input = torch.randn(batch_size, I)
print("Input:", input.size())
code = encoder(input)
print("Code:", code.size())
output = decoder(code)
print("Output:", output.size())
which produce:
Input: torch.Size([32, 21])
Code: torch.Size([32, 19])
Output: torch.Size([32, 21])
I’ve read quite a bit of other posts about this but still, I’m very confused about all of the indices(in_channels, out_channels, batch_size, what is the right order, how many channels I need to do what I want, etc) and I apologize in advance if my question it’s not appropriated. I really appreciate any insight, help, or recommendation.