imantics icon indicating copy to clipboard operation
imantics copied to clipboard

dataset.add() method do not work as expect

Open WangHuancheng opened this issue 4 years ago • 0 comments

Hi, it's really great to find the project, I have being searching this for several days and almost give up. I sincerely thank you developing this awesome tool, but i meet with a problem using it to build my dataset.

below is my code, basically i loop twice and for each time I read a image and mask, then create annoation, then use Dataset.add method adding them to the dataset

data = imantics.Dataset(name='allen_342')`
for i in tqdm(range(2)):`
    image = imantics.Image.from_path('/mydir/image_{}.png'.format(i))
    mask_array =cv2.imread(/mydir/mask_{}.png'.format(i),cv2.IMREAD_GRAYSCALE)
    mask=imantics.Mask(mask_array)
    ann=(imantics.Annotation.from_mask(mask,image,imantics.Category('cell')))
    data.add(image)
    data.add(ann)
    out = data.coco()

the problem is , i got very strange output which is for i==0

{'annotations': [{'area': 2915,
                  'bbox': (201, 33, 271, 444),
                  'category_id': 0,
                  'color': '#214596',
                  'height': 512,
                  'id': 1,
                  'image_id': 0,
                  'isbbox': False,
                  'iscrowd': 0,
                  'metadata': {},
                  'width': 512}],
 'categories': [{'color': '#c81940',
                 'id': 0,
                 'metadata': {},
                 'name': 'cell',
                 'supercategory': None}],
 'images': [{'coco_url': None,
             'date_captured': None,
             'fickr_url': None,
             'file_name': 'image_951980471.png',
             'height': 512,
             'id': 0,
             'license': None,
             'metadata': {},
             'path': '/home/seeker/Swin-Transformer-Object-Detection/image/image_951980471.png',
             'width': 512}],
 'info': {}}

for i==1

{'annotations': [{'area': 2915,
                  'bbox': (201, 33, 271, 444),
                  'category_id': 0,
                  'color': '#214596',
                  'height': 512,
                  'id': 1,
                  'image_id': 0,
                  'isbbox': False,
                  'iscrowd': 0,
                  'metadata': {},
                  'width': 512},
                 {'area': 1583,
                  'bbox': (95, 52, 324, 446),
                  'category_id': 0,
                  'color': '#3d1ea0',
                  'height': 512,
                  'id': 2,
                  'image_id': 0,
                  'isbbox': False,
                  'iscrowd': 0,
                  'metadata': {},
                  'width': 512}],
 'categories': [{'color': '#c81940',
                 'id': 0,
                 'metadata': {},
                 'name': 'cell',
                 'supercategory': None}],
 'images': [{'coco_url': None,
             'date_captured': None,
             'fickr_url': None,
             'file_name': 'image_951980484.png',
             'height': 512,
             'id': 0,
             'license': None,
             'metadata': {},
             'path': '/home/seeker/Swin-Transformer-Object-Detection/image/image_951980484.png',
             'width': 512}],
 'info': {}}

allow me to point out the problems.

  1. The image do no add, there are still one image
  2. the annotations add, but there are only one annotation for each loop, the origin mask have multiple area for each image.
  3. the annotation['image_id'] and the images['id'] always 0, however, the file_name did change

I read about the docus, maybe the Dataset is not a "dataset" but a handle to iterator the image and annos? but even though this doesn't make sense anyway. For,example, the new add anno has the same image_id with the previous one.

How can I make ONE json file with images contains multiple object in each one for future train ? Thank you,

WangHuancheng avatar Jul 04 '21 11:07 WangHuancheng