-1

Given groups=1, weight of size [48, 3, 3, 3], expected input [5, 128, 129, 4] to have 3 channels, but got 128 channels instead.

This is my code:

    **model_ft.eval()
    for image in test_loader:
        image = image.cuda()
        output = model_ft(image)
        output = output.cpu().detach().numpy()
        for i, (e, n) in enumerate(list(zip(output, name))):
            sub.loc[sub['id_code'] == n.split('/')[-1].split('.')[0], 'diagnosis'] = le.inverse_transform([np.argmax(e)])
            
    sub.to_csv('submission.csv', index=False)**
    
    print(X_test.shape)
    (3071, 128, 128, 3)
    from torch.utils.data import DataLoader
    test_loader = DataLoader(X_test, batch_size=5, shuffle=True)
    print(train_data)

i don't know how to fix this problem to predict my compete

Algebra8
  • 1,115
  • 1
  • 10
  • 23

1 Answers1

0

I'm assuming by

print(X_test.shape)
(3071, 128, 128, 3)

you mean that the test data has 3071 samples with 128x128 pixels and 3 color channels each. Also I'm assuming that the model you are using doesn't transpose the inputs, so the convolution layers expect the default layout which is shape (N, C, H, W) but you provide your data as (N, H, W, C).

Solution: Try image.transpose_(1, 3) or image = image.cuda().transpose(1, 3) before handing it to the model.

Marius
  • 378
  • 1
  • 11