|
@@ -49,6 +49,13 @@ class RandomHorizontalFlip:
|
|
|
lines[..., 0] = width - lines[..., 0]
|
|
lines[..., 0] = width - lines[..., 0]
|
|
|
target["lines"] = lines
|
|
target["lines"] = lines
|
|
|
|
|
|
|
|
|
|
+ # Flip lines
|
|
|
|
|
+ if "circle_masks" in target:
|
|
|
|
|
+ lines = target["circle_masks"].clone()
|
|
|
|
|
+ # 只翻转 x 坐标,y 和 visibility 不变
|
|
|
|
|
+ lines[..., 0] = width - lines[..., 0]
|
|
|
|
|
+ target["circle_masks"] = lines
|
|
|
|
|
+
|
|
|
return img, target
|
|
return img, target
|
|
|
|
|
|
|
|
class RandomVerticalFlip:
|
|
class RandomVerticalFlip:
|
|
@@ -74,6 +81,12 @@ class RandomVerticalFlip:
|
|
|
lines[..., 1] = height - lines[..., 1]
|
|
lines[..., 1] = height - lines[..., 1]
|
|
|
target["lines"] = lines
|
|
target["lines"] = lines
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if "circle_masks" in target:
|
|
|
|
|
+ lines = target["circle_masks"].clone()
|
|
|
|
|
+ lines[..., 1] = height - lines[..., 1]
|
|
|
|
|
+ target["circle_masks"] = lines
|
|
|
|
|
+
|
|
|
return img, target
|
|
return img, target
|
|
|
|
|
|
|
|
|
|
|
|
@@ -128,6 +141,9 @@ class RandomResize:
|
|
|
if "lines" in target:
|
|
if "lines" in target:
|
|
|
target["lines"] = target["lines"] * torch.tensor([scale, scale, 1], device=target["lines"].device)
|
|
target["lines"] = target["lines"] * torch.tensor([scale, scale, 1], device=target["lines"].device)
|
|
|
|
|
|
|
|
|
|
+ if "circle_masks" in target:
|
|
|
|
|
+ target["circle_masks"] = target["circle_masks"] * torch.tensor([scale, scale, 1], device=target["circle_masks"].device)
|
|
|
|
|
+
|
|
|
return img, target
|
|
return img, target
|
|
|
|
|
|
|
|
|
|
|
|
@@ -280,6 +296,9 @@ class RandomRotation:
|
|
|
if "lines" in target:
|
|
if "lines" in target:
|
|
|
target["lines"] = self.rotate_lines(target["lines"], angle, center)
|
|
target["lines"] = self.rotate_lines(target["lines"], angle, center)
|
|
|
|
|
|
|
|
|
|
+ if "circle_masks" in target:
|
|
|
|
|
+ target["circle_masks"] = self.rotate_lines(target["circle_masks"], angle, center)
|
|
|
|
|
+
|
|
|
return img, target
|
|
return img, target
|
|
|
|
|
|
|
|
|
|
|
|
@@ -452,6 +471,9 @@ class RandomPerspective:
|
|
|
if "lines" in target:
|
|
if "lines" in target:
|
|
|
target["lines"] = self.perspective_lines(target["lines"], M, width, height)
|
|
target["lines"] = self.perspective_lines(target["lines"], M, width, height)
|
|
|
|
|
|
|
|
|
|
+ if "circle_masks" in target:
|
|
|
|
|
+ target["circle_masks"] = self.perspective_lines(target["circle_masks"], M, width, height)
|
|
|
|
|
+
|
|
|
return img, target
|
|
return img, target
|
|
|
|
|
|
|
|
class DefaultTransform(nn.Module):
|
|
class DefaultTransform(nn.Module):
|