Skip to content

The classmethod HandSegModel.load_from_checkpoint cannot be called on an instance. Please call it on the class type and make sure the return value is used. #13

@asubhekar

Description

@asubhekar

Bug Description

I was trying to load the model using torch.hub.load and I was facing the issue where the .load_from_checkpoint class method cannot be called on an instance. I believe this fix should be

First suggested change in hubconf.py:
def hand_segmentor(pretrained=True, *args, **kwargs): """ Hand segmentor based on a DeepLabV3 model with a ResNet50 encoder. DeeplabV3: https://arxiv.org/abs/1706.05587 ResNet50: https://arxiv.org/abs/1512.03385 """ #model = HandSegModel(*args, **kwargs) if pretrained: #os.system('chmod +x ./scripts/download_model_checkpoint.sh') #os.system('./scripts/download_model_checkpoint.sh') _download_file_from_google_drive('1w7dztGAsPHD_fl_Kv_a8qHL4eW92rlQg', './checkpoint/checkpoint.ckpt') model = HandSegModel.load_from_checkpoint('./checkpoint/checkpoint.ckpt', map_location=torch.device('cpu'), *args, **kwargs) return model

Second suggested change in main.py
def get_model(args): """ build the model. """ model_args = { 'pretrained': args.model_pretrained, 'lr': args.lr, 'in_channels': args.in_channels, } #model = HandSegModel(**model_args) if len(args.model_checkpoint) > 0: model = HandSegModel.load_from_checkpoint(args.model_checkpoint, **model_args) print(f'Loaded checkpoint from {args.model_checkpoint}.') return model

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions