Closed luciaganlulu closed 2 hours ago
您好,是的
PIL.Image
, np.array
,image_path
都可以那请问这种方式的话,怎么保存每个输入图片对应的annotated_frame到指定的路径以及从det_res中获取每个输入图片对应的检测结果参数值呢(例如bbox, label, score)?predict这个函数返回的list没太看明白
那请问这种方式的话,怎么保存每个输入图片对应的annotated_frame到指定的路径以及从det_res中获取每个输入图片对应的检测结果参数值呢(例如bbox, label, score)?predict这个函数返回的list没太看明白
您好我把det_res打印出来看到了,路径问题知道啦,但是请问如何获取图中每个检测对象的bbox和score呢? 另外det_res里面的save_dir=‘runs/detect/predict’是什么意思呢?没找到这个路径在哪里诶
您好,predict返回的list长度和输入的list相同,其中每一个元素包含了预测的结果,可以参考以下保存每一个图片的结果
image_list = [
"assets/example/academic.jpg",
"assets/example/exam_paper.jpg",
"assets/example/financial.jpg",
"assets/example/fuzzy_scan.jpg",
]
det_res = model.predict(
image_list,
imgsz=args.imgsz,
conf=args.conf,
device=device,
)
for image_idx, image_path in enumerate(image_list):
print(det_res[image_idx].boxes.xyxy)
print(det_res[image_idx].boxes.cls)
print(det_res[image_idx].boxes.conf)
annotated_frame = det_res[image_idx].plot(pil=True, line_width=args.line_width, font_size=args.font_size)
if not os.path.exists(args.res_path):
os.makedirs(args.res_path)
output_path = os.path.join(args.res_path, image_path.split("/")[-1].replace(".jpg", "_res.jpg"))
cv2.imwrite(output_path, annotated_frame)
print(f"Result saved to {output_path}")
那请问这种方式的话,怎么保存每个输入图片对应的annotated_frame到指定的路径以及从det_res中获取每个输入图片对应的检测结果参数值呢(例如bbox, label, score)?predict这个函数返回的list没太看明白
您好我把det_res打印出来看到了,路径问题知道啦,但是请问如何获取图中每个检测对象的bbox和score呢? 另外det_res里面的save_dir=‘runs/detect/predict’是什么意思呢?没找到这个路径在哪里诶
det_res[idx].bbox
中,分类结果为det_res[idx].bbox.cls
,置信度为det_res[idx].bbox.conf
,检测框为det_res[idx].bbox.xyxy
(或者不同格式)save_dir
只有传入save=True
才会保存到runs/detect/predict
这个默认路径,可以参考https://docs.ultralytics.com/modes/predict/#inference-arguments那请问这种方式的话,怎么保存每个输入图片对应的annotated_frame到指定的路径以及从det_res中获取每个输入图片对应的检测结果参数值呢(例如bbox, label, score)?predict这个函数返回的list没太看明白
您好我把det_res打印出来看到了,路径问题知道啦,但是请问如何获取图中每个检测对象的bbox和score呢? 另外det_res里面的save_dir=‘runs/detect/predict’是什么意思呢?没找到这个路径在哪里诶
- 结果参数值在
det_res[idx].bbox
中,分类结果为det_res[idx].bbox.cls
,置信度为det_res[idx].bbox.conf
,检测框为det_res[idx].bbox.xyxy
(或者不同格式)save_dir
只有传入save=True
才会保存到runs/detect/predict
这个默认路径,可以参考https://docs.ultralytics.com/modes/predict/#inference-arguments
好的非常感谢~
您好,predict返回的list长度和输入的list相同,其中每一个元素包含了预测的结果,可以参考以下保存每一个图片的结果
image_list = [ "assets/example/academic.jpg", "assets/example/exam_paper.jpg", "assets/example/financial.jpg", "assets/example/fuzzy_scan.jpg", ] det_res = model.predict( image_list, imgsz=args.imgsz, conf=args.conf, device=device, ) for image_idx, image_path in enumerate(image_list): print(det_res[image_idx].boxes.xyxy) print(det_res[image_idx].boxes.cls) print(det_res[image_idx].boxes.conf) annotated_frame = det_res[image_idx].plot(pil=True, line_width=args.line_width, font_size=args.font_size) if not os.path.exists(args.res_path): os.makedirs(args.res_path) output_path = os.path.join(args.res_path, image_path.split("/")[-1].replace(".jpg", "_res.jpg")) cv2.imwrite(output_path, annotated_frame) print(f"Result saved to {output_path}")
请问下,这种方式与os.walk逐个image推理的方式相比的话,区别就在于这种list的方式可以结合batch_size数进行批处理对吗?后者只能batch_size为1。
您好,predict返回的list长度和输入的list相同,其中每一个元素包含了预测的结果,可以参考以下保存每一个图片的结果
image_list = [ "assets/example/academic.jpg", "assets/example/exam_paper.jpg", "assets/example/financial.jpg", "assets/example/fuzzy_scan.jpg", ] det_res = model.predict( image_list, imgsz=args.imgsz, conf=args.conf, device=device, ) for image_idx, image_path in enumerate(image_list): print(det_res[image_idx].boxes.xyxy) print(det_res[image_idx].boxes.cls) print(det_res[image_idx].boxes.conf) annotated_frame = det_res[image_idx].plot(pil=True, line_width=args.line_width, font_size=args.font_size) if not os.path.exists(args.res_path): os.makedirs(args.res_path) output_path = os.path.join(args.res_path, image_path.split("/")[-1].replace(".jpg", "_res.jpg")) cv2.imwrite(output_path, annotated_frame) print(f"Result saved to {output_path}")
请问下,这种方式与os.walk逐个image推理的方式相比的话,区别就在于这种list的方式可以结合batch_size数进行批处理对吗?后者只能batch_size为1。
根据YOLO的逻辑来说应该是的,您可以测试一下
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "1"
det_res = model.predict(
image_paths,
imgsz=1024,
conf=0.2,
device="cuda:1"
)
您好,我用的image_list的方式,batchsize设置的8,上面这个代码的话,我想用GPU #1(显存多点),但请问为什么还是用GPU #0呢?
torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 4.55 GiB. GPU 0 has a total capacity of 79.15 GiB of which 3.27 GiB is free.
您好,请问是直接改这里的batch数,另外source从单个image_path改成所有的图片的PIL.Image列表嘛?https://github.com/opendatalab/DocLayout-YOLO/blob/main/doclayout_yolo/engine/model.py#L431C8-L431C98