You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromfunctoolsimportpartialimportmmcvimporttorchfrommmcv.onnximportregister_extra_symbolicsfrommmcv.runnerimportload_checkpointfrommmcls.modelsimportbuild_classifiertorch.manual_seed(3)
if__name__=='__main__':
input_shape= (1, 3, 480, 224)
cfg=mmcv.Config.fromfile('/image_classification/train_log/swin-large_16xb64_in1k.py')
cfg.model.pretrained=None# build the model and load checkpointclassifier=build_classifier(cfg.model)
model=load_checkpoint(classifier, '/image_classification/train_log/epoch_160.pth', map_location='cpu')
model.cpu().eval()
ifhasattr(model.head, 'num_classes'):
num_classes=model.head.num_classes# Some backbones use `num_classes=-1` to disable top classifier.elifgetattr(model.backbone, 'num_classes', -1) >0:
num_classes=model.backbone.num_classeselse:
raiseAttributeError('Cannot find "num_classes" in both head and backbone, please check the config file.')
model.forward=partial(model.forward, img_metas={}, return_loss=False)
register_extra_symbolics(13)
torch.save(model, 'model.pth')
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
mmcls 0.23.2
mmcv 1.7.0
mmcv-full 1.7.0
onnx 1.12.0
onnxruntime 1.9.0
torch 1.10.2
swin-large_16xb64_in1k.py
Please help to find out where the problem is, thank you!!
Beta Was this translation helpful? Give feedback.
All reactions