简体   繁体   English

我如何修复 pytorch 预测深度学习的问题

[英]how can i fix pytorch predict problem with deep learning

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.给定groups=1 ,大小为[48, 3, 3, 3]的权重,预期输入[5, 128, 129, 4]有 3 个通道,但有 128 个通道。

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我不知道如何解决这个问题来预测我的竞争

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.你的意思是测试数据有 3071 个样本,每个样本有 128x128 像素和 3 个颜色通道。 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).另外我假设您使用的 model 不会转置输入,因此卷积层期望默认布局为形状 (N, C, H, W) 但您提供的数据为 (N, H, W , C)。

Solution: Try image.transpose_(1, 3) or image = image.cuda().transpose(1, 3) before handing it to the model.解决方案:在将其交给 model 之前,尝试image.transpose_(1, 3)image = image.cuda().transpose(1, 3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM