Closed djdll closed 4 months ago
Hi! Can you provide more explanation or code? Here is my minimal YAML file for LeYOLO Nano and classification.
nc: 1000 # number of classes
scales:
# [depth, width, max_channels]
n: [1.0, 1.0, 576]
# LeYOLO Nano backbone
backbone:
# [from, repeats, module, args]
- [-1, 1, mn_conv, [16, 3, 2, "SI"]]
- [-1, 1, mn_conv, [16, 1, 1, "SI"]]
- [-1, 1, MobileNetV3_BLOCK, [16, 3, 16, False, "SI", 2, False]]
- [-1, 1, MobileNetV3_BLOCK, [32, 3, 96, False, "SI", 2]]
- [-1, 1, MobileNetV3_BLOCK, [32, 3, 96, False, "SI", 1]]
- [-1, 1, MobileNetV3_BLOCK, [64, 5, 96, True, "SI", 2]]
- [-1, 1, MobileNetV3_BLOCK, [64, 5, 192, True, "SI", 1]]
- [-1, 1, MobileNetV3_BLOCK, [64, 5, 192, True, "SI", 1]]
- [-1, 1, MobileNetV3_BLOCK, [64, 5, 192, True, "SI", 1]]
- [-1, 1, MobileNetV3_BLOCK, [64, 5, 192, True, "SI", 1]]
- [-1, 1, MobileNetV3_BLOCK, [96, 5, 576, True, "SI", 2]]
- [-1, 1, MobileNetV3_BLOCK, [96, 5, 576, True, "SI", 1]]
- [-1, 1, MobileNetV3_BLOCK, [96, 5, 576, True, "SI", 1]]
- [-1, 1, MobileNetV3_BLOCK, [96, 5, 576, True, "SI", 1]]
#- [-1, 1, SPPF, [96, 5]] not necessary!
# LeYOLO Nano head
head:
- [-1, 1, Classify, [nc]] # Detect(P3, P4, P5)
In my case, I have 2.32 GFLOP with a 640-by-640 input size. With a 224-by-224 image size, I have 0.284 GFLOP.
from ultralytics import YOLO
model = YOLO("ultralytics/cfg/cfg/your_leyolo_classify.yaml")
#out:
#WARNING ⚠️ no model scale passed. Assuming scale='n'.
#FLOP(G): 2.3211008000000004
#leYOLO_cls summary: 158 layers, 1772232 parameters, 1772232 gradients, 2.321101 GFLOPs
The ultralytics API for calculating the number of FLOP is based on 640p input. Since you do classification, you need to change in ultralytics/utils/torch_utils.py the variable imgsz in function get_flops().
This is not an optimal solution for benchmarking the number of FLOPs with different image sizes, but we will work on it.
I think you might have used the neck part in your experimentation am I right ? If you wish to do classification, you might only use the backbone of LeYOLO! If you use the neck and the classifier with -1 index, the classification will be done on a very high input size, thus using tons of FLOP!
@LilianHollard Thank you very much. This is a problem in the process of my reproduction. I deleted the "SI" parameter in yaml, because I did not know what its function was, but it turned out to be necessary. Can you help me figure out what "SI" does? The default seems to be "RE".
"SI" and "RE" mean the type of activation function you want to use. "SI" is SiLU, while "RE" is ReLU.
Hi, I tried to use your research on different tasks, such as classification in v8, which I found to work, but when I tested FLOP, I found it reached 270+. This is weird. I just replaced the head part. Do you know why? If you want to reproduce my question it's easy to just change head to - [-1, 1, Classify, [nc]]