ref
https://blog.csdn.net/qq_27261889/article/details/83622691
测试
def feedback_factors(self,image):
predictions = self.compute_prediction(image)
top_predictions = self.select_top_predictions(predictions)
# top_predictions=predictions
boxes = top_predictions.bbox.tolist()
scores = top_predictions.get_field("scores").tolist()
labels = top_predictions.get_field("labels").tolist()
result = []
result.extend(
[
{
"image_id": 1,
"category_id": labels[k],
"bbox": box,
"score": scores[k],
}
for k, box in enumerate(boxes)
]
)
main中对测试集中数据结果进行写入
out=[]
for i in range(24):
img=cv2.imread('../mask/datasets/coco/val2017/s{}.jpg'.format(i+1))
composite = mydata_demo.feedback_factors(img)
# change the image id
for sample in composite:
sample['image_id']=i+1
for sample in composite:
out.append(sample)#detection result including
import json
with open('test_data.json', 'w', encoding='utf-8') as file:
json.dump(out, file, ensure_ascii=False)
ref