def __call__(self, input_orig, target_orig): # do something to both images input = Resize(self.height, Image.BILINEAR)(input_orig) target = Resize(self.height, Image.NEAREST)(target_orig) if(self.augment): # Random hflip hflip = random.random() if (hflip < 0.5): input = input.transpose(Image.FLIP_LEFT_RIGHT) target = target.transpose(Image.FLIP_LEFT_RIGHT) #Random translation 0-2 pixels (fill rest with padding transX = random.randint(-2, 2) transY = random.randint(-2, 2) input = ImageOps.expand(input, border=(transX,transY,0,0), fill=0) target = ImageOps.expand(target, border=(transX,transY,0,0), fill=255) #pad label filling with 255 input = input.crop((0, 0, input.size[0]-transX, input.size[1]-transY)) target = target.crop((0, 0, target.size[0]-transX, target.size[1]-transY)) input = ToTensor()(input) input_orig = ToTensor()(input_orig) if (self.enc): target = Resize(int(self.height/8), Image.NEAREST)(target) target = ToLabel()(target) target_orig = ToLabel()(target_orig) target = Relabel(255, 1)(target) target_orig = Relabel(255, 1)(target_orig) return input, target, input_orig, target_orig
def __call__(self, input, target): # do something to both images input = cv2.resize(input, self.size, interpolation=cv2.INTER_LINEAR) target = cv2.resize(target,self.size,interpolation=cv2.INTER_NEAREST) if self.rescale: input = (input/255.).astype(np.float32) # target = target/255. target = target.astype(np.float32) if(self.augment): # Random hflip hflip = random.random() if (hflip < 0.5): input = cv2.flip(input,1) target = cv2.flip(target, 1) #Random translation 0-2 pixels (fill rest with padding # transX = random.randint(-2, 2) # transY = random.randint(-2, 2) # # input = ImageOps.expand(input, border=(transX,transY,0,0), fill=0) # target = ImageOps.expand(target, border=(transX,transY,0,0), fill=255) #pad label filling with 255 # input = input.crop((0, 0, input.size[0]-transX, input.size[1]-transY)) # target = target.crop((0, 0, target.size[0]-transX, target.size[1]-transY)) input = ToTensor()(input) target = ToLabel()(target) target = Relabel(255, 3)(target) return input, target
def __call__(self, input, target): # do something to both images input = Resize(self.height, Image.BILINEAR)(input) target = Resize(self.height, Image.NEAREST)(target) if(self.augment): # Random hflip hflip = random.random() if (hflip < 0.5): input = input.transpose(Image.FLIP_LEFT_RIGHT) target = target.transpose(Image.FLIP_LEFT_RIGHT) #Random translation 0-2 pixels (fill rest with padding transX = random.randint(-2, 2) transY = random.randint(-2, 2) input = ImageOps.expand(input, border=(transX,transY,0,0), fill=0) target = ImageOps.expand(target, border=(transX,transY,0,0), fill=255) #pad label filling with 255 input = input.crop((0, 0, input.size[0]-transX, input.size[1]-transY)) target = target.crop((0, 0, target.size[0]-transX, target.size[1]-transY)) #TODO future: additional augments #CenterCrop(256) #Normalize([.485, .456, .406], [.229, .224, .225]), input = ToTensor()(input) if (self.enc): target = Resize(int(self.height/8), Image.NEAREST)(target) target = ToLabel()(target) target = Relabel(255, 19)(target) return input, target
def __call__(self, input, tinput, target): input = Resize(self.height, Image.BILINEAR)(input) tinput = Resize(self.height, Image.BILINEAR)(tinput) target = Resize(self.height, Image.NEAREST)(target) input = ToTensor()(input) tinput = ToTensor()(tinput) target = ToLabel()(target) target = Relabel(255, 19)(target) return input, tinput, target
def __call__(self, input, gray, target): # do something to both images if self.height != 8.1: input = Resize(self.height, Image.BILINEAR)(input) gray = Resize(self.height, Image.BILINEAR)(gray) target = Resize(self.height, Image.NEAREST)(target) # === Data Augmentation === # if (self.dataAugment): # 1. Random horizenal flip hflip = random.random() if (hflip < 0.5): input = input.transpose(Image.FLIP_LEFT_RIGHT) gray = gray.transpose(Image.FLIP_LEFT_RIGHT) target = target.transpose(Image.FLIP_LEFT_RIGHT) # 2. Random translation 0-2 pixels (fill rest with padding transX = random.randint(-2, 2) transY = random.randint(-2, 2) input = ImageOps.expand(input, border=(transX, transY, 0, 0), fill=0) gray = ImageOps.expand(gray, border=(transX, transY, 0, 0), fill=0) target = ImageOps.expand(target, border=(transX, transY, 0, 0), fill=255) #pad label filling with 255 input = input.crop( (0, 0, input.size[0] - transX, input.size[1] - transY)) gray = gray.crop( (0, 0, gray.size[0] - transX, gray.size[1] - transY)) target = target.crop( (0, 0, target.size[0] - transX, target.size[1] - transY)) input = ToTensor()(input) gray = ToTensor()(gray) if (self.encoderOnly): target = Resize(int(self.height / 8), Image.NEAREST)(target) target = ToLabel()(target) target = Relabel(255, 19)(target) # ignored label 255 -> 19 input = torch.cat((input, gray), 0) return input, target
def __call__(self, input, target): # do something to both images input = cv2.resize(input, (self.weight, self.height), interpolation=cv2.INTER_LINEAR) target = cv2.resize(target, (self.weight, self.height), interpolation=cv2.INTER_NEAREST) if self.rescale: input = input / 255. if (self.augment): # Random hflip hflip = random.random() if (hflip < 0.5): input = cv2.flip(input, 1) target = cv2.flip(target, 1) input = ToTensor()(input) target = torch.from_numpy(np.array(target)).long().unsqueeze(0) # target = Relabel(0, 1)(target) #障碍 # target = Relabel(35, 2)(target) #树 # target = Relabel(96, 2)(target) #树 # target = Relabel(100, 4)(target) #天 # target = Relabel(150, 3)(target) #草地 # target = Relabel(170, 6)(target) #沙地 # target = Relabel(255, 5)(target) # void # 0->可通行,1->不可通行,2,3->待判断,4->天空 target = Relabel(0, 0)(target) #障碍 target = Relabel(35, 0)(target) #树 target = Relabel(96, 0)(target) #树 target = Relabel(99, 4)(target) #天 target = Relabel(149, 2)(target) #草地 target = Relabel(170, 3)(target) #沙地 2 target = Relabel(255, 0)(target) # void return input, target
import visdom NUM_CHANNELS = 3 NUM_CLASSES = 20 image_transform = ToPILImage() input_transform_cityscapes = Compose([ Resize((512, 1024), Image.BILINEAR), ToTensor(), #Normalize([.485, .456, .406], [.229, .224, .225]), ]) target_transform_cityscapes = Compose([ Resize((512, 1024), Image.NEAREST), ToLabel(), Relabel(255, 19), #ignore label to 19 ]) cityscapes_trainIds2labelIds = Compose([ Relabel(19, 255), Relabel(18, 33), Relabel(17, 32), Relabel(16, 31), Relabel(15, 28), Relabel(14, 27), Relabel(13, 26), Relabel(12, 25), Relabel(11, 24), Relabel(10, 23), Relabel(9, 22), Relabel(8, 21),
from erfnet import ERFNet from transform import Relabel, ToLabel, Colorize from iouEval import iouEval, getColorEntry NUM_CHANNELS = 3 NUM_CLASSES = 20 image_transform = ToPILImage() input_transform_cityscapes = Compose([ Resize(512, Image.BILINEAR), ToTensor(), ]) target_transform_cityscapes = Compose([ Resize(512, Image.NEAREST), ToLabel(), Relabel(255, 19), #ignore label to 19 ]) def main(args): modelpath = args.loadDir + args.loadModel weightspath = args.loadDir + args.loadWeights print("Loading model: " + modelpath) print("Loading weights: " + weightspath) model = ERFNet(NUM_CLASSES) model = torch.nn.DataParallel(model) if (not args.cpu):
NUM_CHANNELS = 3 NUM_CLASSES = 20 #pascal=22, cityscapes=20 color_transform = Colorize(NUM_CLASSES) image_transform = ToPILImage() input_transform = Compose([ CenterCrop(256), ToTensor(), Normalize([.485, .456, .406], [.229, .224, .225]), ]) target_transform = Compose([ CenterCrop(256), ToLabel(), Relabel(255, 21), ]) #Augmentations - different function implemented to perform random augments on both image and target class MyCoTransform(object): def __init__(self, enc, augment=True, height=512): self.enc = enc self.augment = augment self.height = height pass def __call__(self, input, target): # do something to both images input = Resize(self.height, Image.BILINEAR)(input) target = Resize(self.height, Image.NEAREST)(target)
from erfnet import ERFNet from transform import Relabel, ToLabel, Colorize NUM_CHANNELS = 3 NUM_CLASSES = 2 image_transform = ToPILImage() input_transform_MAV = Compose([ Resize(512), ToTensor(), #Normalize([.485, .456, .406], [.229, .224, .225]), ]) target_transform_MAV = Compose([ Resize(512), ToLabel(), Relabel(101, 0), Relabel(201, 0), #ignore label to 19 ]) MAV_trainIds2labelIds = Compose([ Relabel(1, 1), Relabel(0, 0), ToPILImage(), Resize(1024, Image.NEAREST), ]) def main(args): modelpath = args.loadDir + args.loadModel weightspath = args.loadDir + args.loadWeights
from transform import Relabel, ToLabel, Colorize import visdom NUM_CLASSES = 11 image_transform = ToPILImage() input_transform_geoMat = Compose([ Resize((104, 104), Image.BILINEAR), ToTensor(), #Normalize([.485, .456, .406], [.229, .224, .225]), ]) target_transform_geoMat = Compose([ Resize((104, 104), Image.NEAREST), ToLabel(), Relabel(0, 0), Relabel(25, 1), Relabel(50, 2), Relabel(75, 3), Relabel(100, 4), Relabel(125, 5), Relabel(150, 6), Relabel(175, 7), Relabel(200, 8), Relabel(225, 9), Relabel(250, 10), Relabel(255, 10), ]) def main(args):
import visdom NUM_CHANNELS = 3 NUM_CLASSES = 4 image_transform = ToPILImage() input_transform_cityscapes = Compose([ Resize((512, 1024), Image.BILINEAR), ToTensor(), #Normalize([.485, .456, .406], [.229, .224, .225]), ]) target_transform_cityscapes = Compose([ Resize((512, 1024), Image.NEAREST), ToLabel(), Relabel(0, 1), Relabel(35, 2), Relabel(96, 2), Relabel(100, 4), Relabel(150, 3), Relabel(170, 6), Relabel(255, 5), ]) def main(args): modelpath = args.loadDir + args.loadModel #weightspath = args.loadDir + args.loadWeights #TODO weightspath = "../save/feriburgForest_3/model_best.pth" print("Loading model: " + modelpath)
NUM_CHANNELS = 3 NUM_CLASSES = 1 # 20 image_transform = ToPILImage() input_transform_lot = Compose([ Resize((512, 1024), Image.BILINEAR), ToTensor(), #Normalize([.485, .456, .406], [.229, .224, .225]), ]) label_transform_lot = Compose([ Resize((512, 1024), Image.NEAREST), ToLabel(), ]) pred_transform_lot = Compose([ # Resize((512,1024),Image.NEAREST), Relabel(1, 255), ToPILImage(), Resize((480, 640), Image.NEAREST), ]) def main(args): modelpath = args.loadDir + args.loadModel weightspath = args.loadDir + args.loadWeights print("Loading model: " + modelpath) print("Loading weights: " + weightspath) #Import ERFNet model from the folder #Net = importlib.import_module(modelpath.replace("/", "."), "ERFNet")
from dataset import camvid from transform import Relabel, ToLabel, Colorize from iouEval import iouEval, getColorEntry from FSFNet_Camvid import FSFNet NUM_CHANNELS = 3 NUM_CLASSES = 12 image_transform = ToPILImage() input_transform_camvid = Compose([ ToTensor(), ]) target_transform_camvid = Compose([ ToLabel(), Relabel(255, 11), #ignore label to 19 ]) def main(args): modelpath = args.loadDir + args.loadModel weightspath = args.loadDir + args.loadWeights print("Loading model: " + modelpath) print("Loading weights: " + weightspath) model = FSFNet(NUM_CLASSES) #model = torch.nn.DataParallel(model) if (not args.cpu):
def __call__(self, input, target): # do something to both images input = Resize(self.height, Image.BILINEAR)(input) target = Resize(self.height, Image.NEAREST)(target) if(self.augment): # Random hflip hflip = random.random() if (hflip < 0.5): input = input.transpose(Image.FLIP_LEFT_RIGHT) target = target.transpose(Image.FLIP_LEFT_RIGHT) #Random translation 0-2 pixels (fill rest with padding transX = random.randint(-2, 2) transY = random.randint(-2, 2) input = ImageOps.expand(input, border=(transX,transY,0,0), fill=0) target = ImageOps.expand(target, border=(transX,transY,0,0), fill=255) #pad label filling with 255 input = input.crop((0, 0, input.size[0]-transX, input.size[1]-transY)) target = target.crop((0, 0, target.size[0]-transX, target.size[1]-transY)) input = ToTensor()(input) target = ToLabel()(target) #target = Relabel(255, 19)(target) #TODO target = Relabel(0, 0)(target) target = Relabel(25, 1)(target) target = Relabel(50, 2)(target) target = Relabel(75, 3)(target) target = Relabel(100, 4)(target) target = Relabel(125, 5)(target) target = Relabel(150, 6)(target) target = Relabel(175, 7)(target) target = Relabel(200, 8)(target) target = Relabel(225, 9)(target) target = Relabel(250, 10)(target) target = Relabel(255, 10)(target) return input, target
from erfnet import ERFNet from transform import Relabel, ToLabel, Colorize from iouEval import iouEval, getColorEntry NUM_CHANNELS = 3 NUM_CLASSES = 2 image_transform = ToPILImage() input_transform_MAV = Compose([ Resize(512, Image.BILINEAR), ToTensor(), ]) target_transform_MAV = Compose([ Resize(512, Image.NEAREST), ToLabel(), Relabel(101, 0), Relabel(201, 0), #ignore label to 19 ]) def main(args): modelpath = args.loadDir + args.loadModel weightspath = args.loadDir + args.loadWeights print ("Loading model: " + modelpath) print ("Loading weights: " + weightspath) model = ERFNet(NUM_CLASSES) #model = torch.nn.DataParallel(model) if (not args.cpu):