ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
28.9k stars 5.72k forks source link

Change the number of channels and preprocess the image. #15825

Open SnifferCaptain opened 1 month ago

SnifferCaptain commented 1 month ago

Search before asking

Question

Thanks for your fantastic model before I begin. I want to change the channels from 3 to 4 to meet my personal requirements, but here are the challenge: The image I read is originally three channels (BGR), but I want to randomly select a label based on the situation and convert it into a mask for the fourth channel of this image. such code may look like: ////// alpha_channel = np.zeros(img.shape[:2], dtype=np.uint8)#3channels cv2.rectangle(alpha_channel, p1, p2, 255, -1) img_rgba = np.dstack((img, alpha_channel))#4channels ////// but I don't know where should I put this transform. Help me plz...

yolov8-det while training.

Additional

No response

glenn-jocher commented 1 month ago

@SnifferCaptain thank you for your question and for using our model! To add a fourth channel to your images during training, you can modify the dataset loading function to include your transformation. This can be done in the load_image function within the dataset class. If you need further assistance, please refer to the Ultralytics documentation.