txtPath=os.path.join(vocDir,"eval.txt") with open(txtPath,"w") as f: f.writelines("allGroundBoxNum:{} ".format(groundBoxNum)) f.writelines("allDetectedBoxNum:{} ".format(detectedBoxNum)) f.writelines("allDetectedBoxRightNum:{} ".format(detectedBoxRightNum)) f.writelines("allDetectedBoxAndClassificationRightNum:{} ".format(detectedBoxAndClassificationRightNum)) f.writelines("识别错误的框的个数:{} ".format(detectedBoxNum - detectedBoxRightNum)) f.writelines("识别错误的框的个数/预测的框:{} ".format((detectedBoxNum - detectedBoxRightNum) / detectedBoxNum)) f.writelines("识别对的框/所有的框:{} ".format(detectedBoxRightNum / groundBoxNum)) f.writelines("框和分类都正确/所有的框:{} ".format(detectedBoxAndClassificationRightNum / groundBoxNum)) for i in range(len(categories)): f.writelines("{}的Ground,Detected,DetectedRight个数分别为{},{},{}, ".format(categories[i]["name"], allGroundClassNumDict[i + 1], allDetectedClassNumDict[i + 1], allDetectedClassRightNumDict[i + 1]))
w+表示写入,不存在则创建
写入也可以用python的format,太方便了