Skip to content

Commit 3970d37

Browse files
committed
perf(draw): 添加类别列表参数
1 parent 7ca7724 commit 3970d37

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

py/detector.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121

2222
S = 7
2323
B = 2
24-
C = 3
24+
# C = 3
25+
# cate_list = ['cucumber', 'eggplant', 'mushroom']
26+
27+
C = 20
28+
cate_list = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car', 'cat', 'chair', 'cow', 'diningtable',
29+
'dog', 'horse', 'motorbike', 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']
2530

2631

2732
def load_data(img_path, xml_path):
@@ -63,7 +68,9 @@ def load_data(img_path, xml_path):
6368
# device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
6469
device = "cpu"
6570

66-
img, data_dict = load_data('../imgs/cucumber_9.jpg', '../imgs/cucumber_9.xml')
71+
# img, data_dict = load_data('../imgs/cucumber_9.jpg', '../imgs/cucumber_9.xml')
72+
# img, data_dict = load_data('../imgs/000012.jpg', '../imgs/000012.xml')
73+
img, data_dict = load_data('../imgs/000007.jpg', '../imgs/000007.xml')
6774
model = file.load_model(device, S, B, C)
6875
# 计算
6976
outputs = model.forward(img.to(device)).cpu().squeeze(0)
@@ -92,8 +99,8 @@ def load_data(img_path, xml_path):
9299
# 预测边界框的缩放,回到原始图像
93100
pred_bboxs = util.deform_bboxs(pred_cate_bboxs, data_dict, S)
94101
# 在原图绘制标注边界框和预测边界框
95-
dst = draw.plot_bboxs(data_dict['src'], data_dict['bndboxs'], data_dict['name_list'], pred_bboxs, pred_cates,
96-
pred_cate_probs)
102+
dst = draw.plot_bboxs(data_dict['src'], data_dict['bndboxs'], data_dict['name_list'], cate_list,
103+
pred_bboxs, pred_cates, pred_cate_probs)
97104
cv2.imwrite('./detect.png', dst)
98105
# BGR -> RGB
99106
dst = cv2.cvtColor(dst, cv2.COLOR_BGR2RGB)

py/lib/utils/draw.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
import cv2
1313
import matplotlib.pyplot as plt
1414

15-
cate_list = ['cucumber', 'eggplant', 'mushroom']
16-
17-
1815
def plot_loss(loss_list):
1916
x = list(range(len(loss_list)))
2017
fg = plt.figure()
@@ -38,7 +35,7 @@ def plot_box(img, bndboxs, name_list):
3835
return dst
3936

4037

41-
def plot_bboxs(img, bndboxs, name_list, pred_boxs, pred_cates, pred_probs):
38+
def plot_bboxs(img, bndboxs, name_list, cate_list, pred_boxs, pred_cates, pred_probs):
4239
dst = copy.deepcopy(img)
4340

4441
for i in range(len(name_list)):

0 commit comments

Comments
 (0)