-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Problem of replacing Conv with LightConv in yolov8.yaml #12803
Comments
👋 Hello @Malvinlam, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered. If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it. If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results. Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users. InstallPip install the pip install ultralytics EnvironmentsYOLOv8 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 Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit. |
Hello, Thanks for reaching out with your issue! It looks like the error you're experiencing with the If # Define in your yolov8n.yaml
backbone:
# Existing layers
...
- [from, number, LightConv, args] # Ensure LightConv is properly defined in your code
... And make sure to implement import torch
from torch import nn
class LightConv(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, stride):
super(LightConv, self).__init__()
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride)
self.activ = nn.ReLU()
def forward(self, x):
return self.activ(self.conv(x))
# Register the module
torch.nn.LightConv = LightConv Ensure that this custom module is correctly recognized and placed within your project structure. This will allow Ultralytics YOLO to load and use Please double-check that you integrate your custom layers properly and feel free to update here if there are more issues or concerns! |
I tried to add the
|
Hi there! It looks like the error you're encountering is related to the YAML syntax in your Make sure that your YAML file is correctly formatted. YAML is sensitive to indentation and requires spaces (not tabs) for nesting. Each nested level should be indented by two spaces relative to its parent. Here's a quick example: backbone:
- from: -1
number: 1
module: LightConv
args: [256, 3, 1] Ensure there are no tabs or misplaced characters in your YAML configuration. Also, double-check that the If If the problem persists, you might want to validate your YAML file with a YAML linter to catch any subtle syntax issues. |
I tried to add two space but its not working also. Here's my
I even try
which shows no error for this line on Colab terminal, but I still cannot declare the model:
it still shows me the same error:
I tried the yamllint, which only shows warning for the comment on my |
Hi there! It seems like the Here’s a quick suggestion:
If these steps don’t resolve the issue, it might be helpful to provide more details about the modifications you've made to |
Search before asking
Question
I was going to train a Yolov8 model by using LightConv as feature extractor, but I can't seem to proceed of building the model, similar attempt is fine for the case of DWConv. The code and output on Colab is as follows:
Additional
Custom YOLO model initialization
model = YOLO("yolov8n.yaml")
Check the model architecture
print(model)
Output:
KeyError Traceback (most recent call last)
in <cell line: 2>()
1 # Custom YOLO model initialization
----> 2 model = YOLO("yolov8n.yaml")
3
4 # Check the model architecture
5 print(model)
4 frames
/usr/local/lib/python3.10/dist-packages/ultralytics/models/yolo/model.py in init(self, model, task, verbose)
21 else:
22 # Continue with default YOLO initialization
---> 23 super().init(model=model, task=task, verbose=verbose)
24
25 @Property
/usr/local/lib/python3.10/dist-packages/ultralytics/engine/model.py in init(self, model, task, verbose)
148 # Load or create new YOLO model
149 if Path(model).suffix in {".yaml", ".yml"}:
--> 150 self._new(model, task=task, verbose=verbose)
151 else:
152 self._load(model, task=task)
/usr/local/lib/python3.10/dist-packages/ultralytics/engine/model.py in _new(self, cfg, task, model, verbose)
217 self.cfg = cfg
218 self.task = task or guess_model_task(cfg_dict)
--> 219 self.model = (model or self._smart_load("model"))(cfg_dict, verbose=verbose and RANK == -1) # build model
220 self.overrides["model"] = self.cfg
221 self.overrides["task"] = self.task
/usr/local/lib/python3.10/dist-packages/ultralytics/nn/tasks.py in init(self, cfg, ch, nc, verbose)
285 if nc and nc != self.yaml["nc"]:
286 LOGGER.info(f"Overriding model.yaml nc={self.yaml['nc']} with nc={nc}")
--> 287 self.yaml["nc"] = nc # override YAML value
288 self.model, self.save = parse_model(deepcopy(self.yaml), ch=ch, verbose=verbose) # model, savelist
289 self.names = {i: f"{i}" for i in range(self.yaml["nc"])} # default names dict
/usr/local/lib/python3.10/dist-packages/ultralytics/nn/tasks.py in parse_model(d, ch, verbose)
853 ch = [ch]
854 layers, save, c2 = [], [], ch[-1] # layers, savelist, ch out
--> 855 for i, (f, n, m, args) in enumerate(d["backbone"] + d["head"]): # from, number, module, args
856 m = getattr(torch.nn, m[3:]) if "nn." in m else globals()[m] # get module
857 for j, a in enumerate(args):
KeyError: 'LightConv'
The text was updated successfully, but these errors were encountered: