Skip to content

Commit

Permalink
[orientation] augment angle while training (#1567)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixdittrich92 authored Apr 26, 2024
1 parent 124960d commit 5568612
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion references/classification/train_pytorch_orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
def rnd_rotate(img: torch.Tensor, target):
angle = int(np.random.choice(CLASSES))
idx = CLASSES.index(angle)
rotated_img = F.rotate(img, angle=-angle, fill=0, expand=False)[:3]
# augment the angle randomly with a probability of 0.5
if np.random.rand() < 0.5:
angle += float(np.random.choice(np.arange(-25, 25, 5)))
rotated_img = F.rotate(img, angle=-angle, fill=0, expand=angle not in CLASSES)[:3]
return rotated_img, idx


Expand Down
5 changes: 4 additions & 1 deletion references/classification/train_tensorflow_orientation.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@
def rnd_rotate(img: tf.Tensor, target):
angle = int(np.random.choice(CLASSES))
idx = CLASSES.index(angle)
# augment the angle randomly with a probability of 0.5
if np.random.rand() < 0.5:
angle += float(np.random.choice(np.arange(-25, 25, 5)))
# clockwise rotation
rotated_img = rotated_img_tensor(img, -angle, expand=False)
rotated_img = rotated_img_tensor(img, -angle, expand=angle not in CLASSES)
return rotated_img, idx


Expand Down

0 comments on commit 5568612

Please sign in to comment.