Skip to content

Data augmentation via random rotations#1386

Closed
dgolden1 wants to merge 2 commits intoBVLC:devfrom
CellScope:random-rotate
Closed

Data augmentation via random rotations#1386
dgolden1 wants to merge 2 commits intoBVLC:devfrom
CellScope:random-rotate

Conversation

@dgolden1
Copy link
Contributor

Some datasets are indifferent to which direction in the image is "up" and therefore can be augmented with random rotations. This PR implements a rotate option in the TransformationParameter message which operates analogously to mirror. It's false by default; setting it to true causes images to be randomly rotated by an integer multiple of 90 degrees. If mirror is also enabled, there are 8 possibilities for the randomly transformed output image.

An error is thrown if the input data is not square (i.e., if datum.height() != datum.width()); the logic for dealing with square rotations is easier to start with, and I believe that transformed_data is expected to have the same shape as the input data.

I added unit tests to test_data_transformer.cpp by copying and pasting some pre-existing mirroring unit tests; the tests show that this transformation runs, but they don't prove that it does what I expect it to do (i.e., rotate an image properly). I'm not a pro at Caffe unit tests, so if anyone can suggest how to write a unit test that confirms that the rotation is working properly, I'd be happy to implement it. I can (and probably will) copy the logic to a little test script in Matlab to convince myself that the logic is working, but that's not really good enough as a unit test.

I have not yet tried to train a network using the rotate parameter but that's next on my list. In the mean time, eyeballs on my rotation (and generalized mirroring) logic are welcome.

Update: I've trained a network using the random rotations and it worked just fine (if not necessarily any better than when random rotations were disabled).

@bhack
Copy link
Contributor

bhack commented Oct 31, 2014

I remember that @Bigene has something extended to other transformation (affine?)

@dgolden1
Copy link
Contributor Author

dgolden1 commented Nov 1, 2014

@bhack, can you link to the PR?

The advantage of 90 degree rotations is that they're nearly computationally free; they can be implemented by messing with input and output indexing, just like mirroring. Affine transformations are significantly more expensive, but potentially also very useful.

@dgolden1
Copy link
Contributor Author

dgolden1 commented Nov 1, 2014

Here's a Matlab test of the rotation logic: https://gist.github.com/drdan14/99dc38fb363913f295f5. I tried to copy the C++ rotation logic as closely as possible, offensive as nested for loops in Matlab are. Because C++ is 0-indexed and Matlab is 1-indexed, a tweak here and there was required.

The output looks good to me.

@bhack
Copy link
Contributor

bhack commented Nov 1, 2014

See @Bigene comments here #1070

@dgolden1
Copy link
Contributor Author

I don't have the bandwidth to rebase this onto master, so I am closing it.

@dgolden1 dgolden1 closed this Jun 17, 2015
@bhack
Copy link
Contributor

bhack commented Jun 17, 2015

@drdan14 Nevermind. I'm not satisfied with this but often caffe PR are subject to neverending rebase over the months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments