ZHOUXINWEN / 2019Baidu-XJTU_URFC

2019Baidu&XJTU_URFC Preliminary Round Code
32 stars 9 forks source link

BDXJTU2019_SGD_80.pth is not available #3

Open sunlanchang opened 5 years ago

sunlanchang commented 5 years ago

I try to change GeResult.py to replace weight that you provided from BaiduNetdisk, like this net.load_state_dict(torch.load('./model/BDXJTU2019_SGD_80.pth'))

when I run this python GeResult.py , I got this error:

load pretrained model from model/se_resnext50_32x4d-a260b3a4.pth
Traceback (most recent call last):
  File "GeResult.py", line 60, in <module>
    GeResult()
  File "GeResult.py", line 36, in GeResult
    net.load_state_dict(torch.load('./model/BDXJTU2019_SGD_80.pth'))
  File "/home/sun/.local/lib/python3.6/site-packages/torch/serialization.py", line 387, in load
    return _load(f, map_location, pickle_module, **pickle_load_args)
  File "/home/sun/.local/lib/python3.6/site-packages/torch/serialization.py", line 581, in _load
    deserialized_objects[key]._set_from_file(f, offset, f_should_read_directly)
RuntimeError: storage has wrong size: expected 7595430114468248624 got 1024

After google this issue, I found it may be caused by damage of the weight file, I hope you re-upload the weight file(BDXJTU2019_SGD_80.pth), I really want to get your help, thanks.

sunlanchang commented 5 years ago

GeResult.py code is here.

import torch
import torch.nn as nn
import torch.utils.data as data
import torch.backends.cudnn as cudnn

from Dataloader.MultiModal_BDXJTU2019 import BDXJTU2019_test
from basenet.ResNeXt101_64x4d import ResNeXt101_64x4d
from basenet.senet import se_resnet50, se_resnext101_32x4d
from basenet.octave_resnet import octave_resnet50
from basenet.nasnet import nasnetalarge
from basenet.multimodal import MultiModalNet

import os

CLASSES = ['001', '002', '003', '004', '005', '006', '007', '008', '009']

def GeResult():
    # Priors
    torch.set_default_tensor_type('torch.cuda.FloatTensor')
    torch.cuda.set_device(0)

    # Dataset
    Dataset = BDXJTU2019_test(root='data')
    Dataloader = data.DataLoader(Dataset, 1,
                                 num_workers=1,
                                 shuffle=False, pin_memory=True)

    # Network
    cudnn.benchmark = True
    #Network = pnasnet5large(6, None)
    #Network = ResNeXt101_64x4d(6)
    net = MultiModalNet('se_resnext50_32x4d', 'DPN26', 0.5)
    # net.load_state_dict(torch.load('./model/BDXJTU2019_SGD_20.pth'))
    net.load_state_dict(torch.load('./model/BDXJTU2019_SGD_80.pth'))

    net.eval()

    filename = 'MM_epoch80_R_TTA.txt'

    f = open(filename, 'w')

    for (Input_O, Input_H, visit_tensor, anos) in Dataloader:
        ConfTensor_O = net.forward(Input_O.cuda(), visit_tensor.cuda())
        ConfTensor_H = net.forward(Input_H.cuda(), visit_tensor.cuda())
        #ConfTensor_V = net.forward(Input_V.cuda())
        # +torch.nn.functional.normalize(ConfTensor_V)
        preds = torch.nn.functional.normalize(
            ConfTensor_O) + torch.nn.functional.normalize(ConfTensor_H)
        _, pred = preds.data.topk(1, 1, True, True)
        #f.write(anos[0] + ',' + CLASSES[4] + '\r\n')
        print(anos[0][:-4] + '\t' + CLASSES[pred[0][0]] + '\n')
        f.writelines(anos[0][:-4] + '\t' + CLASSES[pred[0][0]] + '\n')
    f.close()

if __name__ == '__main__':
    GeResult()