with open(path, 'rb') as f: img = Image.open(f) # Resize image if specified. resized_img = img.resize( resizeDim, Image.ANTIALIAS) if (resizeDim != None) else img # Crop image if crop area specified. cropped_img = img.crop(cropArea) if (cropArea != None) else resized_img # Flip image horizontally if specified. flipped_img = cropped_img.transpose( Image.FLIP_LEFT_RIGHT) if frameFlip else cropped_img return flipped_img.convert('RGB') bdcn = bdcn.BDCN() bdcn.cuda() structure_gen = layers.StructureGen(feature_level=args.feature_level) structure_gen.cuda() detail_enhance = layers.DetailEnhance() detail_enhance.cuda() # Channel wise mean calculated on adobe240-fps training dataset mean = [0.5, 0.5, 0.5] std = [0.5, 0.5, 0.5] normalize = transforms.Normalize(mean=mean, std=std) transform = transforms.Compose([transforms.ToTensor(), normalize]) negmean = [-1 for x in mean] restd = [2, 2, 2] revNormalize = transforms.Normalize(mean=negmean, std=restd) TP = transforms.Compose([revNormalize, transforms.ToPILImage()])
img = Image.open(f) # Resize image if specified. resized_img = img.resize( resizeDim, Image.ANTIALIAS) if (resizeDim != None) else img # Crop image if crop area specified. cropped_img = img.crop(cropArea) if (cropArea != None) else resized_img # Flip image horizontally if specified. flipped_img = cropped_img.transpose( Image.FLIP_LEFT_RIGHT) if frameFlip else cropped_img return flipped_img.convert('RGB') bdcn = bdcn.BDCN() bdcn.cuda() # structure_gen = layers.StructureGen(feature_level=args.feature_level) structure_gen = layers.StructureGen(3) structure_gen.cuda() detail_enhance = layers.DetailEnhance() detail_enhance.cuda() # Channel wise mean calculated on adobe240-fps training dataset mean = [0.5, 0.5, 0.5] std = [0.5, 0.5, 0.5] normalize = transforms.Normalize(mean=mean, std=std) transform = transforms.Compose([transforms.ToTensor(), normalize]) negmean = [-1 for x in mean] restd = [2, 2, 2] revNormalize = transforms.Normalize(mean=negmean, std=restd) TP = transforms.Compose([revNormalize, transforms.ToPILImage()])