model.load_state_dict (torch.load (weights_path)) не удалось в train.py - PullRequest
0 голосов
/ 23 апреля 2020

Я тренирую эффективную модель в pytorch. Я хочу загрузить вес, который был сохранен в model.load_state_dict(torch.load(weights_path))
, но потеря и cc выглядят так, что модель не обучена. Но в модели eval.py кажется, что модель может успешно загружать веса

Вот мой код загрузки в train.py

    if opt.load_weights is not None:
    if opt.load_weights.endswith('.pth'):
        weights_path = opt.load_weights
    else:
        weights_path = get_last_weights(opt.saved_path)
    try:
        last_step = int(os.path.basename(weights_path).split('_')[-1].split('.')[0])
    except:
        last_step = 0

    try:
        model.load_state_dict(torch.load(weights_path), strict=False)
    except RuntimeError as e:
        print(f'[Warning] Ignoring {e}')
        print(
            '[Warning] Don\'t panic if you see this, this might be because you load a pretrained weights with different number of classes. The rest of the weights should be loaded already.')

    print(f'[Info] loaded weights: {os.path.basename(weights_path)}, resuming checkpoint from step: {last_step}')
else:
    last_step = 0
    print('[Info] initializing weights...')
    init_weights(model)

Вот мой код загрузки в eval.py

    model = EfficientDetBackbone(compound_coef=compound_coef, num_classes=len(obj_list),
                                 ratios=eval(params['anchors_ratios']), scales=eval(params['anchors_scales']))
    model.load_state_dict(torch.load(weights_path, map_location=torch.device('cpu')))
    model.requires_grad_(False)
    model.eval()

Моя среда:

Факел: 1.4.0 Факел видение: 0.5.0 Ubuntu: 16.0.4

Кто-нибудь может мне помочь? спасибо очень

...