83dc25dbc8b4ed98b4cc952e3cb35668e5a65490,coco_eval.py,,evaluate_coco,#Any#Any#Any#,11
Before Change
// write output
json.dump(results, open("{}_bbox_results.json".format(dataset.set_name), "w"), indent=4)
json.dump(image_ids, open("{}_processed_image_ids.json".format(dataset.set_name), "w"), indent=4)
// load results in COCO evaluation tool
coco_true = dataset.coco
After Change
model.eval()
with torch.no_grad():
// start collecting results
results = []
image_ids = []
for index in range(len(dataset)):
data = dataset[index]
scale = data["scale"]
// run network
scores, labels, boxes = model(data["img"].permute(2, 0, 1).cuda().float().unsqueeze(dim=0))
scores = scores.cpu()
labels = labels.cpu()
boxes = boxes.cpu()
// correct boxes for image scale
boxes /= scale
// change to (x, y, w, h) (MS COCO standard)
boxes[:, 2] -= boxes[:, 0]
boxes[:, 3] -= boxes[:, 1]
// compute predicted labels and scores
//for box, score, label in zip(boxes[0], scores[0], labels[0]):
for box_id in range(boxes.shape[0]):
score = float(scores[box_id])
label = int(labels[box_id])
box = boxes[box_id, :]
// scores are sorted, so we can break
if score < threshold:
break
// append detection for each positively labeled class
image_result = {
"image_id" : dataset.image_ids[index],
"category_id" : dataset.label_to_coco_label(label),
"score" : float(score),
"bbox" : box.tolist(),
}
// append detection to results
results.append(image_result)
// append image to list of processed images
image_ids.append(dataset.image_ids[index])
// print progress
print("{}/{}".format(index, len(dataset)), end="\r")
if not len(results):
return
// write output
json.dump(results, open("{}_bbox_results.json".format(dataset.set_name), "w"), indent=4)
// load results in COCO evaluation tool
coco_true = dataset.coco
coco_pred = coco_true.loadRes("{}_bbox_results.json".format(dataset.set_name))
// run COCO evaluation
coco_eval = COCOeval(coco_true, coco_pred, "bbox")
coco_eval.params.imgIds = image_ids
coco_eval.evaluate()
coco_eval.accumulate()
coco_eval.summarize()
model.train()
return
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 4
Instances
Project Name: yhenon/pytorch-retinanet
Commit Name: 83dc25dbc8b4ed98b4cc952e3cb35668e5a65490
Time: 2018-06-12
Author: yannhenon@gmail.com
File Name: coco_eval.py
Class Name:
Method Name: evaluate_coco
Project Name: mittagessen/kraken
Commit Name: 56156540d33f329ebf271ac9313ca723e649c0a2
Time: 2019-06-27
Author: mittagessen@l.unchti.me
File Name: kraken/blla.py
Class Name:
Method Name: segment
Project Name: kengz/SLM-Lab
Commit Name: 2381a50a70559340a0335288d648b4bb9a675588
Time: 2018-06-12
Author: kengzwl@gmail.com
File Name: slm_lab/agent/algorithm/actor_critic.py
Class Name: ActorCritic
Method Name: train_separate