Untitled

mail@pastecode.io avatar
unknown
python
a year ago
783 B
3
Indexable
Never
img_info = {
    "id": id,
    "file_name": "None",
}

#iteracija preko vseh predicted boxov:
for box in range(len(boxes_xywh)):
    anno = {
        "id": anno_id, #samo indeks, prva anotacija je 0 potem vsaka +1
        "image_id": id,
        "area": int(area, #izracuna se povrsina vsakega bboxa
        "bbox": [int(box[0].item()), int(box[1]), int(box[2]), int(box[3])], #pomembno FORMAT: (X,Y WIDTH; HEIGHT)
        "category_id": 1,
        "score": float(scores[i].item()), # Nek scoring vrne že SAM, najbolje da se uporabi kar tisto (score ima vsak box svoj!)
    }
    anno_id += 1
    predictions["annotations"].append(anno)
predictions["images"].append(img_info)



with open("predictions_SAM" + "_" + split + ".json", "w") as handle:
    json.dump(predictions, handle)