(self, index)
| 542 | # return self |
| 543 | |
| 544 | def __getitem__(self, index): |
| 545 | if self.image_weights: |
| 546 | index = self.indices[index] |
| 547 | |
| 548 | hyp = self.hyp |
| 549 | mosaic = self.mosaic and random.random() < hyp['mosaic'] |
| 550 | if mosaic: |
| 551 | # Load mosaic |
| 552 | img, labels = load_mosaic(self, index) |
| 553 | #img, labels = load_mosaic9(self, index) |
| 554 | shapes = None |
| 555 | |
| 556 | # MixUp https://arxiv.org/pdf/1710.09412.pdf |
| 557 | if random.random() < hyp['mixup']: |
| 558 | img2, labels2 = load_mosaic(self, random.randint(0, len(self.labels) - 1)) |
| 559 | #img2, labels2 = load_mosaic9(self, random.randint(0, len(self.labels) - 1)) |
| 560 | r = np.random.beta(8.0, 8.0) # mixup ratio, alpha=beta=8.0 |
| 561 | img = (img * r + img2 * (1 - r)).astype(np.uint8) |
| 562 | labels = np.concatenate((labels, labels2), 0) |
| 563 | |
| 564 | else: |
| 565 | # Load image |
| 566 | img, (h0, w0), (h, w) = load_image(self, index) |
| 567 | |
| 568 | # Letterbox |
| 569 | shape = self.batch_shapes[self.batch[index]] if self.rect else self.img_size # final letterboxed shape |
| 570 | img, ratio, pad = letterbox(img, shape, auto=False, scaleup=self.augment) |
| 571 | shapes = (h0, w0), ((h / h0, w / w0), pad) # for COCO mAP rescaling |
| 572 | |
| 573 | # Load labels |
| 574 | labels = [] |
| 575 | x = self.labels[index] |
| 576 | if x.size > 0: |
| 577 | # Normalized xywh to pixel xyxy format |
| 578 | labels = x.copy() |
| 579 | labels[:, 1] = ratio[0] * w * (x[:, 1] - x[:, 3] / 2) + pad[0] # pad width |
| 580 | labels[:, 2] = ratio[1] * h * (x[:, 2] - x[:, 4] / 2) + pad[1] # pad height |
| 581 | labels[:, 3] = ratio[0] * w * (x[:, 1] + x[:, 3] / 2) + pad[0] |
| 582 | labels[:, 4] = ratio[1] * h * (x[:, 2] + x[:, 4] / 2) + pad[1] |
| 583 | |
| 584 | if self.augment: |
| 585 | # Augment imagespace |
| 586 | if not mosaic: |
| 587 | img, labels = random_perspective(img, labels, |
| 588 | degrees=hyp['degrees'], |
| 589 | translate=hyp['translate'], |
| 590 | scale=hyp['scale'], |
| 591 | shear=hyp['shear'], |
| 592 | perspective=hyp['perspective']) |
| 593 | |
| 594 | # Augment colorspace |
| 595 | augment_hsv(img, hgain=hyp['hsv_h'], sgain=hyp['hsv_s'], vgain=hyp['hsv_v']) |
| 596 | |
| 597 | # Apply cutouts |
| 598 | # if random.random() < 0.9: |
| 599 | # labels = cutout(img, labels) |
| 600 | |
| 601 | nL = len(labels) # number of labels |
nothing calls this directly
no test coverage detected