YOLO NAS预测报错:save参数不存在,求解决方案及文档指引
YOLO NAS预测保存坐标及参数查询问题解决办法
一、解决save参数报错及保存TXT坐标的方法
YOLO NAS的predict方法不支持YOLOv8中的save、save_txt参数,要保存预测坐标为TXT文件,需手动处理预测结果:
- 执行预测获取结果:
results = yolo_nas_l.predict(url, conf=0.70)
- 提取检测框信息并写入TXT文件(以单张图片为例):
detections = results[0].predictions # 写入YOLO格式的TXT文件 with open("detection_results.txt", "w") as txt_file: for det in detections: # 计算归一化后的YOLO格式坐标 img_w, img_h = det.image_width, det.image_height x_center = (det.xmin + det.xmax) / 2 / img_w y_center = (det.ymin + det.ymax) / 2 / img_h bbox_w = (det.xmax - det.xmin) / img_w bbox_h = (det.ymax - det.ymin) / img_h # 写入内容:类别索引 中心x 中心y 宽 高 置信度 txt_file.write(f"{det.class_id} {x_center:.6f} {y_center:.6f} {bbox_w:.6f} {bbox_h:.6f} {det.confidence:.6f}\n")
- 若需保存预测后的可视化图片,调用结果对象的
save方法:
results.save("output_directory")
二、查询YOLO NAS函数及参数的渠道
- 用Python内置
help()函数:在代码中执行help(yolo_nas_l.predict)或help(CustomizableDetector),直接获取方法/类的参数、功能说明 - 查看本地源码注释:找到YOLO NAS所属库(如SuperGradients)中
CustomizableDetector类的定义文件,查看方法的参数注释 - 参考库的官方API文档:查阅对应机器学习库的官方API参考章节,获取完整的函数、参数说明
内容的提问来源于stack exchange,提问作者hamza masri
相关产品推荐
相关产品推荐

