Untitled
unknown
python
15 days ago
1.5 kB
8
Indexable
Never
tiles = 2 # 3?? # v for loopu nekako takole: thr = xy??? if (bboxes[:,:,2]-bboxes[:,:,0]).mean() > thr or (bboxes[:,:,3]-bboxes[:,:,1]).mean() > thr: tile = img.shape[2] // tiles imgs = [] for i in range(tiles): for j in range(tiles): imgs.append(img[:, :, i * tile:(i + 1) * tile, j * tile:(j + 1) * tile]) # change bboxes: # if a bbox is in the image, it has to have all coordinates > 0 and x2 and y2 < image size bboxes_ = [] for i in range(tiles): for j in range(tiles): bboxes_.append(bboxes - torch.tensor([j * tile, i * tile, j * tile, i * tile]).to(device)) # check on which tile a bbox is for i in range(tiles*tiles): bboxes_[i] = bboxes_[i][torch.logical_not( torch.logical_or((bboxes_[i] < 0).any(dim=2), (bboxes_[i] > imgs[i].shape[3]).any(dim=2)))] # # pad bboxes to have the same number of bboxes max_num_bboxes = max([bboxes_[i].shape[0] for i in range(tiles*tiles)]) for i in range(tiles*tiles): bboxes_[i] = torch.cat([bboxes_[i], torch.zeros((max_num_bboxes - bboxes_[i].shape[0], 4)).to(device)]) bboxes_batch = torch.stack([bb for bb in bboxes_])*tiles img_batch = torch.stack([im[0] for im in imgs]) # Upscale image tensor to 1024,1024 img_batch = torch.nn.functional.interpolate(img_batch, size=1024, mode='bilinear', align_corners=False) #### Kjer imaš roi-pooling popravi, da se concatenirajo exemplarji in replicirajo v batch size (tj #tiles)
Leave a Comment