A python script that tiles (slices) images to a desired dimensions. Here is a screenshot of sample result using tile_yolo.py
.
If you're interested in knowing something for small object detection check out this gist.
-
Download
tile_yolo.py
. -
Place
tile_yolo.py
in the desired directory where user would like tiled images to be stored.Note:
tile_yolo.py
will automatically create the directories it requires. -
(Optional) Have a look at Recommended configurations
-
Install Python (preferably, version <= 10) Download.
Note: as of this writing, Python 3.11 or greater may cause error.
-
Download a python compatible IDE. I recommend Jupyter Notebook, PyCharm, DataSpell, or DeepNote.
Note: I wouldn't recommend a cloud service such as Google Colab due to the large amount of images that may be generated.
-
Install the required packages listed in
requirements.txt
by running the following command in the terminal:pip install -r requirements.txt
-
Users should have an annotated dataset. Check out Roboflow or LabelImg for quick and easy YOLO image annotation. Refer to their instructions/installation requirements.
-
When to use? Image tiling is recommended when the object of interest is very small compared to the parent image. Example: Small Object Detection: An Image Tiling Based Approach
-
tile_yolo.py
will create the necessary directories to run successfully however, users are encouraged to modify the directory creation code to fit their personal needs! -
Recommended approach: Place untiled images with their respective annotations into a folder called
Input
. Upon runningtile_yolo.py
the contents inInput
will tiled to a user's desired dimensions and tiles will be placed into a folder namedImages
. Finally, a user can decide to move the tiled annotation (.txt) files into a separate folder namedLabels
or keep the tiled images and their corresponding annotations together.Note: Keeping the tiled images and their annotations in the same directory is recommended for YOLO - YOLOv4
Note: Separating tiled images into
Images
and their annotations intoLabels
is recommended for YOLOv5 - YOLOv7
The python script can be run in terminal or in an IDE (PyCharm works great!).
Added several improvements to nagi1995 original
-Added directory-level tiling (all images in folder instead of a single image) :)
-Added user choice to keep tiled files in one directory (Recommended for YOLOv1-YOLOv4)
../datasets/images/im0.jpg # image
../datasets/images/im0.txt # label
-Added user choice to separate files into separate directories (Recommended for YOLOv5, YOLOX, YOLOR, YOLOv7, etc..)
../datasets/images/im0.jpg # image
../datasets/labels/im0.txt # label
-Added the creation of Images and Labels directory (user can modify code to choose a different directory)
-Added empty 'null' tile saving (if a tile doesn't have an annotation, user can discard or save them).
-Added progress bars via tqdm
Your contributions are always welcome! Special thanks to Mr. David Schmitt!