Add dpg for data augmentation, including random crop and random sample.
(bbox, imgwidth, imght)
| 36 | |
| 37 | |
| 38 | def addDPG(bbox, imgwidth, imght): |
| 39 | """Add dpg for data augmentation, including random crop and random sample.""" |
| 40 | PatchScale = random.uniform(0, 1) |
| 41 | width = bbox[2] - bbox[0] |
| 42 | ht = bbox[3] - bbox[1] |
| 43 | |
| 44 | if PatchScale > 0.85: |
| 45 | ratio = ht / width |
| 46 | if (width < ht): |
| 47 | patchWidth = PatchScale * width |
| 48 | patchHt = patchWidth * ratio |
| 49 | else: |
| 50 | patchHt = PatchScale * ht |
| 51 | patchWidth = patchHt / ratio |
| 52 | |
| 53 | xmin = bbox[0] + random.uniform(0, 1) * (width - patchWidth) |
| 54 | ymin = bbox[1] + random.uniform(0, 1) * (ht - patchHt) |
| 55 | xmax = xmin + patchWidth + 1 |
| 56 | ymax = ymin + patchHt + 1 |
| 57 | else: |
| 58 | xmin = max( |
| 59 | 1, min(bbox[0] + np.random.normal(-0.0142, 0.1158) * width, imgwidth - 3)) |
| 60 | ymin = max( |
| 61 | 1, min(bbox[1] + np.random.normal(0.0043, 0.068) * ht, imght - 3)) |
| 62 | xmax = min( |
| 63 | max(xmin + 2, bbox[2] + np.random.normal(0.0154, 0.1337) * width), imgwidth - 3) |
| 64 | ymax = min( |
| 65 | max(ymin + 2, bbox[3] + np.random.normal(-0.0013, 0.0711) * ht), imght - 3) |
| 66 | |
| 67 | bbox[0] = xmin |
| 68 | bbox[1] = ymin |
| 69 | bbox[2] = xmax |
| 70 | bbox[3] = ymax |
| 71 | |
| 72 | return bbox |
| 73 | |
| 74 | |
| 75 | def im_to_torch(img): |