Skip to content

--freeze option doen't work as expected #6038

Closed

Description

@bilzard

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

Training

Bug

The change made in #6019 currently not working when I specified single integer.
When specified single integer value, the freeze value is created as a list of single integer: e.g. [10]. Therefore, the train.py code only freezes the 11th layer, remaining other former layers 0, .., 9 are ignored.

The expected behavior is:

python train.py --freeze 10 # freeze up to 10.

Environment

No response

Minimal Reproducible Example

python train.py --freeze 10

the output:

freezing model.10.conv.weight
freezing model.10.bn.weight
freezing model.10.bn.bias

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!

Activity

  1. github-actions commented on Dec 20, 2021

    @github-actions
    Contributor

    👋 Hello @bilzard, 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. changed the title [-]--freeze option don't work as expected[/-] [+]--freeze option when specified single integer don't work as expected[/+] on Dec 20, 2021
  3. bilzard commented on Dec 20, 2021

    @bilzard
    ContributorAuthor

    I read the initial issue.
    #6001 (comment)

    I think meeting both specifications 1, 2 is difficult:

    specification. 1: python train.py --freeze 10  # freeze up to 10
    specification. 2: python train.py --freeze 5 6 7 8 9 10  # freeze layers 5-10
    

    Because when specifying single integer, the program can't distinguish the two cases: 1) freeze only layer 10 and 2) freeze layer from 0 to 9.

    I think there are two solutions:

    a) give up specification 1 or 2
    b) separate option for specification 1 to 2. e.g: --freeze-up-to 10 and --freeze 0 1 2

  4. bilzard commented on Dec 20, 2021

    @bilzard
    ContributorAuthor

    Personally, I prefer keeping specification 1 and give up 2 because specification 1 is simple.
    But I don't know if there are the cases when freezing only middle layers or latter layers.
    Since specification 1 is just a syntax sugar, keeping spec 2 might be better.

  5. changed the title [-]--freeze option when specified single integer don't work as expected[/-] [+]--freeze option when specified single integer doen't work as expected[/+] on Dec 20, 2021
  6. changed the title [-]--freeze option when specified single integer doen't work as expected[/-] [+]--freeze option doen't work as expected[/+] on Dec 20, 2021
  7. glenn-jocher commented on Dec 20, 2021

    @glenn-jocher
    Member

    @bilzard thanks for the bug report! I'm able to reproduce. Will push a fix.

  8. added a commit that references this issue on Dec 20, 2021
  9. linked a pull request that will close this issue`--freeze` fix #6044on Dec 20, 2021
  10. added a commit that references this issue on Dec 20, 2021
  11. glenn-jocher commented on Dec 20, 2021

    @glenn-jocher
    Member

    @bilzard good news 😃! Your original issue may now be fixed ✅ in PR #6044. 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 🚀!

  12. bilzard commented on Dec 20, 2021

    @bilzard
    ContributorAuthor

    @glenn-jocher Thank you for the quick reply.
    I checked the PR. It works most of the cases, but I think this solution is insufficient.

    How do the user specify to freeze only one layer? See, layer 0 only?

  13. glenn-jocher commented on Dec 21, 2021

    @glenn-jocher
    Member

    @bilzard good question! Layer 0 freeze is not supported currently. I'll take a look and see if I can add support for this use case.

  14. added a commit that references this issue on Aug 26, 2022
  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

    TODOHigh priority itemsbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions