How to deploy a trained Gelan C-seg model?

Hello, i have trained a Gelan C-seg model for instance segmentation and i want to include it in my code to access the results directly to change the output image such as text font size. Due to large amount of images, i do not want to save images to my local workspace, i just want to display it and see if it is correct. For YOLOv8 i could do it with:

results = model.predict(), this gives me access to all output object such as orig_img, masks.xy etc. However, when i tried to run this by including Gelan C-seg yaml, the result output shows None for all masks. How do i resolve this? Thank you

Hello! :blush:

It sounds like you’re on an exciting project with the Gelan C-seg model! If you’re seeing None for all masks, it might be due to a few reasons. Here are some steps you can take to troubleshoot and resolve the issue:

  1. Check Model Compatibility: Ensure that the Gelan C-seg model is compatible with the Ultralytics framework you’re using. Sometimes, custom models may require specific configurations.

  2. Verify YAML Configuration: Double-check your YAML configuration to ensure all paths and parameters are correctly set. Any discrepancies might lead to unexpected results.

  3. Inspect Model Weights: Make sure the model weights are correctly loaded. You can try reloading the model to see if that resolves the issue.

  4. Use Latest Version: Ensure you’re using the latest version of the Ultralytics package. Updates often include bug fixes and improvements.

  5. Debugging: Add some print statements or use a debugger to inspect the intermediate outputs. This might help identify where things are going wrong.

Here’s a quick example of how you might structure your code to display results without saving:

from ultralytics import YOLO

# Load your model
model = YOLO('gelan-c-seg.yaml')

# Run prediction
results = model.predict('path/to/image.jpg')

# Access and display results
for result in results:
    if result.masks is not None:
        # Display or process your results here
        result.show()
    else:
        print("No masks detected.")

For more detailed guidance, you can refer to the Ultralytics documentation.

If the issue persists, feel free to share more details, and we can dive deeper. Good luck with your project! :rocket:

Thank you for your suggestion. Here are some of the errors i encountered.

I got an error when i ran:
model = YOLO(“best.pt”) which is my trained gelan c-seg weights.

TypeError: ERROR best.pt appears to be an Ultralytics YOLOv5 model originally trained with GitHub - ultralytics/yolov5: YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite.
This model is NOT forwards compatible with YOLOv8 at GitHub - ultralytics/ultralytics: Ultralytics YOLO11 🚀.

When i ran another line i got another error:
model = YOLO(‘gelan-c-seg.yaml’)

File “C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\ultralytics\nn\tasks.py”, line 678, in parse_model
m = getattr(torch.nn, m[3:]) if ‘nn.’ in m else globals()[m] # get module
~~~~~~~~~^^^
KeyError: ‘RepNCSPELAN4’

From what i know, Gelan C-seg is YOLOv9, not YOLOv5 so i do not know where did the error generate from. However, please correct me if i’m wrong.

@Cereal if your best.pt model was not trained using the ultralytics library GitHub - ultralytics/ultralytics: Ultralytics YOLO11 🚀 and instead used another repository that was based on the YOLOv5 codebase (like the WongKinYiu repository), then it will not work as-is with ultralytics. You will need to train the model using the ultralytics package natively, as the weights files are not compatible with other code bases.

from ultralytics import YOLO

model = YOLO("yolov9c-seg.pt")

# Train model (if needed)
train_results = model.train(data="path/to/data.yaml")  # update with other training arguments

model = YOLO("path/to/best.pt")

results = model.predict("path/to/source.png")

For brevity, I’ve included these all in a single block, but you’d likely want to separate out use of the predict() method to a new Python session. Once you have prediction results, you can see what methods are available to the Results object in the documentation Predict - Ultralytics YOLO Docs

You can test using the pretrained yolov9c-seg.pt model to ensure it works with the following:

from ultralytics import YOLO, ASSETS

model = YOLO("yolov9c-seg.pt")
results = model.predict(ASSETS / "bus.jpg")
for result in results:
    print(result.masks.xy)
    result.show()  # preview image (does not wait, could open multiple windows for more than one file)