[1]. Yuxin Wu and Kaiming He. Group Normalization. In ECCV,
2018.
[2]. Sergey Ioffe and Christian Szegedy. Batch Normalization:
Accelerating Deep Network Training by Reducing Internal Covariate Shift.
In ICML, 2015.
[3]. Lei Jimmy Ba, Jamie Ryan Kiros, and Geoffrey E. Hinton.
Layer normalization. arXiv:1607.06450, 2016.
[4]. Dmitry Ulyanov, Andrea Vedaldi and Victor S. Lempitsky.
Instance normalization: The missing ingredient for fast stylization.
arXiv:1607.08022, 2016.
import cv2 import os.path as osp import numpy as np
classCOCODataset(): """ COCO style dataset """ def__init__( self, data_dir=None, json_file="coco_train.json", name="train", area_threshold=-1, ): """ Dataset initialization. Annotation data are read into memory by COCO API. Args: data_dir (str): dataset root directory json_file (str): annotation json file name name (str): data name (e.g. 'train' or 'val') area_threshold(int): area threshold for object """ self.area_thres = area_threshold self.data_dir = data_dir self.json_file = json_file self.imgs = None self.name = name self.init()
definit(self): from pycocotools.coco import COCO self.coco = COCO(osp.join(self.data_dir, "annotations", self.json_file))
# NOTE: do not use self.coco.getImgIds() self.ids = list(self.coco.imgToAnns.keys()) self.class_ids = sorted(self.coco.getCatIds()) self.cats = self.coco.loadCats(self.coco.getCatIds()) self._classes = tuple([c["name"] for c in self.cats])
self.annotations = self._load_coco_annotations()
def__getitem__(self, index): # NOTE: in case empty label max_iter = 5 for _ inrange(max_iter): res, img_info, _ = self.annotations[index] if res.size > 0: break index = np.random.randint(0, self.__len__()) id_ = self.ids[index]
# labels with warnings.catch_warnings(): # ignore the warning information when the file is empty warnings.simplefilter("ignore") labels = np.loadtxt(file)
targets = np.zeros((len(labels), 5)) if labels.size == 0: continue if labels.ndim == 1: labels = labels[None] # part2: annotations information for label in labels: target_info = { "segmentation" : [], "category_id" : int(label[0]), "image_id" : id, "id" : ann_id, "area" : round((label[3]-label[1])*(label[4]-label[2]), 6), "bbox" : xyxy2xywh(label, (H,W)), "iscrowd" : 0, } ann_id += 1 label_json["annotations"].append(target_info) # save the labels in a json file withopen(json_path, 'w') as json_f: json.dump(label_json, json_f)
polygon = [] for point in contour: polygon.extend( [point[0][0], point[0][1]] ) # get area area = cv2.contourArea(contour) # get bounding box bbox = cv2.boundingRect(contour)