Darknet: Vertical Flip

Created on 28 Aug 2020  路  5Comments  路  Source: AlexeyAB/darknet

does vertical flip as an augmentation for object detection exist? I'm working on an aerial dataset for which vertical flip would be just as useful as horizontal flip. I can always manually flip all my images if not.

Feature-request

All 5 comments

Currently Darknet doesn't support vertical flip.

"Bug fixed"? Last commit I see is on August 16...am I missing something?

@LukeAI you may also want to see this, which rotates 90, 180, and 270 degrees. Rotates the markup as well as the images: https://www.ccoderun.ca/darkmark/DataAugmentationRotation.html

"Bug fixed"?

Miss click )

wrote a quick 'n dirty script to augment a folder of images (and darknet annotations) with vertical flips. Adding here just in case somebody finds this thread and wants to do similar.

It creates a copy of each image called _filename_flip.jpg and also transforms the annotation (if it's there).

Usage:
./flipyolo.py /path/to/folder/
flipyolo.py.txt

Right now the function used to flip an image is this one (in _image.c_):

void flip_image(image a)
{
    int i,j,k;
    for(k = 0; k < a.c; ++k){
        for(i = 0; i < a.h; ++i){
            for(j = 0; j < a.w/2; ++j){
                int index = j + a.w*(i + a.h*(k));
                int flip = (a.w - j - 1) + a.w*(i + a.h*(k));
                float swap = a.data[flip];
                a.data[flip] = a.data[index];
                a.data[index] = swap;
            }
        }   
    }
}

To add vertical flip we could rename this one to _horizontal_flip_image_ (renaming all its usage in the project) and adding a _vertical_flip_image_ that looks something like this:

void flip_image_vertical(image a)
{
    int i,j,k;
    for(k = 0; k < a.c; ++k){
        for(j = 0; j < a.w; ++j){
            for(i = 0; i < a.h/2; ++i){
                int index = i + a.h*(j + a.w*(k));
                int flip = (a.h - i - 1) + a.h*(j + a.w*(k));
                float swap = a.data[flip];
                a.data[flip] = a.data[index];
                a.data[index] = swap;
            }
        }
    }
}

Then the only thing we would have to do is change the parsing of the cfg file to add both options, right? I haven't tested it tho.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HilmiK picture HilmiK  路  3Comments

shootingliu picture shootingliu  路  3Comments

siddharth2395 picture siddharth2395  路  3Comments

louisondumont picture louisondumont  路  3Comments

Yumin-Sun-00 picture Yumin-Sun-00  路  3Comments