qqlu / Amodal-Instance-Segmentation-through-KINS-Dataset

Amodal-Instance-Segmentation-through-KINS-Dataset
133 stars 19 forks source link

questions about annotation #11

Closed YoruCathy closed 4 years ago

YoruCathy commented 4 years ago

I found in the training set there are 7481 images, but in your annotation json file for training set, the max image id is 7475, does it mean that the last several images are not annotated , or did I make some mistakes? thx

qqlu commented 4 years ago

You are right. We only annotated 7475 images. Another 6 images are in the wrong annotation so we delete them.

YoruCathy commented 4 years ago

thanks! Can I ask for a code sample to visualize the inmodal_bbox? I tried to visualize inmodal_bbox in json annotation but found it wrong I think there must be some problem in my code but I don't know how to fix it (The first picture may be right I guess by the way, the bbox format is the same as coco dataset, namely x,y for upper left ,and w,h for weight and height, isn't it? Here is my code

import cv2 as cv
import json
import numpy as np
from PIL import Image
import os
from tqdm import tqdm
from time import time
from pycocotools import mask as maskUtils
import cv2
root = "/home/amodal/data/KINS"

def draw_bbox(img_id, annos):

    image_path = "/home/amodal/KINS/train2017/"

    if img_id < 10:
        img_path = image_path+'00000000000'+str(img_id) + '.jpg'
    elif img_id < 100:
        img_path = image_path+'0000000000'+str(img_id) + '.jpg'
    # return
    elif img_id < 1000:
        img_path = image_path+'000000000'+str(img_id) + '.jpg'
    else:
        img_path = image_path+'00000000'+str(img_id) + '.jpg'
    img = cv2.imread(img_path)
    for anno in annos:
        # print(anno)
        x, y, w, h = anno
        xmin_data = x
        ymin_data = y
        xmax_data = w+x
        ymax_data = h+y
        cv2.rectangle(img, (int(float(xmin_data)), int(float(ymin_data))),
                      (int(float(xmax_data)), int(float(ymax_data))), (55, 255, 155), 1)
    cv2.imwrite(
        "/home/amodal/data/KINS/Visualization/{}.jpg".format(str(img_id)), img)

if __name__ == "__main__":
    print('Loading', os.path.join(root, 'annotations', 'instances_train.json'))
    with open(os.path.join(root, 'annotations', 'instances_train.json')) as coco_json:
        data = json.load(coco_json)
        annotation_dict = {}
        for anno in data['annotations']:
            img_id = anno['image_id']
            try:
                annotation_dict[img_id].append(anno['inmodal_bbox'])
            except KeyError:
                annotation_dict[img_id] = [anno['inmodal_bbox']]

        for im_id, annos in tqdm(annotation_dict.items()):
            draw_bbox(im_id, annos)
qqlu commented 4 years ago

You can refer to kitti_vis_without_cocoapi.py for inmodal mask visualization. It is the same as inmodal box.

Perhaps you do not match the img_id to image name right. The image id does not equal to the image name.

YoruCathy commented 4 years ago

oh that's the case thank you very much