def get_all_image_data(data_dir=None, as_dict=False):
    """
    Get Image ids from start_index to end_index.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    dataFile = os.path.join(data_dir, 'image_data.json')
    data = json.load(open(dataFile))
    if not as_dict:
        return [utils.parse_image_data(image) for image in data]

    return {
        image['id'] if 'id' in image else image['image_id']: utils.parse_image_data(image) for image in data
    }
Пример #2
0
    def createIndex(self):
        # create index
        print('creating index...')

        objects = set()
        imgs = {}
        imgToAnns = defaultdict(list)
        for data in self.image_data:
            image = parse_image_data(data)
            imgs[image.id] = image
        for data in self.object_data:
            objs = parse_object_data(data['objects'])
            img_id = data["image_id"]
            if objs is None:
                try:
                    del imgs[img_id]
                except:
                    pass
                continue
            imgToAnns[img_id] = objs
            for obj in objs:
                objects.add(obj.names)

        print('index created!')

        # create class members
        self.imgToAnns = imgToAnns
        self.imgs = imgs
        self.objects = dict(zip(range(len(objects)), list(objects)))
        self.object_to_id = dict(zip(list(objects), range(len(objects))))
Пример #3
0
def get_image_data(id=61512):
    """
    Get data about an image.
    """
    data = utils.retrieve_data('/api/v0/images/' + str(id))
    if 'detail' in data and data['detail'] == 'Not found.':
        return None
    image = utils.parse_image_data(data)
    return image
Пример #4
0
def get_all_image_data(data_dir=None):
    """
    Get Image ids from start_index to end_index.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    dataFile = os.path.join(data_dir, 'image_data.json')
    data = json.load(open(dataFile))
    return [utils.parse_image_data(image) for image in data]
Пример #5
0
def get_image_data(id=61512):
    """
    Get data about an image.
    """
    data = utils.retrieve_data("/api/v0/images/" + str(id))
    if "detail" in data and data["detail"] == "Not found.":
        return None
    image = utils.parse_image_data(data)
    return image
Пример #6
0
def get_image_data(id=61512):
    """
    Get data about an image.
    """
    data = utils.retrieve_data('/api/v0/images/' + str(id))
    if 'detail' in data and data['detail'] == 'Not found.':
        return None
    image = utils.parse_image_data(data)
    return image
Пример #7
0
def get_all_image_data(data_dir=None):
    """
    Get Image ids from start_index to end_index.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    dataFile = os.path.join(data_dir, 'image_data.json')
    data = json.load(open(dataFile))
    return [utils.parse_image_data(image) for image in data]
Пример #8
0
def get_all_image_data(data_dir=None):
    """
    Get Image ids from start_index to end_index.
    """
    if data_dir is None:
        data_dir = utils.get_data_dir()
    # In case when exact filename is passed
    if os.path.isdir(data_dir):
        dataFile = os.path.join(data_dir, 'image_data.json')
    else:
        dataFile = data_dir
    data = json.load(open(dataFile))
    return [utils.parse_image_data(image) for image in data]