-
-
Notifications
You must be signed in to change notification settings - Fork 16.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is the Focus layer equivalent to a simple Conv layer? #4825
Comments
👋 Hello @thomasbi1, 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. RequirementsPython>=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 EnvironmentsYOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):
StatusIf 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. |
@thomasbi1 thanks for raising this issue! That would be exciting if we can simplify this layer, we are always looking for improvements. I will try to reproduce your results later today. |
@thomasbi1 I was able to run your comparison is Colab. The allclose seems ok, but I got significantly different profile results when tested in Colab (with T4). I'm not sure what the cause could be, will try different hardware later. |
V100 results here, shows improvement forward and backward at batch size 16 and 1.
On balance it seems to help most setups, though the large K80 and T4 slowdowns are unfortunate as they are Colab mainstays. I'll take a look at the exportability next, though I don't imagine any issues there. |
@thomasbi1 export tests are good! Ok, this seems like a good candidate for our upcoming v6.0 release, which will arrive with a few other minor architecture updates in October. I will add this issue to the release notes and make sure credit is assigned to you for uncovering this. Thank you for your contributions and let us know if you spot any other items for improvement! TODO: apply to v6.0 release backbone updates: backbone:
# [from, number, module, args]
[[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 <--- update
[-1, 1, Conv, [128, 3, 2]], # 1-P2/4
[-1, 3, C3, [128]],
[-1, 1, Conv, [256, 3, 2]], # 3-P3/8
[-1, 9, C3, [256]],
[-1, 1, Conv, [512, 3, 2]], # 5-P4/16
[-1, 9, C3, [512]],
[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
[-1, 1, SPP, [1024, [5, 9, 13]]],
[-1, 3, C3, [1024, False]], # 9
] |
Removed TODO, update included in upcoming v6.0 release. |
@glenn-jocher Hi ,I use v6.0 to trt is report erro (Unnamed Layer* 0) [Convolution]: group count must divide input channel count [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2 <--- update |
@ptklx not sure I follow, |
@glenn-jocher Sorry, I read the wrong place |
@glenn-jocher Hi, I would like to ask why Conv can replace Focus? I used the above code and the result shows that Focus is significantly faster than Conv. |
@yao-zheng-yi As far as I can tell the Regarding speed, I seem to remember that the CUDA version plays an important role and that the |
@yao-zheng-yi yes from your profiling results Focus() is much faster on your machine. We did a pretty thorough analysis of various GPUs and found that Focus() is faster on many consumer cards and on T4 GPUs, while Conv() tends to be faster on enterprise cards and newer hardware. This change (and most every other change) is an exercise in compromise, and we implement changes if we feel the balance of the benefits outweigh the drawbacks for most users, so this is one place where some users will experience slowdowns while others may experience improvements, and hopefully this ratio will improve in the future for new hardware. One of the main benefits also is improved exportability and simpler architectures as well. |
@thomasbi1 @glenn-jocher Many thanks! |
@duanzhiihao great, yes thanks for the feedback! |
my memory only 2G ,55555555555 |
this is how i convert yolo focus to caffe. what a coincidence |
nice, thanks for your guys's job |
👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs. Access additional YOLOv5 🚀 resources:
Access additional Ultralytics ⚡ resources:
Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed! Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐! |
Hi
I had a look at the Focus layer and it seems to me like it is equivalent to a simple 2d-convolutional layer without the need for the space-to-depth operation. For example, a
Focus
layer with kernel size 3 can be expressed as aConv
layer with kernel size 6 and stride 2 . I wrote some code to verify this:And the output as follows:
I did have to slightly tweak the tolerance in
torch.allcose
for the assertion to succeed, but looking at the errors they seem to be purely numerical.So am I missing something or could the
Focus
layer simply be replaced by aConv
layer which would lead to a slight increase in speed?The text was updated successfully, but these errors were encountered: