def convert(src, dst):
    """Convert keys in torchvision pretrained MobileNetV2 models to mmpretrain
    style."""

    # load pytorch model
    blobs = torch.load(src, map_location='cpu')

    # convert to pytorch style
    state_dict = OrderedDict()
    converted_names = set()

    for key, weight in blobs.items():
        if 'features.0' in key:
            convert_conv1(key, weight, state_dict, converted_names)
        elif 'classifier' in key:
            convert_head(key, weight, state_dict, converted_names)
        elif 'features.18' in key:
            convert_conv5(key, weight, state_dict, converted_names)
        else:
            convert_block(key, weight, state_dict, converted_names)

    # check if all layers are converted
    for key in blobs:
        if key not in converted_names:
            print(f'not converted: {key}')
    # save checkpoint
    checkpoint = dict()
    checkpoint['state_dict'] = state_dict
    torch.save(checkpoint, dst)
Convert keys in torchvision pretrained MobileNetV2 models to mmpretrain
    style.
tools/model_converters/mobilenetv2_to_mmpretrain.py