Skip to content

pretrained=False bug #5964

Closed
Closed

Description

@junyuancat1

Search before asking

Question

Hi there,
I simply want to train two-classification model, such as cat and dog, or 0 and 1.
so that I want to use branch classifer with out pretrained model.
I found that the classifier.py will load pretrained torchhub model anyway, is there any method to disable loading pretrained model and ?

Additional

No response

Activity

  1. github-actions commented on Dec 13, 2021

    @github-actions
    Contributor

    👋 Hello @junyuancat1, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

    If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

    If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

    For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

    Requirements

    Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

    $ git clone https://github.com/ultralytics/yolov5
    $ cd yolov5
    $ pip install -r requirements.txt

    Environments

    YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

    Status

    CI CPU testing

    If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

  2. hrnbot commented on Dec 13, 2021

    @hrnbot

    @junyuancat1 you can use --weights '' " to start learning from scratch.

  3. junyuancat1 commented on Dec 13, 2021

    @junyuancat1
    Author

    @hrnbot thanks for answer man~
    But in branch classifier, the pythonfile classifier.py is used to train a classifer instead of train.py, and there's not an option --weights in classifier.py ,the model is initing by torch hub.load.
    The train.py in this branch still contain the conception of anchor, but u known the classifer should not contain anchor like detector does, so I guess the train.py could not be used in this branch.

  4. junyuancat1 commented on Dec 13, 2021

    @junyuancat1
    Author

    using model yolov5s
    if i change the option pretrained = false ,there will be some urlerror occur[connection timed out].
    maybe i should check my connection first

  5. junyuancat1 commented on Dec 13, 2021

    @junyuancat1
    Author

    ok ,there's no more url error
    it shows that Exception: Cache may be out of date, try force_reload=True by loading model
    model = torch.hub.load('ultralytics/yolov5', opt.model, autoshape=False ,pretrained=False)

  6. glenn-jocher commented on Dec 13, 2021

    @glenn-jocher
    Member

    @junyuancat1 I'm able to reproduce a pretrained=False error. I will investigate today.

  7. added
    TODOHigh priority items
    bugSomething isn't working
    and removed
    questionFurther information is requested
    on Dec 13, 2021
  8. changed the title [-]How to use classifier without pretrained model[/-] [+]`pretrained=False` bug[/+] on Dec 13, 2021
  9. added a commit that references this issue on Dec 13, 2021
  10. linked a pull request that will close this issue`pretrained=False` fix #5966on Dec 13, 2021
  11. added a commit that references this issue on Dec 13, 2021
  12. glenn-jocher commented on Dec 13, 2021

    @glenn-jocher
    Member

    @junyuancat1 good news 😃! Your original issue may now be fixed ✅ in PR #5966. You can now pass pretrained=False when loading YOLOv5 PyTorch Hub models.

    To receive this update:

    • Git – git pull from within your yolov5/ directory or git clone https://github.com/ultralytics/yolov5 again
    • PyTorch Hub – Force-reload model = torch.hub.load('ultralytics/yolov5', 'yolov5s', force_reload=True)
    • Notebooks – View updated notebooks Open In Colab Open In Kaggle
    • Docker – sudo docker pull ultralytics/yolov5:latest to update your image Docker Pulls

    Thank you for spotting this issue and informing us of the problem. Please let us know if this update resolves the issue for you, and feel free to inform us of any other issues you discover or feature requests that come to mind. Happy trainings with YOLOv5 🚀!

  13. junyuancat1 commented on Dec 14, 2021

    @junyuancat1
    Author

    @glenn-jocher awsome!The classifier branch already contains model configs(model.yaml) . Since i need no pretrain,so I just temporarily using Model(cfg,ch,cn) to construct a model instead of loading from pytorch hub, It works for me.
    I'll try using pretrained=false to fix my issue. Thanks for such an precise and fast debug!

  14. glenn-jocher commented on Dec 14, 2021

    @glenn-jocher
    Member

    @junyuancat1 great! Yes you can also construct a model the way you show.

  15. added a commit that references this issue on May 24, 2023
  16. added a commit that references this issue on Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions