def forward(self, clips): h, w, _ = clips[0].shape oh, ow = self.size if h < oh or w < ow: raise ValueError("Cannot crop area {} from image with size \ ({}, {})".format(str(self.size), h, w)) new_clips = [] for cur_img in clips: center = cur_img[(h - oh) // 2:(h + oh) // 2, (w - ow) // 2:(w + ow) // 2, :] tl = cur_img[0:oh, 0:ow, :] bl = cur_img[h - oh:h, 0:ow, :] tr = cur_img[0:oh, w - ow:w, :] br = cur_img[h - oh:h, w - ow:w, :] new_clips.append(center) new_clips.append(tl) new_clips.append(bl) new_clips.append(tr) new_clips.append(br) new_clips.append(np.flip(center, axis=1)) new_clips.append(np.flip(tl, axis=1)) new_clips.append(np.flip(bl, axis=1)) new_clips.append(np.flip(tr, axis=1)) new_clips.append(np.flip(br, axis=1)) return new_clips
def forward(self, clips): h, w, _ = clips[0].shape ctx = clips[0].context crop_size_pairs = self.fillCropSize(h, w) size_sel = random.randint(0, len(crop_size_pairs)-1) crop_height = crop_size_pairs[size_sel][0] crop_width = crop_size_pairs[size_sel][1] is_flip = random.random() < self.prob if self.fix_crop: offsets = self.fillFixOffset(h, w) off_sel = random.randint(0, len(offsets)-1) h_off = offsets[off_sel][0] w_off = offsets[off_sel][1] else: h_off = random.randint(0, h - self.height) w_off = random.randint(0, w - self.width) new_clips = [] for cur_img in clips: crop_img = cur_img[h_off:h_off+crop_height, w_off:w_off+crop_width, :] scale_img = npx.image.resize(crop_img, (self.width, self.height)) if is_flip: flip_img = np.flip(scale_img, axis=1) else: flip_img = scale_img tensor_img = np.transpose(flip_img, axes=(2, 0, 1)) / self.max_intensity new_clips.append((tensor_img - self.mean.as_in_context(ctx)) / self.std.as_in_context(ctx)) return new_clips
def forward(self, clips): new_clips = [] if random.random() < self.prob: for cur_img in clips: new_clips.append(np.flip(cur_img, axis=1)) else: new_clips = clips return new_clips
def sort(tensor, axis, descending=False): if descending: return np.flip(np.sort(tensor, axis=axis), axis=axis) else: return np.sort(tensor, axis=axis)