Skip to content

Commit 2c17bf3

Browse files
committed
update
1 parent 38c6ab7 commit 2c17bf3

File tree

5 files changed

+80
-37
lines changed

5 files changed

+80
-37
lines changed

examples/example_notebooks/mot_YOLOv3 copy.ipynb

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 8,
12+
"execution_count": 1,
1313
"metadata": {},
1414
"outputs": [],
1515
"source": [
1616
"import numpy as np\n",
1717
"import cv2 as cv\n",
18-
"from motrackers.detectors import nanodet\n",
18+
"from motrackers.detectors import Nanodet\n",
1919
"from motrackers import CentroidTracker, CentroidKF_Tracker, SORT, IOUTracker\n",
2020
"from motrackers.utils import draw_tracks\n",
2121
"from nanodet.util import Logger, cfg, load_config, load_model_weight\n",
@@ -24,7 +24,7 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 9,
27+
"execution_count": 2,
2828
"metadata": {},
2929
"outputs": [],
3030
"source": [
@@ -35,21 +35,21 @@
3535
},
3636
{
3737
"cell_type": "code",
38-
"execution_count": 10,
38+
"execution_count": 3,
3939
"metadata": {},
4040
"outputs": [
4141
{
4242
"data": {
4343
"application/vnd.jupyter.widget-view+json": {
44-
"model_id": "87a5b23e8af54b2aae7a0234a88ab351",
44+
"model_id": "51e2f69a12a44156811e0421ab0e949c",
4545
"version_major": 2,
4646
"version_minor": 0
4747
},
4848
"text/plain": [
4949
"Select(description='MOTracker:', options=('CentroidTracker', 'CentroidKF_Tracker', 'SORT', 'IOUTracker'), valu…"
5050
]
5151
},
52-
"execution_count": 10,
52+
"execution_count": 3,
5353
"metadata": {},
5454
"output_type": "execute_result"
5555
}
@@ -67,7 +67,7 @@
6767
},
6868
{
6969
"cell_type": "code",
70-
"execution_count": 11,
70+
"execution_count": 4,
7171
"metadata": {},
7272
"outputs": [],
7373
"source": [
@@ -86,7 +86,7 @@
8686
},
8787
{
8888
"cell_type": "code",
89-
"execution_count": 12,
89+
"execution_count": 5,
9090
"metadata": {},
9191
"outputs": [
9292
{
@@ -103,26 +103,25 @@
103103
"name": "stderr",
104104
"output_type": "stream",
105105
"text": [
106-
"\u001b[1m\u001b[35m[root]\u001b[0m\u001b[34m[04-10 20:46:36]\u001b[0m\u001b[32mINFO:\u001b[0m\u001b[37mPress \"Esc\", \"q\" or \"Q\" to exit.\u001b[0m\n",
107-
"\u001b[1m\u001b[35m[root]\u001b[0m\u001b[34m[04-10 20:46:36]\u001b[0m\u001b[32mINFO:\u001b[0m\u001b[37mPress \"Esc\", \"q\" or \"Q\" to exit.\u001b[0m\n"
106+
"\u001b[1m\u001b[35m[root]\u001b[0m\u001b[34m[04-10 21:59:08]\u001b[0m\u001b[32mINFO:\u001b[0m\u001b[37mPress \"Esc\", \"q\" or \"Q\" to exit.\u001b[0m\n"
108107
]
109108
}
110109
],
111110
"source": [
112111
"# 导入模型文件\n",
113112
"local_rank = 0\n",
114-
"model = WEIGHTS_PATH\n",
113+
"modelpath = WEIGHTS_PATH\n",
115114
"device = \"cpu:0\"\n",
116115
"config = CONFIG_FILE_PATH\n",
117116
"logger = Logger(local_rank, use_tensorboard=False)\n",
118117
"load_config(cfg, config)\n",
119-
"detmodel = nanodet.Nanodet(cfg, model, logger, device)\n",
118+
"detmodel = Nanodet(cfg, modelpath, logger, device)\n",
120119
"logger.log('Press \"Esc\", \"q\" or \"Q\" to exit.')"
121120
]
122121
},
123122
{
124123
"cell_type": "code",
125-
"execution_count": 13,
124+
"execution_count": 6,
126125
"metadata": {
127126
"scrolled": false
128127
},
@@ -138,12 +137,10 @@
138137
" print(\"Cannot read the video feed.\")\n",
139138
" break\n",
140139
" \n",
141-
" meta, res = detmodel.inference(image)\n",
142-
" bboxes, confidences, class_ids = detmodel.visualize(res[0], meta, cfg.class_names, 0.43)\n",
140+
" meta, res = model.inference(image)\n",
141+
" bboxes,confidences,class_ids,updated_image = model.visualize(res[0], meta, cfg.class_names, 0.43)\n",
143142
" \n",
144143
" tracks = tracker.update(bboxes, confidences, class_ids)\n",
145-
" \n",
146-
" updated_image = detmodel.draw_bboxes(image.copy(), bboxes, confidences, class_ids)\n",
147144
"\n",
148145
" updated_image = draw_tracks(updated_image, tracks)\n",
149146
"\n",
@@ -157,31 +154,39 @@
157154
},
158155
{
159156
"cell_type": "code",
160-
"execution_count": 14,
157+
"execution_count": 7,
161158
"metadata": {},
162159
"outputs": [
163160
{
164161
"name": "stdout",
165162
"output_type": "stream",
166163
"text": [
167-
"forward time: 0.146s | decode time: 0.004s | viz time: 0.000s\n"
164+
"forward time: 0.156s | decode time: 0.038s | viz time: 0.003s\n"
165+
]
166+
},
167+
{
168+
"name": "stderr",
169+
"output_type": "stream",
170+
"text": [
171+
"d:\\ProgramData\\Anaconda3\\envs\\ist\\lib\\site-packages\\torch\\functional.py:478: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at C:\\actions-runner\\_work\\pytorch\\pytorch\\builder\\windows\\pytorch\\aten\\src\\ATen\\native\\TensorShape.cpp:2895.)\n",
172+
" return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined]\n"
168173
]
169174
},
170175
{
171-
"ename": "AttributeError",
172-
"evalue": "'Nanodet' object has no attribute 'draw_bboxes'",
176+
"ename": "ValueError",
177+
"evalue": "not enough values to unpack (expected 4, got 3)",
173178
"output_type": "error",
174179
"traceback": [
175180
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
176-
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
177-
"Cell \u001b[1;32mIn[14], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m main(VIDEO_FILE, model, tracker)\n",
178-
"Cell \u001b[1;32mIn[13], line 16\u001b[0m, in \u001b[0;36mmain\u001b[1;34m(video_path, model, tracker)\u001b[0m\n\u001b[0;32m 12\u001b[0m bboxes, confidences, class_ids \u001b[39m=\u001b[39m detmodel\u001b[39m.\u001b[39mvisualize(res[\u001b[39m0\u001b[39m], meta, cfg\u001b[39m.\u001b[39mclass_names, \u001b[39m0.43\u001b[39m)\n\u001b[0;32m 14\u001b[0m tracks \u001b[39m=\u001b[39m tracker\u001b[39m.\u001b[39mupdate(bboxes, confidences, class_ids)\n\u001b[1;32m---> 16\u001b[0m updated_image \u001b[39m=\u001b[39m detmodel\u001b[39m.\u001b[39;49mdraw_bboxes(image\u001b[39m.\u001b[39mcopy(), bboxes, confidences, class_ids)\n\u001b[0;32m 18\u001b[0m updated_image \u001b[39m=\u001b[39m draw_tracks(updated_image, tracks)\n\u001b[0;32m 20\u001b[0m cv\u001b[39m.\u001b[39mimshow(\u001b[39m\"\u001b[39m\u001b[39mimage\u001b[39m\u001b[39m\"\u001b[39m, updated_image)\n",
179-
"\u001b[1;31mAttributeError\u001b[0m: 'Nanodet' object has no attribute 'draw_bboxes'"
181+
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
182+
"Cell \u001b[1;32mIn[7], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m main(VIDEO_FILE, detmodel, tracker)\n",
183+
"Cell \u001b[1;32mIn[6], line 12\u001b[0m, in \u001b[0;36mmain\u001b[1;34m(video_path, model, tracker)\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[39mbreak\u001b[39;00m\n\u001b[0;32m 11\u001b[0m meta, res \u001b[39m=\u001b[39m model\u001b[39m.\u001b[39minference(image)\n\u001b[1;32m---> 12\u001b[0m bboxes,confidences,class_ids,updated_image \u001b[39m=\u001b[39m model\u001b[39m.\u001b[39mvisualize(res[\u001b[39m0\u001b[39m], meta, cfg\u001b[39m.\u001b[39mclass_names, \u001b[39m0.43\u001b[39m)\n\u001b[0;32m 14\u001b[0m tracks \u001b[39m=\u001b[39m tracker\u001b[39m.\u001b[39mupdate(bboxes, confidences, class_ids)\n\u001b[0;32m 16\u001b[0m updated_image \u001b[39m=\u001b[39m draw_tracks(updated_image, tracks)\n",
184+
"\u001b[1;31mValueError\u001b[0m: not enough values to unpack (expected 4, got 3)"
180185
]
181186
}
182187
],
183188
"source": [
184-
"main(VIDEO_FILE, model, tracker)"
189+
"main(VIDEO_FILE, detmodel, tracker)"
185190
]
186191
},
187192
{

main.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import numpy as np
22
import cv2 as cv
3-
from motrackers.detectors import nanodet
3+
from motrackers.detectors import Nanodet
44
from motrackers import CentroidTracker, CentroidKF_Tracker, SORT, IOUTracker
55
from motrackers.utils import draw_tracks
66
from nanodet.util import Logger, cfg, load_config, load_model_weight
77

8-
VIDEO_FILE = "22.avi"
9-
WEIGHTS_PATH = 'weight/LiquidV4.pth'
10-
CONFIG_FILE_PATH = 'config/LiquidDetect416.yml'
8+
VIDEO_FILE = r"D:\shijue\LiquidDrop\22.avi"
9+
WEIGHTS_PATH = r'D:\shijue\multi-object-tracker\weight\LiquidV4.pth'
10+
CONFIG_FILE_PATH = r'D:\shijue\multi-object-tracker\config\LiquidDetect416.yml'
1111

1212
tracker = CentroidTracker(max_lost=0, tracker_output_format='mot_challenge')
1313

1414
# 导入模型文件
1515
local_rank = 0
16-
model = WEIGHTS_PATH
16+
modelpath = WEIGHTS_PATH
1717
device = "cpu:0"
1818
config = CONFIG_FILE_PATH
1919
logger = Logger(local_rank, use_tensorboard=False)
2020
load_config(cfg, config)
21-
model = nanodet(cfg, model, logger, device)
21+
detmodel = Nanodet(cfg, modelpath, logger, device)
2222
logger.log('Press "Esc", "q" or "Q" to exit.')
2323

2424
def main(video_path, model, tracker):
@@ -32,11 +32,9 @@ def main(video_path, model, tracker):
3232
break
3333

3434
meta, res = model.inference(image)
35-
bboxes, confidences, class_ids = model.visualize(res[0], meta, cfg.class_names, 0.43)
35+
bboxes,confidences,class_ids,updated_image = model.visualize(res[0], meta, cfg.class_names, 0.43)
3636

3737
tracks = tracker.update(bboxes, confidences, class_ids)
38-
39-
updated_image = model.draw_bboxes(image.copy(), bboxes, confidences, class_ids)
4038

4139
updated_image = draw_tracks(updated_image, tracks)
4240

@@ -49,4 +47,4 @@ def main(video_path, model, tracker):
4947

5048

5149

52-
main(VIDEO_FILE, model, tracker)
50+
main(VIDEO_FILE, detmodel, tracker)

motrackers/detectors/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from motrackers.detectors.tf import TF_SSDMobileNetV2
22
from motrackers.detectors.caffe import Caffe_SSDMobileNet
33
from motrackers.detectors.yolo import YOLOv3
4+
from motrackers.detectors.nanodet import Nanodet

motrackers/detectors/nanodet.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,19 @@ def visualize(self, dets, meta, class_names, score_thres, wait=0):
6363
self.class_names = class_names
6464
bboxes , confidences , class_ids = infotrans(all_box)
6565
print("viz time: {:.3f}s".format(time.time() - time1))
66-
return bboxes , confidences , class_ids
66+
67+
image = meta["raw_img"][0].copy()
68+
for bb, conf, cid in zip(bboxes, confidences, class_ids):
69+
bbox_colors = {key: np.random.randint(0, 255, size=(3,)).tolist() for key in self.class_names.keys()}
70+
clr = [int(c) for c in bbox_colors[cid]]
71+
cv2.rectangle(image, (bb[0], bb[1]), (bb[0] + bb[2], bb[1] + bb[3]), clr, 2)
72+
label = "{}:{:.4f}".format(self.class_names[cid], conf)
73+
(label_width, label_height), baseLine = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 0.5, 2)
74+
y_label = max(bb[1], label_height)
75+
cv2.rectangle(image, (bb[0], y_label - label_height), (bb[0] + label_width, y_label + baseLine),
76+
(255, 255, 255), cv2.FILLED)
77+
cv2.putText(image, label, (bb[0], y_label), cv2.FONT_HERSHEY_SIMPLEX, 0.5, clr, 2)
78+
return bboxes , confidences , class_ids , image
6779

6880
def draw_bboxes(self, image, bboxes, confidences, class_ids):
6981
"""

setup_nanodet.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env python
2+
from setuptools import find_packages, setup
3+
4+
from nanodet import __author__, __author_email__, __docs__, __homepage__, __version__
5+
6+
if __name__ == "__main__":
7+
setup(
8+
name="nanodet",
9+
version=__version__,
10+
description=__docs__,
11+
url=__homepage__,
12+
author=__author__,
13+
author_email=__author_email__,
14+
keywords="deep learning",
15+
packages=find_packages(exclude=("config", "tools", "demo")),
16+
classifiers=[
17+
"Development Status :: Beta",
18+
"License :: OSI Approved :: Apache Software License",
19+
"Operating System :: OS Independent",
20+
"Programming Language :: Python :: 3.5",
21+
"Programming Language :: Python :: 3.6",
22+
"Programming Language :: Python :: 3.7",
23+
"Programming Language :: Python :: 3.8",
24+
],
25+
license="Apache License 2.0",
26+
zip_safe=False,
27+
)

0 commit comments

Comments
 (0)