ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
51.18k stars 16.43k forks source link

Error while running any YAML file in yolo.py #3501

Closed jaskiratsingh2000 closed 3 years ago

jaskiratsingh2000 commented 3 years ago

Hi @glenn-jocher I created this yaml file:

# parameters
nc: 80  # number of classes
depth_multiple: 1.0  # model depth multiple
width_multiple: 1.0  # layer channel multiple

# anchors
anchors:
  - [10,13, 16,30, 33,23]  # 52x52
  - [30,61, 62,45, 59,119]  # 26x26
  - [116,90, 156,198, 373,326]

# YOLOv3-tiny backbone
backbone:
  # [from, number, module, args[input_channel, output_channel, Kernel, stride]]
  [[-1, 1, conv3x3, [3, 12, 3, 1]],
   [-1, 1, conv3x3, [12, 24, 3, 2]],  # 0
   [-1, 1, PEP, [24, 24, 7, 1]],  # 1-P1/2
   [-1, 1, EP, [24, 70, 2]],
   [-1, 1, PEP, [70, 70, 25, 1]],
   [-1, 1, PEP, [70, 70, 24, 1]],
   [-1, 1, PEP, [70, 70, 25, 1]],
   [-1, 1, EP, [70, 150, 2]],
   [-1, 1, PEP, [150, 150, 56, 1]],
   [-1, 1, conv1x1, [150, 150, 1]],
   [-1, 1, FCA, [150, 8]],
   [-1, 1, PEP, [150, 150, 73, 1]],
   [-1, 1, PEP, [150, 150, 71, 1]],
   [-1, 1, PEP, [150, 150, 75, 1]],
   [-1, 1, EP, [150, 325, 2]],
   [-1, 1, PEP, [325, 325, 132, 1]],
   [-1, 1, PEP, [325, 325, 124, 1]],
   [-1, 1, PEP, [325, 325, 141, 1]],
   [-1, 1, PEP, [325, 325, 140, 1]],
   [-1, 1, PEP, [325, 325, 137, 1]],
   [-1, 1, PEP, [325, 325, 135, 1]],
   [-1, 1, PEP, [325, 325, 133, 1]],
   [-1, 1, PEP, [325, 325, 140, 1]],
   [-1, 1, PEP, [325, 545, 2]],
   [-1, 1, PEP, [545, 545, 276, 1]],
   [-1, 1, EP, [230, 489, 1]],
   [-1, 1, PEP, [489, 469, 213, 1]],
   [-1, 1, conv1x1, [469, 189, 1]],
   [-1, 1, conv1x1, [189, 105, 1]],
   [-1, 1, PEP, [430, 325, 113, 1]],
   [-1, 1, PEP, [325, 207, 99, 1]],
   [-1, 1, conv1x1, [207, 98, 1]],
   [-1, 1, conv1x1, [98, 47, 1]],
   [-1, 1, PEP, [197, 122, 58, 1]],
   [-1, 1, PEP, [122, 87, 52, 1]],
   [-1, 1, PEP, [87, 93, 47, 1]],
   [-1, 1, EP, [98, 183, 1]],
   [-1, 1, EP, [189, 462, 1]],
   [[19, 15], 1, Detect, [nc, anchors]],  # Detect(P4, P5)
  ]

So when I am trying to run this with python3 model/yolo.py it is giving me the following errors:

Traceback (most recent call last):
  File "models/yolo.py", line 294, in <module>
    model = Model(opt.cfg).to(device)
  File "models/yolo.py", line 93, in __init__
    self.model, self.save = parse_model(deepcopy(self.yaml), ch=[ch])  # model, savelist
  File "models/yolo.py", line 238, in parse_model
    m = eval(m) if isinstance(m, str) else m  # eval strings
  File "<string>", line 1, in <module>
NameError: name 'conv3x3' is not defined

Even I have tried importing the module that contains these layers class. You can check within the forked version here - https://github.com/jaskiratsingh2000/yolov5/tree/master/models with the name yolo_layers_network.py and basic_layers.py

@glenn-jocher Can you please help me simplify the things because I really want to check the profiling of the yolo-nano

glenn-jocher commented 3 years ago

@jaskiratsingh2000 for new modules you may need to add them to the L248 module list, and optionally provide custom code to deal with them in the yolo.py parse_model() function: https://github.com/ultralytics/yolov5/blob/90b7895d652c3bd3d361b2d6e9aee900fd67f5f7/models/yolo.py#L232-L283

jaskiratsingh2000 commented 3 years ago

@glenn-jocher I made changes but by adding the names of the modules in that specific line but it is till showing me the same error:

Traceback (most recent call last):
  File "models/yolo.py", line 294, in <module>
    model = Model(opt.cfg).to(device)
  File "models/yolo.py", line 93, in __init__
    self.model, self.save = parse_model(deepcopy(self.yaml), ch=[ch])  # model, savelist
  File "models/yolo.py", line 238, in parse_model
    m = eval(m) if isinstance(m, str) else m  # eval strings
  File "<string>", line 1, in <module>
NameError: name 'conv3x3' is not defined

@glenn-jocher consider helping me out with the specific things if possible since I am new to it.

glenn-jocher commented 3 years ago

@jaskiratsingh2000 python requires imports to function correctly.

jaskiratsingh2000 commented 3 years ago

@glenn-jocher I already did that but still, the error is the same You can check here:

https://github.com/jaskiratsingh2000/yolov5/blob/816e02288cfeae0b33c6687923789a1934546638/models/yolo.py#L18

and this one adding the modules.

https://github.com/jaskiratsingh2000/yolov5/blob/816e02288cfeae0b33c6687923789a1934546638/models/yolo.py#L246

@glenn-jocher Please let me know what do you think and how we can rectify that.

glenn-jocher commented 3 years ago

@jaskiratsingh2000 custom code is up to you my friend, we only assist with bugs or features we'd like to see integrated.

jaskiratsingh2000 commented 3 years ago

Okay! so I would really like to request if ultralytics can also have the tiniest version of yolo that is yolo-nano with the YAML file. Is that possible? @glenn-jocher

glenn-jocher commented 3 years ago

@jaskiratsingh2000 the smallest current version is YOLOv5s. Accuracy for smaller versions is not suitable for production use-cases, so we've not reduced size any smaller. https://github.com/ultralytics/yolov5/blob/develop/models/yolov5s.yaml

For a smaller-sized model with minimal accuracy losses you should probably simply use YOLOv5s-ghost in https://github.com/ultralytics/yolov5/issues/3234

Model size
(pixels)
mAPval
0.5:0.95
mAPtest
0.5:0.95
mAPval
0.5
Speed
T4 (ms)
params
(M)
FLOPS
640 (B)
YOLOv5s 640 37.0 - 56.4 4.7 7.3 17.0
YOLOv5s-ghost1 640 35.2 - 54.0 4.8 5.1 11.2
YOLOv5s-ghost2 640 35.6 - 54.1 4.9 3.9 8.8
jaskiratsingh2000 commented 3 years ago

@glenn-jocher How can I access the YAML file for the YOLOv5s-ghost? I was not able to find that on this repo. Please let me know Thanks!

glenn-jocher commented 3 years ago

@jaskiratsingh2000 follow https://github.com/ultralytics/yolov5/issues/3234, and also see branch ghost

github-actions[bot] commented 3 years ago

👋 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 ⭐!