def postprocess(img: torch.tensor): # img = img[0][2] img = torch.argmax(img, dim=1) img = img.cpu().numpy() img = np.squeeze(img) img = re_normalize(img) # img = util.invert(img) return img
def transform_x(self, x): # make sure it's a numpy.ndarray on the cpu x = x.cpu().numpy() # from [C, H, W] to [H, W, C] - only for RGB images. if self.check_if_rgb(x): x = np.moveaxis(x, source=0, destination=-1) # Re-normalize x = re_normalize(x) return x
def transform_image(self, x): image_transformed = self.rcnn_transform([self.image]) x = image_transformed[0].tensors[0] # make sure it's a numpy.ndarray on the cpu x = x.cpu().numpy() # from [C, H, W] to [H, W, C] - only for RGB images. x = np.moveaxis(x, source=0, destination=-1) # Re-normalize x = re_normalize(x) return x
def transform_x(self, sample): # dict unpacking x, x_name = sample['x'], sample['x_name'] # make sure it's a numpy.ndarray on the cpu x = x.cpu().numpy() # from [C, H, W] to [H, W, C] - only for RGB images. if self.check_if_rgb(x): x = np.moveaxis(x, source=0, destination=-1) # Re-normalize x = re_normalize(x) return x, x_name
def __next__(self): x, y = next(iter(self.dataloader)) x, y = x.cpu().numpy(), y.cpu().numpy() # make sure it's a numpy.ndarray on the cpu # Batch batch_size = x.shape[0] rand_num = np.random.randint(low=0, high=batch_size) x, y = x[rand_num], y[rand_num] # Pick a random image from the batch # RGB if self.rgb: x = np.moveaxis(x, source=0, destination=-1) # from [C, H, W] to [H, W, C] # Re-normalize if self.re_normalize: from transformations import re_normalize x = re_normalize(x) return x, y
def transform_x(self, x): # Re-normalize x = re_normalize(x) return x
def postprocess(img: torch.tensor): img = torch.argmax(img, dim=1) # perform argmax to generate 1 channel img = img.cpu().numpy() # send to cpu and transform to numpy.ndarray img = np.squeeze(img) # remove batch dim and channel dim -> [H, W] img = re_normalize(img) # scale it to the range [0-255] return img