问题描述
我正在尝试使用 COCO api 评估 YOlov4 mAP,但我遇到了一些问题。事实上,它在所有评估指标中都归零。
我使用的是 YOlov4 tiny 大小为 416 并且重量经过预训练,实际上,如果我对图像进行测试似乎可以正常工作(它在图像中很好地显示了 boundinxg 框),那么当我显示结果时,问题不在于模型。
但是当我尝试评估时,我得到了非常糟糕的结果:
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.000
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.000
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.000
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.000
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.000
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.000
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.000
全零真的很奇怪。
这是我如何获得单个图像检测的方法(由我自己创建):
#parameter
min_conf_threshold=0.1
def detect_single_image(image_path,image_name):
aList=[]
image_path = image_path + image_name
image = cv2.imread(image_path)
image_rgb = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
imH,imW,_ = image.shape
image_resized = cv2.resize(image_rgb,(size,size))
image_normalized = image_resized / 255.
input_data = np.expand_dims(image_normalized,axis=0)
input_data = np.asarray(input_data).astype(np.float32)
# Perform the actual detection by running the model with the image as input
interpreter.set_tensor(input_details[0]['index'],input_data)
interpreter.invoke()
# Retrieve detection results
Boxes = interpreter.get_tensor(output_details[0]['index'])[0] # Bounding Box coordinates of detected objects
classes = interpreter.get_tensor(output_details[1]['index'])[0] # Class index of detected objects
# Loop over all detections and draw detection Box if confidence is above minimum threshold
for i in range(len(classes)):
max_index = np.argmax(classes[i])
max_value = classes[i][max_index]
if ((max_value > min_conf_threshold) and (max_value <= 1.0)):
# Get bounding Box coordinates and draw Box
# Interpreter can return coordinates that are outside of image dimensions,need to force them to be within image using max() and min()
Box_xy = np.array([Boxes[i][0],Boxes[i][1]])
Box_wh = np.array([Boxes[i][2],Boxes[i][3]])
scale = np.array([imW/size,imH/size])
Box_mins = (((Box_xy - (Box_wh / 2.)) * scale)).astype(int)
Box_xy_scaled = (Box_xy * scale).astype(int)
Box_wh_scaled = (Box_wh * scale).astype(int)
aList.append({
"image_id": int(os.path.splitext(image_name)[0]),"category_id": int(max_index),"bBox": [float(Box_mins[0]),float(Box_mins[1]),float(Box_wh_scaled[0]),float(Box_wh_scaled[1])],"score": float(max_value)
})
return aList
我遵循coco website
给出的格式[{
"image_id"
: int,"category_id"
: int,"bBox"
: [x,y,width,height],"score"
: float,}]
import os
from IPython.display import clear_output
result = ""
directory = r'/content/val2017'
i=0
full = len(os.listdir(directory))
for filename in os.listdir(directory):
a = detect_single_image(directory+"/",filename)
if (type(result) == str):
result = a
else:
result.extend(a)
#print percentage
i=i+1
if ((i%50)==0):
clear_output()
print((i/full)*100,"%")
print(type(result))
jsonString = json.dumps(result)
jsonFile = open("data.json","w")
jsonFile.write(jsonString)
jsonFile.close()
但是当我尝试使用 COCOeval 进行评估时,我失败并在所有指标中得到 0:
#second way to coco eval
annFile="/content/annotations/instances_val2017.json"
detFile="/content/data.json"
cocoGt=COCO(annFile)
cocoDt=cocoGt.loadRes(result)
# running evaluation
cocoEval = COCOeval(cocoGt,cocoDt,'bBox')
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()
我已经在顶部显示了结果。
希望有人能帮助我。
非常感谢您。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)