如何保存YOLACT实例分割结果的信息



使用YOLACT执行实例分割时,是否有任何方法将检测到的类别、它们的编号、MASK区域等保存到TXT文件或CSV文件?

我在用YOLACT(https://github.com/dbolya/yolact)挑战实例分割。我能够使用eval.py对我自己的数据进行实例分割,并保存图像或视频。然而,我真正需要的是YOLACT的AI检测和分类的类名及其编号,以及​​口罩。如果我们可以将这些信息输出到txt文件或csv文件,我们可以使用YOLACT,甚至更高级。

如果我可以通过在eval.py中添加一个选项或修改代码来实现这一点,请教我。

谢谢。

您已经从eval.py中获得了该信息。

eval.py中的这一行为您提供信息。

# line 160
classes, scores, boxes = [x[:args.top_k].cpu().numpy() for x in t[:3]]
masks = t[3][:args.top_k]
areas = []
for mask in masks:
# Use OpenCV's findContours() to detect and obtain the contour of the variable mask
# Use OpenCV's contourArea() to calculate the area
areas.append(area)

获取检测次数:

# line 162
num_dets_to_consider = min(args.top_k, classes.shape[0])
for j in range(num_dets_to_consider):
if scores[j] < args.score_threshold:
num_dets_to_consider = j
break

将课程和分数保存为csv文件:

import pandas as pd
df = pd.DataFrame(columns=['class', 'score'])
c = 0
for i in reversed(range(num_dets_to_consider)):
classname = cfg.dataset.class_names[classes[j]]
score = scores[i]
df.loc[c] = [classname, score]
c += 1
df.to_csv('info.csv', index=None)

第1版:您可以从prep_display((返回值(类、分数、面积(,然后在evalimage((中检索它们。请注意,evaimage((调用prep_display((。你可以这样做:

classes, scores, areas = prep_display()
# Here you can include the pandas code. Note that it stores the information only for one image. You can use a loop and then store the information of all the images.

第2版:

# This is the default line in eval.py at line ~600
# This is found at evalimage()
img_numpy = prep_display(preds, frame, None, None, undo_transform=False)
# Change the above line to this:
classes, scores, areas, img_numpy = prep_display(preds, frame, None, None, undo_transform=False)
# Also, remember to return these 4 values from the prep_display(). 
# Otherwise, it will lead to an error. 
# img_numpy is the default one that will be returned from prep_display(). 
# You're now simply returning 4 values instead of 1.
# NOTE: I have included img_numpy because I found that prep_display() is being used in many places. 
# You need to modify the returns wherever prep_display() is being called in the eval.py. I think it's being called 3 times from different regions in eval.py.

最新更新