Git Product home page Git Product logo

Comments (3)

Cxz-dev avatar Cxz-dev commented on May 26, 2024

I dowload the pretrained model from https://github.com/Westlake-AI/MogaNet/releases/download/moganet-in1k-weights/moganet_base_sz224_8xbs128_ep300.pth.tar

from moganet.

Lupin1998 avatar Lupin1998 commented on May 26, 2024

Hi, @Cxz-dev, thanks for using MogaNet. Could you please describe your usage in detail? The RuntimeError you met is caused by no classification head in the built model. I provide two situations of loading pre-trained models and hope these will be helpful to you.

  • In image classification tasks, you can build MogaNet-Base and load pre-training without any errors:

    import models
    from timm.models import create_model
    cnn = create_model('moganet_base', pretrained=True)  # build by timm
    cnn = models.moganet.moganet_base(pretrained=True)  # or call the model directly
  • For downstream tasks, you will get RuntimeError: Error(s) in loading state_dict for MogaNet if you build the model like this. Since fork_feat=True will remove the classification head in MogaNet and the pre-trained models in moganet-in1k-weights contain parameters of the head, it will raise the error using model.load_state_dict(checkpoint["state_dict"]), where strict defaults to True.

    import models
    from timm.models import create_model
    cnn = create_model('moganet_base', pretrained=True, fork_feat=True)  # fork_feat=True for dense predictions

    Therefore, I suggest you load the model as follows or directly perform dense prediction tasks by our implementations in MogaNet/detection, MogaNet/segmentation, and MogaNet/pose_estimation.

    import torch
    import models
    from timm.models import create_model
    cnn = create_model('moganet_base', fork_feat=True)
    checkpoint = torch.hub.load_state_dict_from_url(url='https://github.com/Westlake-AI/MogaNet/releases/download/moganet-in1k-weights/moganet_base_sz224_8xbs128_ep300.pth.tar', map_location="cpu", check_hash=True)
    cnn.load_state_dict(checkpoint["state_dict"], strict=False)  # allow unexpected keys

from moganet.

Lupin1998 avatar Lupin1998 commented on May 26, 2024

Thanks for your question. I will close this issue if you have no more questions. Please feel free to open a new issue when new problems occur.

from moganet.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.