def train_transform(rgb, depth): s = np.random.uniform(1.0, 1.5) # random scaling # print("scale factor s={}".format(s)) depth_np = depth / s angle = np.random.uniform(-5.0, 5.0) # random rotation degrees do_flip = np.random.uniform(0.0, 1.0) < 0.5 # random horizontal flip # perform 1st part of data augmentation transform = transforms.Compose([ transforms.Resize( 250.0 / iheight ), # this is for computational efficiency, since rotation is very slow transforms.Rotate(angle), transforms.Resize(s), transforms.CenterCrop((oheight, owidth)), transforms.HorizontalFlip(do_flip) ]) rgb_np = transform(rgb) # random color jittering rgb_np = color_jitter(rgb_np) rgb_np = np.asfarray(rgb_np, dtype='float') / 255 depth_np = transform(depth_np) return rgb_np, depth_np
def train_transform(rgb, depth): s = np.random.uniform(1.0, 1.5) # random scaling # print("scale factor s={}".format(s)) depth_np = depth / s angle = np.random.uniform(-5.0, 5.0) # random rotation degrees do_flip = np.random.uniform(0.0, 1.0) < 0.5 # random horizontal flip # perform 1st part of data augmentation transform = transforms.Compose([ transforms.Crop(130, 10, 240, 1200), transforms.Rotate(angle), transforms.Resize(s), transforms.CenterCrop((oheight, owidth)), transforms.HorizontalFlip(do_flip) ]) rgb_np = transform(rgb) # random color jittering rgb_np = color_jitter(rgb_np) rgb_np = np.asfarray(rgb_np, dtype='float') / 255 # Scipy affine_transform produced RuntimeError when the depth map was # given as a 'numpy.ndarray' depth_np = np.asfarray(depth_np, dtype='float32') depth_np = transform(depth_np) return rgb_np, depth_np
def train_transform(rgb, depth): s = np.random.uniform(1.0, 1.5) # random scaling # print("scale factor s={}".format(s)) depth_np = depth / s angle = np.random.uniform(-5.0, 5.0) # random rotation degrees do_flip = np.random.uniform(0.0, 1.0) < 0.5 # random horizontal flip # set zeros in depth as NaN depth_np[depth_np == 0] = np.nan # perform 1st part of data augmentation transform = transforms.Compose([ transforms.Resize( float(image_size) / iheight ), # this is for computational efficiency, since rotation is very slow transforms.Rotate(angle), transforms.Resize(s), transforms.CenterCrop((oheight, owidth)), transforms.HorizontalFlip(do_flip), ]) rgb_np = transform(rgb) # random color jittering rgb_np = color_jitter(rgb_np) rgb_np = np.asfarray(rgb_np, dtype='float') / 255 rgb_np = normalize(rgb_np) # from [0,1] to [-1,1] depth_np = transform(depth_np) depth_np[np.isnan(depth_np)] = 0 depth_np = depth_np / 10.0 return rgb_np, depth_np
def train_transform(self, rgb: np.ndarray, depth_raw: np.ndarray, depth_fix: np.ndarray) -> TNpData: s = np.random.uniform(1.0, 1.5) # random scaling depth_raw = depth_raw / s depth_fix = depth_fix / s angle = np.random.uniform(-5.0, 5.0) # random rotation degrees do_flip = np.random.uniform(0.0, 1.0) < 0.5 # random horizontal flip # perform 1st part of data augmentation transform = transforms.Compose([ transforms.Resize( 250.0 / self.iheight ), # this is for computational efficiency, since rotation is very slow transforms.Rotate(angle), transforms.Resize(s), transforms.CenterCrop((self.oheight, self.owidth)), transforms.HorizontalFlip(do_flip) ]) rgb = transform(rgb) # random color jittering rgb = color_jitter(rgb) rgb = np.asfarray(rgb, dtype='float') / 255 depth_raw = transform(depth_raw) depth_fix = transform(depth_fix) return rgb, depth_raw, depth_fix
def train_transform(rgb, depth): s = np.random.uniform(1.0, 1.5) # random scaling # print("scale factor s={}".format(s)) depth_np = depth / s angle = np.random.uniform(-5.0, 5.0) # random rotation degrees do_flip = np.random.uniform(0.0, 1.0) < 0.5 # random horizontal flip # perform 1st part of data augmentation transform = transforms.Compose([ #transforms.Resize(530 / iheight), # this is for computational efficiency, since rotation is very slow transforms.Resize(250 / iheight), transforms.Rotate(angle), transforms.Resize(s), transforms.CenterCrop((oheight, owidth)), transforms.HorizontalFlip(do_flip) ]) rgb_np = transform(rgb) # 自己添加 # rgb_np = Transform.resize(rgb_np, [512, 512]) rgb_np = cv2.resize(rgb_np, (512, 512), interpolation=cv2.INTER_NEAREST) ########### # random color jittering rgb_np = color_jitter(rgb_np) rgb_np = np.asfarray(rgb_np, dtype='float') / 255 depth_np = transform(depth_np) #自己添加 depth_np = cv2.resize(depth_np, (512, 512), interpolation=cv2.INTER_NEAREST) #depth_np=Transform.resize(depth_np,[512,512]) ########### #data=rgb_np*255 #data=Image.fromarray(data.astype(np.uint8)) #data.show() return rgb_np, depth_np