Loading configs/coco_train.sh 0 → 100644 +16 −0 Original line number Diff line number Diff line #!/usr/bin/env bash PYTHON=${PYTHON:-"python"} GPUS=$1 $PYTHON -m torch.distributed.launch --nproc_per_node=$GPUS \ --master_port=$((RANDOM + 10000)) --use_env $(dirname "$0")/../train.py \ --num-classes 81 \ --trains "coco_2017_train" \ --tests "coco_2017_val" \ --lr-steps 8 11 \ --epochs 12 \ --batch-size 2 \ --work-dir "works_dir/coco" \ --lr 1e-5 ${@:2} No newline at end of file data/__init__.py +20 −6 Original line number Diff line number Diff line from torch.utils.data.dataloader import default_collate def collate_fn(batch): # img, img_meta, target """ Args: batch: list of tuple, 0 is images, 1 is img_meta, 2 is target Returns: """ batch = list(zip(*batch)) imgs = default_collate(batch[0]) return imgs, batch[1], batch[2] No newline at end of file imgs = batch[0] img_metas = batch[1] targets = batch[2] if len(imgs) == 1: batched_imgs = imgs[0].unsqueeze_(0) else: max_size = tuple(max(s) for s in zip(*[img.shape for img in imgs])) batch_shape = (len(imgs),) + max_size batched_imgs = imgs[0].new_full(batch_shape, 0.0) for img, pad_img in zip(imgs, batched_imgs): pad_img[..., :img.shape[-2], :img.shape[-1]].copy_(img) return batched_imgs.contiguous(), img_metas, targets data/build.py +10 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,16 @@ DATASETS = { 'root': foggy_cityscapes_images_dir, 'train': False, }, "coco_2017_train": { "ann_file": "/data7/lufficc/coco/annotations/instances_train2017.json", "root": "/data7/lufficc/coco/train2017", 'train': True, }, "coco_2017_val": { "ann_file": "/data7/lufficc/coco/annotations/instances_val2017.json", "root": "/data7/lufficc/coco/val2017", 'train': False, }, } Loading data/coco.py 0 → 100644 +70 −0 Original line number Diff line number Diff line from .dataset import COCODataset # normalizer = { # 'name': 'normalize', # 'mean': [102.9801, 115.9465, 122.7717], # 'std': [1, 1, 1], # 'to_bgr': True, # } normalizer = { 'name': 'normalize', 'mean': [0.5, 0.5, 0.5], 'std': [0.5, 0.5, 0.5], 'to_01': True, } train_transforms = [ { 'name': 'random_flip' }, { 'name': 'resize', 'min_size': (800,), 'max_size': 1333, }, { 'name': 'pad', 'size_divisor': 16, }, normalizer, { 'name': 'collect' } ] test_transforms = [ { 'name': 'resize', 'min_size': (800,), 'max_size': 1333, }, { 'name': 'pad', 'size_divisor': 16, }, normalizer, { 'name': 'collect' } ] class MSCOCODataset(COCODataset): CLASSES = ('__background__', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic_light', 'fire_hydrant', 'stop_sign', 'parking_meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports_ball', 'kite', 'baseball_bat', 'baseball_glove', 'skateboard', 'surfboard', 'tennis_racket', 'bottle', 'wine_glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot_dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted_plant', 'bed', 'dining_table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell_phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy_bear', 'hair_drier', 'toothbrush') def __init__(self, ann_file, root, train=True): transforms = train_transforms if train else test_transforms super().__init__(ann_file, root, transforms=transforms, remove_empty=train) data/transforms.py +23 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,28 @@ class normalize(object): return results class pad(object): def __init__(self, size_divisor=0, pad_val=0): self.size_divisor = size_divisor self.pad_val = pad_val def __call__(self, results): img = results['img'] pad_shape = img.shape if self.size_divisor > 0: pad_shape = list(pad_shape) pad_shape[0] = int(np.ceil(img.shape[0] / self.size_divisor)) * self.size_divisor pad_shape[1] = int(np.ceil(img.shape[1] / self.size_divisor)) * self.size_divisor pad_shape = tuple(pad_shape) pad = np.full(pad_shape, self.pad_val, dtype=img.dtype) pad[:img.shape[0], :img.shape[1], ...] = img else: pad = img results['img'] = pad results['pad_shape'] = pad_shape return results def de_normalize(image, img_meta): assert 'img_norm' in img_meta image = image.detach().cpu().permute(1, 2, 0).numpy() Loading Loading @@ -150,6 +172,7 @@ TRANSFORMS = { 'resize': resize, 'normalize': normalize, 'collect': collect, 'pad': pad, } Loading Loading
configs/coco_train.sh 0 → 100644 +16 −0 Original line number Diff line number Diff line #!/usr/bin/env bash PYTHON=${PYTHON:-"python"} GPUS=$1 $PYTHON -m torch.distributed.launch --nproc_per_node=$GPUS \ --master_port=$((RANDOM + 10000)) --use_env $(dirname "$0")/../train.py \ --num-classes 81 \ --trains "coco_2017_train" \ --tests "coco_2017_val" \ --lr-steps 8 11 \ --epochs 12 \ --batch-size 2 \ --work-dir "works_dir/coco" \ --lr 1e-5 ${@:2} No newline at end of file
data/__init__.py +20 −6 Original line number Diff line number Diff line from torch.utils.data.dataloader import default_collate def collate_fn(batch): # img, img_meta, target """ Args: batch: list of tuple, 0 is images, 1 is img_meta, 2 is target Returns: """ batch = list(zip(*batch)) imgs = default_collate(batch[0]) return imgs, batch[1], batch[2] No newline at end of file imgs = batch[0] img_metas = batch[1] targets = batch[2] if len(imgs) == 1: batched_imgs = imgs[0].unsqueeze_(0) else: max_size = tuple(max(s) for s in zip(*[img.shape for img in imgs])) batch_shape = (len(imgs),) + max_size batched_imgs = imgs[0].new_full(batch_shape, 0.0) for img, pad_img in zip(imgs, batched_imgs): pad_img[..., :img.shape[-2], :img.shape[-1]].copy_(img) return batched_imgs.contiguous(), img_metas, targets
data/build.py +10 −1 Original line number Diff line number Diff line Loading @@ -43,7 +43,16 @@ DATASETS = { 'root': foggy_cityscapes_images_dir, 'train': False, }, "coco_2017_train": { "ann_file": "/data7/lufficc/coco/annotations/instances_train2017.json", "root": "/data7/lufficc/coco/train2017", 'train': True, }, "coco_2017_val": { "ann_file": "/data7/lufficc/coco/annotations/instances_val2017.json", "root": "/data7/lufficc/coco/val2017", 'train': False, }, } Loading
data/coco.py 0 → 100644 +70 −0 Original line number Diff line number Diff line from .dataset import COCODataset # normalizer = { # 'name': 'normalize', # 'mean': [102.9801, 115.9465, 122.7717], # 'std': [1, 1, 1], # 'to_bgr': True, # } normalizer = { 'name': 'normalize', 'mean': [0.5, 0.5, 0.5], 'std': [0.5, 0.5, 0.5], 'to_01': True, } train_transforms = [ { 'name': 'random_flip' }, { 'name': 'resize', 'min_size': (800,), 'max_size': 1333, }, { 'name': 'pad', 'size_divisor': 16, }, normalizer, { 'name': 'collect' } ] test_transforms = [ { 'name': 'resize', 'min_size': (800,), 'max_size': 1333, }, { 'name': 'pad', 'size_divisor': 16, }, normalizer, { 'name': 'collect' } ] class MSCOCODataset(COCODataset): CLASSES = ('__background__', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic_light', 'fire_hydrant', 'stop_sign', 'parking_meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports_ball', 'kite', 'baseball_bat', 'baseball_glove', 'skateboard', 'surfboard', 'tennis_racket', 'bottle', 'wine_glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot_dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted_plant', 'bed', 'dining_table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell_phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy_bear', 'hair_drier', 'toothbrush') def __init__(self, ann_file, root, train=True): transforms = train_transforms if train else test_transforms super().__init__(ann_file, root, transforms=transforms, remove_empty=train)
data/transforms.py +23 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,28 @@ class normalize(object): return results class pad(object): def __init__(self, size_divisor=0, pad_val=0): self.size_divisor = size_divisor self.pad_val = pad_val def __call__(self, results): img = results['img'] pad_shape = img.shape if self.size_divisor > 0: pad_shape = list(pad_shape) pad_shape[0] = int(np.ceil(img.shape[0] / self.size_divisor)) * self.size_divisor pad_shape[1] = int(np.ceil(img.shape[1] / self.size_divisor)) * self.size_divisor pad_shape = tuple(pad_shape) pad = np.full(pad_shape, self.pad_val, dtype=img.dtype) pad[:img.shape[0], :img.shape[1], ...] = img else: pad = img results['img'] = pad results['pad_shape'] = pad_shape return results def de_normalize(image, img_meta): assert 'img_norm' in img_meta image = image.detach().cpu().permute(1, 2, 0).numpy() Loading Loading @@ -150,6 +172,7 @@ TRANSFORMS = { 'resize': resize, 'normalize': normalize, 'collect': collect, 'pad': pad, } Loading