I am working in an musical notes classificator.
I have a simple multilayer perceptron write in Pytorch. My musical notes are isolated. I am just trying to recognize one note each time.
My perceptron has an input of shape 252, and an output of 88.
In the target, if I tried to recognize the note 2, I have a tensor like:
[0,0,1,0 …,0,0,0], with 88 elements.
The train_loader returns like input, [batch_size, 252] and the target is [batch_size, 88].
The dataset is normalized, but the accuracy is really bad. (Like 9%).
I had checked all and I tryed with differents hyperparameters but the network doesn’t give me good results.
My train code is:
def train(model, train_loader, optimizer, criterion):
model.train()
for idx_batch, (input,target) in enumerate(train_loader):
    optimizer.zero_grad()
    input = input.cuda()
    target = target.cuda()
    outputs = model(input) 
    loss = criterion(outputs, target)
    loss.backward()   
    optimizer.step()
    train_loss += loss.item()
return train_loss

Each time I train, I am doing a validation test:
def val(model, val_loader, optimizer, criterion):
model.eval()
val_loss = 0
with torch.no_grad():
    for idx_batch, (input, target) in enumerate(val_loader):
         input = input.cuda()
         target = target.cuda()
        outputs = model(input)
        loss = criterion(outputs, target)
        val_loss += loss.item()
return val_loss

This is the code where I did the train and validation in epochs, and after, I do the test section.
    for epoch in range(1, N_EPOCHS+1):
    print("------------EPOCHS ",epoch,"------------")
    train_loss = 0
    val_loss = 0
    train_loss = train(mlp, train_loader, optimizer, criterion)
    val_loss = val(mlp, val_loader, optimizer, criterion)
    
    #Mean of losses
    train_loss = train_loss/len(train_loader.dataset)
    val_loss = val_loss/len(val_loader.dataset)
    
    #Stats training and validation.
    print('Epoch: {} \tTraining loss: {:.6f} \tValidation loss:{:.6f}'.format(epoch, train_loss, val_loss))


mlp.eval()
for data, target in test_loader:

    data = data.to('cuda')
    target = target.to('cuda')
    outputs = mlp(data)
    loss = criterion(outputs, target)
    test_loss += loss.item() 
    pred = torch.max(outputs, 1)[1]
    t = torch.max(target, 1)[1]
    correct += pred.eq(t).sum()
    print("Correct: {}/len(test_loader.dataset) ")


I’m new to Pytorch and maybe I’m not doing something right.
Thank you for your help.