Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dataset #9

Merged
merged 6 commits into from
May 18, 2022
Merged

Feature/dataset #9

merged 6 commits into from
May 18, 2022

Conversation

JoonHyun814
Copy link
Contributor

close #7

change COCO

'''

def __init__(self, annotation_file=None):
    """
    Constructor of Microsoft COCO helper class for reading and visualizing annotations.
    :param annotation_file (str): location of annotation file
    :param image_folder (str): location to the folder that hosts images.
    :return:
    """
    # load dataset
    self.dataset,self.anns,self.cats,self.imgs = dict(),dict(),dict(),dict()
    self.imgToAnns, self.catToImgs = defaultdict(list), defaultdict(list)
    if type(annotation_file) == str:
        print('loading annotations into memory...')
        tic = time.time()
        with open(annotation_file, 'r') as f:
            dataset = json.load(f)
        assert type(dataset)==dict, 'annotation file format {} not supported'.format(type(dataset))
        print('Done (t={:0.2f}s)'.format(time.time()- tic))
        self.dataset = dataset
        self.createIndex()

    elif type(annotation_file) == dict:
        tic = time.time()
        self.dataset = annotation_file
        self.createIndex()

def createIndex(self):
    # create index
    # print('creating index...')
    anns, cats, imgs = {}, {}, {}
    imgToAnns,catToImgs = defaultdict(list),defaultdict(list)
    if 'annotations' in self.dataset:
        for ann in self.dataset['annotations']:
            imgToAnns[ann['image_id']].append(ann)
            anns[ann['id']] = ann

    if 'images' in self.dataset:
        for img in self.dataset['images']:
            imgs[img['id']] = img

    if 'categories' in self.dataset:
        for cat in self.dataset['categories']:
            cats[cat['id']] = cat

    if 'annotations' in self.dataset and 'categories' in self.dataset:
        for ann in self.dataset['annotations']:
            catToImgs[ann['category_id']].append(ann['image_id'])

    # print('index created!')

    # create class members
    self.anns = anns
    self.imgToAnns = imgToAnns
    self.catToImgs = catToImgs
    self.imgs = imgs
    self.cats = cats

'''

@JoonHyun814 JoonHyun814 linked an issue May 18, 2022 that may be closed by this pull request
@JoonHyun814 JoonHyun814 merged commit 95d22d9 into develop May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dataset
2 participants