Skip to content
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

how to use this with a datasets? #28

Open
v1ns0n0 opened this issue Dec 19, 2024 · 7 comments
Open

how to use this with a datasets? #28

v1ns0n0 opened this issue Dec 19, 2024 · 7 comments
Labels
question Further information is requested

Comments

@v1ns0n0
Copy link

v1ns0n0 commented Dec 19, 2024

hello, how to use this with a datasets?

@Koldim2001 Koldim2001 added the question Further information is requested label Dec 19, 2024
@Koldim2001
Copy link
Owner

This technology is useful if your datasets contain a large number of objects in each frame. In other cases, you can use the standard YOLO without the patch mode.

If your goal is to run the technology on a pre-trained model on COCO, you can simply use the automatic patching technology, which will help you determine the optimal parameter values for patches to detect a large number of objects in images (see the section "How to Automatically Determine Optimal Parameters for Patches (Crops)" in the README for instructions on how to work with this).

@Koldim2001
Copy link
Owner

If you want to train the network on your own datasets and then run inference with the patch-based approach, it is recommended to initially slice your dataset into patches of a fixed size, where each patch contains a maximum of 0 to 30 objects. You should then train the YOLO model on this dataset. After that, you can use this model with the patch-based approach, specifying the same slicing parameters that you used when creating the dataset (i.e., the same values for shape_x, shape_y, overlap_x, and overlap_y) using this library.

@Koldim2001
Copy link
Owner

Koldim2001 commented Jan 2, 2025

@v1ns0n0 Good afternoon. Could you tell me if you managed to figure it out? Did I answer your question?

@v1ns0n0
Copy link
Author

v1ns0n0 commented Jan 7, 2025

import cv2
from ultralytics import YOLO
from patched_yolo_infer import auto_calculate_crop_values

Load the image
img_path = "test_image.jpg"
img = cv2.imread(img_path)

Calculate the optimal crop size and overlap for an image
shape_x, shape_y, overlap_x, overlap_y = auto_calculate_crop_values(
image=img, mode="network_based", model=YOLO("yolov8m.pt")
)
I don't know how to apply it to an individual's dataset and use it to train a model

@Koldim2001
Copy link
Owner

This technology allows you to increase the number of detections made by the YOLO network, so it makes sense that you first need to train the YOLO network on your dataset. You can learn how to do this on this website: https://docs.ultralytics.com/modes/train/.
There are hundreds of detailed tutorials on YouTube about training Ultralytics YOLO networks, so I recommend checking them out. Once the network is trained and you encounter issues with small, hard-to-detect objects in the frame, you can then use this library, patched_yolo_infer.

@Jordan-Pierce
Copy link
Contributor

@v1ns0n0 If you want to apply "patching" (or tiling) to a YOLO dataset to train / validate / test a YOLO model (ultralytics), checkout this other repository (it's mine)

https://github.com/Jordan-Pierce/yolo-tiling

Once you have a YOLO dataset, you can use my library to tile it (the train, valid, and test data) intoa tiled version. Use this tiled version to train your model.

Then, after you trained your model, use this library (YOLO-Patch-Based-Inference), which tiles images for models for during inference time.

@Koldim2001
Copy link
Owner

@Jordan-Pierce Excellent project. I was just thinking about doing something like this someday. Thank you for sharing and for letting me know that there’s already a ready-to-use tool for dataset slicing. If people are interested in how to prepare datasets, I will definitely recommend your library for this purpose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants