p2irc / deepplantphenomics

Deep learning for plant phenotyping.
GNU General Public License v2.0
133 stars 46 forks source link

Rotation Augmentation #31

Closed donovanlavoie closed 5 years ago

donovanlavoie commented 5 years ago

This adds a new augmentation option for training images for classification and regression tasks. Training images can now be randomly rotated by arbitrary angles from 0 to 360 degrees.

Rotating images introduces black borders around images, however, which can be dealt with by either cropping the borders out or leaving them and accepting worse training results. An option is provided for choosing between these methods.

For the cropping method, the tightest possible crop required (i.e. for 45 degree rotation) is chosen in order to remove black borders but maintain a similar scale across images. This will crop out at least half of the image, though, making it mostly suitable for images whose main features are centred and have plenty of featureless padding (ex. plants with mostly dirt around them).

The public API for this feature is the function set_augmentation_rotation, which sets a boolean flag for applying rotation and an optional flag for whether to crop out black borders as described above (turned off by default).

Testing was done using a small debugging script that, instead of starting up training, directly calls split_raw_data and __parse_dataset and then captures and displays the output augmentation images. It also combined random rotations with random cropping to make sure that rotation and border cropping cooperated with the new image size after random cropping. The images used were from the test_Ara2013_Canon test set. In all cases, images were visibly rotated (and missing black borders when called for), even with non-square aspect ratios.

Other tests still pass, and I also made a bunch of PEP8 changes.