How do i get MeanIoU metrics from SemSegEvaluator using COCO Json as input #4755
Unanswered
anirbankonar123
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
All, I am using the InstanceSegmentation using R50_FPN Arch etc for long time, without any issues. Was using the COCOEvaluator. Now I want to compare Detectron2 model perf with Tensorflow and so I need MeanIoU score. What I noticed is SemSegEvaluator gives this. Was trying to use this, but I get error - key "sem_seg_file_name" missing. After checking I found this key is not there in COCO Json. So I was trying to shift to DatasetCatalog.register like this :
DatasetCatalog.register("coco_train", lambda d=d: get_corrosion_dicts("/content/Blisters/","/content/Train_Coco.json"))
Since my input is a COCO Json (my annotation tool provides that), I wrote a function to return records of dicts like this:
def get_corrosion_dicts(img_dir,json_file):
dataset_dicts = []
f = open(json_file)
data = json.load(f)
for i in range(len(data['images'])):
record = {}
annotations=[]
filename = os.path.join(img_dir+data['images'][i]["file_name"])
record["file_name"] = filename
record["sem_seg_file_name"] = filename
record["sem_seg"] = "True"
record["image_id"] = data['images'][i]["id"]
record["height"] = data['images'][i]["height"]
record["width"] = data['images'][i]["width"]
I checked the sample record format of balloon dataset provided by detectron tutorial and the one created by me on my dataset. They are exactly same.
But still when visualising the annotations I am getting error messages.
dataset_dicts = get_corrosion_dicts("/content/Blisters/","/content/Train_Coco.json")
for d in random.sample(dataset_dicts, 3):
img = cv2.imread(d["file_name"])
visualizer = Visualizer(img[:, :, ::-1], metadata=coco_metadata, scale=0.5)
out = visualizer.draw_dataset_dict(d)
cv2_imshow(out.get_image()[:, :, ::-1])
I get error
/usr/local/lib/python3.8/dist-packages/detectron2/utils/visualizer.py in (.0)
242 if classes is not None:
243 if class_names is not None and len(class_names) > 0:
--> 244 labels = [class_names[i] for i in classes]
245 else:
246 labels = [str(i) for i in classes]
IndexError: list index out of range
Tried Visualizer.draw_sem_seg(d) also, that is also giving some strange error
Can someone help how I can use SemSegEvaluator using a COCO Annotation JSON and thereby get MeanIoU score. My main need is to get MeanIoU score , I already got metrics like AP, AP50.
Here's the link to my colab file as well : https://colab.research.google.com/drive/1gbSuwvct8gyBNVMBebgSsEeYRT20Qe7Q?usp=sharing
Beta Was this translation helpful? Give feedback.
All reactions