Spaces:
Sleeping
Sleeping
dinhminh20521597
commited on
Commit
·
d6a7d5a
1
Parent(s):
2366fef
Upload 8 files
Browse files- README.md +21 -12
- app.py +278 -0
- configs/fasterrcnn.py +247 -0
- configs/yolov3.py +210 -0
- demo_page-0001.jpg +0 -0
- environment.yml +227 -0
- generate.py +182 -0
- models/dump.txt +0 -0
README.md
CHANGED
@@ -1,12 +1,21 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!-- Title -->
|
2 |
+
<h1 align="center"><b>Newspaper Crawling with Scrapy</b></h1>
|
3 |
+
|
4 |
+
## Set up environment
|
5 |
+
|
6 |
+
```
|
7 |
+
conda env create -f environment.yml
|
8 |
+
conda activate demo-mm-st
|
9 |
+
```
|
10 |
+
|
11 |
+
## Streamlit demo
|
12 |
+
|
13 |
+
To run streamlit demo, you need to download weights files [Faster-RCNN](https://github.com/laichithien/FaceMaskDetection_StreamlitDemo/releases/download/FaceMaskDetModels/fasterrcnn.pth), [YOLOv3](https://github.com/laichithien/FaceMaskDetection_StreamlitDemo/releases/download/FaceMaskDetModels/yolov3.pth) and place them in `models` folder
|
14 |
+
After that, simply run command below
|
15 |
+
```
|
16 |
+
streamlit run demo.py
|
17 |
+
```
|
18 |
+
## Demo interface
|
19 |
+
![](demo_page-0001.jpg)
|
20 |
+
|
21 |
+
|
app.py
ADDED
@@ -0,0 +1,278 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
import requests
|
5 |
+
from mmdet.apis import init_detector, inference_detector
|
6 |
+
import mmcv
|
7 |
+
import torch
|
8 |
+
from mmdet.utils.contextmanagers import concurrent
|
9 |
+
from pprint import pprint
|
10 |
+
from PIL import Image
|
11 |
+
import datetime
|
12 |
+
|
13 |
+
def IoU(bbox1, bbox2):
|
14 |
+
|
15 |
+
x1_left = bbox1[0]
|
16 |
+
y1_top = bbox1[1]
|
17 |
+
x1_right = bbox1[2]
|
18 |
+
y1_bot = bbox1[3]
|
19 |
+
|
20 |
+
x2_left = bbox2[0]
|
21 |
+
y2_top = bbox2[1]
|
22 |
+
x2_right = bbox2[2]
|
23 |
+
y2_bot = bbox2[3]
|
24 |
+
|
25 |
+
x_left = max(x1_left, x2_left)
|
26 |
+
x_right = min(x1_right, x2_right)
|
27 |
+
y_top = max(y1_top, y2_top)
|
28 |
+
y_bot = min(y1_bot, y2_bot)
|
29 |
+
|
30 |
+
inter = (x_right - x_left) * (y_bot - y_top)
|
31 |
+
if x_right < x_left or y_bot < y_top:
|
32 |
+
return 0.0
|
33 |
+
area1 = (x1_right - x1_left) * (y1_bot - y1_top)
|
34 |
+
area2 = (x2_right - x2_left) * (y2_bot - y2_top)
|
35 |
+
union = area1 + area2 - inter
|
36 |
+
|
37 |
+
IoU = inter / union
|
38 |
+
return IoU
|
39 |
+
|
40 |
+
def file():
|
41 |
+
inputimg = st.file_uploader("Upload your image")
|
42 |
+
if inputimg is not None:
|
43 |
+
inputimg = Image.open(inputimg)
|
44 |
+
inputimg = np.array(inputimg)
|
45 |
+
inputimg = cv2.cvtColor(inputimg, cv2.COLOR_BGR2RGB)
|
46 |
+
cv2.imwrite('demo_file.jpg', inputimg)
|
47 |
+
return inputimg
|
48 |
+
|
49 |
+
def webcam():
|
50 |
+
inputimg = st.camera_input("Take a picture")
|
51 |
+
if inputimg is not None:
|
52 |
+
inputimg = Image.open(inputimg)
|
53 |
+
inputimg = np.array(inputimg)
|
54 |
+
inputimg = cv2.cvtColor(inputimg, cv2.COLOR_BGR2RGB)
|
55 |
+
cv2.imwrite('demo_webcam.jpg', inputimg)
|
56 |
+
return inputimg
|
57 |
+
|
58 |
+
def phonecam():
|
59 |
+
if st.button("Take picture"):
|
60 |
+
url = 'http://192.168.114.78:8080//photo.jpg'
|
61 |
+
img_resp = requests.get(url)
|
62 |
+
img_arr = np.array(bytearray(img_resp.content), dtype=np.uint8)
|
63 |
+
inputimg = cv2.imdecode(img_arr, -1)
|
64 |
+
cv2.imwrite('demo_phonecam.jpg', inputimg)
|
65 |
+
return inputimg
|
66 |
+
|
67 |
+
|
68 |
+
def detect(inputimg, model):
|
69 |
+
|
70 |
+
if model == 'f':
|
71 |
+
config_file = './configs/fasterrcnn.py'
|
72 |
+
checkpoint_file = './models/fasterrcnn.pth'
|
73 |
+
# Specify the path to model config and checkpoint file
|
74 |
+
else:
|
75 |
+
config_file = './configs/yolov3.py'
|
76 |
+
checkpoint_file = './models/yolov3.pth'
|
77 |
+
|
78 |
+
# build the model from a config file and a checkpoint file
|
79 |
+
model = init_detector(config_file, checkpoint_file, device='cuda:0')
|
80 |
+
if (inputimg == 'Webcam'):
|
81 |
+
img = 'demo_webcam.jpg' # or img = mmcv.imread(img), which will only load it once
|
82 |
+
elif (inputimg == 'File'):
|
83 |
+
img = 'demo_file.jpg'
|
84 |
+
elif (inputimg == 'Phone'):
|
85 |
+
img = 'demo_phonecam.jpg'
|
86 |
+
start = datetime.datetime.now()
|
87 |
+
result = inference_detector(model, img)
|
88 |
+
end = datetime.datetime.now()
|
89 |
+
|
90 |
+
time = end - start
|
91 |
+
|
92 |
+
time_mcs = time.microseconds
|
93 |
+
|
94 |
+
total_people = 0
|
95 |
+
incorrect = 0
|
96 |
+
withmask = 0
|
97 |
+
withoutmask = 0
|
98 |
+
|
99 |
+
list_objects = []
|
100 |
+
isRemove = []
|
101 |
+
for i in result[1]:
|
102 |
+
temp = i
|
103 |
+
temp = np.append(temp, 1)
|
104 |
+
list_objects.append(temp)
|
105 |
+
isRemove.append(0)
|
106 |
+
|
107 |
+
for i in result[2]:
|
108 |
+
temp = i
|
109 |
+
temp = np.append(temp, 2)
|
110 |
+
list_objects.append(temp)
|
111 |
+
isRemove.append(0)
|
112 |
+
|
113 |
+
for i in result[3]:
|
114 |
+
temp = i
|
115 |
+
temp = np.append(temp, 3)
|
116 |
+
list_objects.append(temp)
|
117 |
+
isRemove.append(0)
|
118 |
+
|
119 |
+
for i in range(len(list_objects) - 1):
|
120 |
+
for j in range(i + 1, len(list_objects)):
|
121 |
+
bbox1 = [list_objects[i][0], list_objects[i][1], list_objects[i][2], list_objects[i][3]]
|
122 |
+
bbox2 = [list_objects[j][0], list_objects[j][1], list_objects[j][2], list_objects[j][3]]
|
123 |
+
if abs(IoU(bbox1, bbox2)) > 0.7:
|
124 |
+
if list_objects[i][4] > list_objects[j][4]:
|
125 |
+
isRemove[j] = 1
|
126 |
+
else:
|
127 |
+
isRemove[i] = 1
|
128 |
+
# print("IoU", abs(IoU(bbox1, bbox2)))
|
129 |
+
|
130 |
+
|
131 |
+
if list_objects[i][4] < 0.4:
|
132 |
+
isRemove[i] = 1
|
133 |
+
if list_objects[j][4] < 0.4:
|
134 |
+
isRemove[j] = 1
|
135 |
+
|
136 |
+
selected_list = []
|
137 |
+
for i in range(len(list_objects)):
|
138 |
+
if isRemove[i] == 0:
|
139 |
+
selected_list.append(list_objects[i])
|
140 |
+
|
141 |
+
for i in selected_list:
|
142 |
+
if i[5] == 1:
|
143 |
+
incorrect += 1
|
144 |
+
elif i[5] == 2:
|
145 |
+
withmask += 1
|
146 |
+
elif i[5] ==3:
|
147 |
+
withoutmask += 1
|
148 |
+
|
149 |
+
total_people += incorrect + withmask + withoutmask
|
150 |
+
|
151 |
+
|
152 |
+
img = cv2.imread(img)
|
153 |
+
for i in selected_list:
|
154 |
+
if i[5] == 1:
|
155 |
+
color = (255, 0, 0)
|
156 |
+
text = "Mask weared incorrect"
|
157 |
+
elif i[5] == 2:
|
158 |
+
color = (0, 255, 0)
|
159 |
+
text = "With mask"
|
160 |
+
elif i[5] == 3:
|
161 |
+
color = (0, 0, 255)
|
162 |
+
text = "Without mask"
|
163 |
+
text += ": " + str(round(i[4], 2))
|
164 |
+
x1 = i[0]
|
165 |
+
y1 = i[1]
|
166 |
+
x2 = i[2] - 1
|
167 |
+
y2 = i[3] - 1
|
168 |
+
|
169 |
+
x1 = round(x1)
|
170 |
+
y1 = round(y1)
|
171 |
+
x2 = round(x2)
|
172 |
+
y2 = round(y2)
|
173 |
+
|
174 |
+
img = cv2.rectangle(img, (x1, y1), (x2, y2), color, 3)
|
175 |
+
img = cv2.putText(img, text, (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2)
|
176 |
+
output ="result_demo.jpg"
|
177 |
+
return img, total_people, incorrect, withmask, withoutmask, time_mcs/1000
|
178 |
+
|
179 |
+
st.title("Demo đồ án môn học CS331 - Thị giác máy tính nâng cao")
|
180 |
+
|
181 |
+
st.write("Lại Chí Thiện - 20520309")
|
182 |
+
st.write("Lê Thị Phương Vy - 20520355")
|
183 |
+
|
184 |
+
file_page, webcam_page, phonecam_page = st.tabs(["File", "Webcam", "Phone's camera"])
|
185 |
+
|
186 |
+
with file_page:
|
187 |
+
inputimg_file = file()
|
188 |
+
if inputimg_file is not None:
|
189 |
+
st.image(cv2.cvtColor(inputimg_file, cv2.COLOR_BGR2RGB))
|
190 |
+
frcnn, yolov3 = st.columns(2)
|
191 |
+
with frcnn:
|
192 |
+
result_rcnn, total, inc, withm, withoutm, time = detect('File', 'f')
|
193 |
+
st.image(cv2.cvtColor(result_rcnn, cv2.COLOR_BGR2RGB))
|
194 |
+
st.write("Faster R-CNN")
|
195 |
+
st.write("Tổng số người có trong bức ảnh: ", total)
|
196 |
+
st.write("Tổng số người không đeo khẩu trang: ", withoutm)
|
197 |
+
st.write("Tổng số người đeo khẩu trang sai cách: ", inc)
|
198 |
+
st.write("Tổng số người đeo khẩu trang: ", withm)
|
199 |
+
st.write("Tỉ lệ số người không đeo khẩu trang: ", round(withoutm/total, 2))
|
200 |
+
st.write("Tỉ lệ số người đeo khẩu trang sai cách: ", round(inc/total, 2))
|
201 |
+
st.write("Tỉ lệ số người đeo khẩu trang: ", round(withm/total, 2))
|
202 |
+
st.write("Thời gian thực thi (miliseconds): ", time)
|
203 |
+
with yolov3:
|
204 |
+
result_yolov3, total, inc, withm, withoutm, time = detect('File', 'y')
|
205 |
+
st.image(cv2.cvtColor(result_yolov3, cv2.COLOR_BGR2RGB))
|
206 |
+
st.write("YOLOv3")
|
207 |
+
st.write("Tổng số người có trong bức ảnh: ", total)
|
208 |
+
st.write("Tổng số người không đeo khẩu trang: ", withoutm)
|
209 |
+
st.write("Tổng số người đeo khẩu trang sai cách: ", inc)
|
210 |
+
st.write("Tổng số người đeo khẩu trang: ", withm)
|
211 |
+
st.write("Tỉ lệ số người không đeo khẩu trang: ", round(withoutm/total, 2))
|
212 |
+
st.write("Tỉ lệ số người đeo khẩu trang sai cách: ", round(inc/total, 2))
|
213 |
+
st.write("Tỉ lệ số người đeo khẩu trang: ", round(withm/total, 2))
|
214 |
+
st.write("Thời gian thực thi (miliseconds): ", time)
|
215 |
+
|
216 |
+
with webcam_page:
|
217 |
+
inputimg_wc = webcam()
|
218 |
+
if inputimg_wc is not None:
|
219 |
+
st.image(cv2.cvtColor(inputimg_wc, cv2.COLOR_BGR2RGB))
|
220 |
+
frcnn, yolov3 = st.columns(2)
|
221 |
+
with frcnn:
|
222 |
+
result_rcnn, total, inc, withm, withoutm, time = detect('Webcam', 'f')
|
223 |
+
st.image(cv2.cvtColor(result_rcnn, cv2.COLOR_BGR2RGB))
|
224 |
+
st.write("Faster R-CNN")
|
225 |
+
st.write("Tổng số người có trong bức ảnh: ", total)
|
226 |
+
st.write("Tổng số người không đeo khẩu trang: ", withoutm)
|
227 |
+
st.write("Tổng số người đeo khẩu trang sai cách: ", inc)
|
228 |
+
st.write("Tổng số người đeo khẩu trang: ", withm)
|
229 |
+
st.write("Tỉ lệ số người không đeo khẩu trang: ", round(withoutm/total, 2))
|
230 |
+
st.write("Tỉ lệ số người đeo khẩu trang sai cách: ", round(inc/total, 2))
|
231 |
+
st.write("Tỉ lệ số người đeo khẩu trang: ", round(withm/total, 2))
|
232 |
+
st.write("Thời gian thực thi (miliseconds): ", time)
|
233 |
+
with yolov3:
|
234 |
+
result_yolov3, total, inc, withm, withoutm, time = detect('Webcam', 'y')
|
235 |
+
st.image(cv2.cvtColor(result_yolov3, cv2.COLOR_BGR2RGB))
|
236 |
+
st.write("YOLOv3")
|
237 |
+
st.write("Tổng số người có trong bức ảnh: ", total)
|
238 |
+
st.write("Tổng số người không đeo khẩu trang: ", withoutm)
|
239 |
+
st.write("Tổng số người đeo khẩu trang sai cách: ", inc)
|
240 |
+
st.write("Tổng số người đeo khẩu trang: ", withm)
|
241 |
+
st.write("Tỉ lệ số người không đeo khẩu trang: ", round(withoutm/total, 2))
|
242 |
+
st.write("Tỉ lệ số người đeo khẩu trang sai cách: ", round(inc/total, 2))
|
243 |
+
st.write("Tỉ lệ số người đeo khẩu trang: ", round(withm/total, 2))
|
244 |
+
st.write("Thời gian thực thi (miliseconds): ", time)
|
245 |
+
|
246 |
+
with phonecam_page:
|
247 |
+
inputimg_pc = phonecam()
|
248 |
+
if inputimg_pc is not None:
|
249 |
+
st.image(cv2.cvtColor(inputimg_pc, cv2.COLOR_BGR2RGB))
|
250 |
+
frcnn, yolov3 = st.columns(2)
|
251 |
+
with frcnn:
|
252 |
+
result_rcnn, total, inc, withm, withoutm, time = detect('Phone', 'f')
|
253 |
+
st.image(cv2.cvtColor(result_rcnn, cv2.COLOR_BGR2RGB))
|
254 |
+
st.write("Faster R-CNN")
|
255 |
+
st.write("Tổng số người có trong bức ảnh: ", total)
|
256 |
+
st.write("Tổng số người không đeo khẩu trang: ", withoutm)
|
257 |
+
st.write("Tổng số người đeo khẩu trang sai cách: ", inc)
|
258 |
+
st.write("Tổng số người đeo khẩu trang: ", withm)
|
259 |
+
st.write("Tỉ lệ số người không đeo khẩu trang: ", round(withoutm/total, 2))
|
260 |
+
st.write("Tỉ lệ số người đeo khẩu trang sai cách: ", round(inc/total, 2))
|
261 |
+
st.write("Tỉ lệ số người đeo khẩu trang: ", round(withm/total, 2))
|
262 |
+
st.write("Thời gian thực thi (miliseconds): ", time)
|
263 |
+
with yolov3:
|
264 |
+
result_yolov3, total, inc, withm, withoutm, time = detect('Phone', 'y')
|
265 |
+
st.image(cv2.cvtColor(result_yolov3, cv2.COLOR_BGR2RGB))
|
266 |
+
st.write("YOLOv3")
|
267 |
+
st.write("Tổng số người có trong bức ảnh: ", total)
|
268 |
+
st.write("Tổng số người không đeo khẩu trang: ", withoutm)
|
269 |
+
st.write("Tổng số người đeo khẩu trang sai cách: ", inc)
|
270 |
+
st.write("Tổng số người đeo khẩu trang: ", withm)
|
271 |
+
st.write("Tỉ lệ số người không đeo khẩu trang: ", round(withoutm/total, 2))
|
272 |
+
st.write("Tỉ lệ số người đeo khẩu trang sai cách: ", round(inc/total, 2))
|
273 |
+
st.write("Tỉ lệ số người đeo khẩu trang: ", round(withm/total, 2))
|
274 |
+
st.write("Thời gian thực thi (miliseconds): ", time)
|
275 |
+
|
276 |
+
|
277 |
+
|
278 |
+
|
configs/fasterrcnn.py
ADDED
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
model = dict(
|
2 |
+
type='FasterRCNN',
|
3 |
+
backbone=dict(
|
4 |
+
type='ResNet',
|
5 |
+
depth=50,
|
6 |
+
num_stages=4,
|
7 |
+
out_indices=(0, 1, 2, 3),
|
8 |
+
frozen_stages=1,
|
9 |
+
norm_cfg=dict(type='BN', requires_grad=True),
|
10 |
+
norm_eval=True,
|
11 |
+
style='pytorch',
|
12 |
+
init_cfg=dict(type='Pretrained', checkpoint='torchvision://resnet50')),
|
13 |
+
neck=dict(
|
14 |
+
type='FPN',
|
15 |
+
in_channels=[256, 512, 1024, 2048],
|
16 |
+
out_channels=256,
|
17 |
+
num_outs=5),
|
18 |
+
rpn_head=dict(
|
19 |
+
type='RPNHead',
|
20 |
+
in_channels=256,
|
21 |
+
feat_channels=256,
|
22 |
+
anchor_generator=dict(
|
23 |
+
type='AnchorGenerator',
|
24 |
+
scales=[8],
|
25 |
+
ratios=[0.5, 1.0, 2.0],
|
26 |
+
strides=[4, 8, 16, 32, 64]),
|
27 |
+
bbox_coder=dict(
|
28 |
+
type='DeltaXYWHBBoxCoder',
|
29 |
+
target_means=[0.0, 0.0, 0.0, 0.0],
|
30 |
+
target_stds=[1.0, 1.0, 1.0, 1.0]),
|
31 |
+
loss_cls=dict(
|
32 |
+
type='CrossEntropyLoss', use_sigmoid=True, loss_weight=1.0),
|
33 |
+
loss_bbox=dict(type='L1Loss', loss_weight=1.0)),
|
34 |
+
roi_head=dict(
|
35 |
+
type='StandardRoIHead',
|
36 |
+
bbox_roi_extractor=dict(
|
37 |
+
type='SingleRoIExtractor',
|
38 |
+
roi_layer=dict(type='RoIAlign', output_size=7, sampling_ratio=0),
|
39 |
+
out_channels=256,
|
40 |
+
featmap_strides=[4, 8, 16, 32]),
|
41 |
+
bbox_head=dict(
|
42 |
+
type='Shared2FCBBoxHead',
|
43 |
+
in_channels=256,
|
44 |
+
fc_out_channels=1024,
|
45 |
+
roi_feat_size=7,
|
46 |
+
num_classes=4,
|
47 |
+
bbox_coder=dict(
|
48 |
+
type='DeltaXYWHBBoxCoder',
|
49 |
+
target_means=[0.0, 0.0, 0.0, 0.0],
|
50 |
+
target_stds=[0.1, 0.1, 0.2, 0.2]),
|
51 |
+
reg_class_agnostic=False,
|
52 |
+
loss_cls=dict(
|
53 |
+
type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0),
|
54 |
+
loss_bbox=dict(type='L1Loss', loss_weight=1.0))),
|
55 |
+
train_cfg=dict(
|
56 |
+
rpn=dict(
|
57 |
+
assigner=dict(
|
58 |
+
type='MaxIoUAssigner',
|
59 |
+
pos_iou_thr=0.7,
|
60 |
+
neg_iou_thr=0.3,
|
61 |
+
min_pos_iou=0.3,
|
62 |
+
match_low_quality=True,
|
63 |
+
ignore_iof_thr=-1),
|
64 |
+
sampler=dict(
|
65 |
+
type='RandomSampler',
|
66 |
+
num=256,
|
67 |
+
pos_fraction=0.5,
|
68 |
+
neg_pos_ub=-1,
|
69 |
+
add_gt_as_proposals=False),
|
70 |
+
allowed_border=-1,
|
71 |
+
pos_weight=-1,
|
72 |
+
debug=False),
|
73 |
+
rpn_proposal=dict(
|
74 |
+
nms_pre=2000,
|
75 |
+
max_per_img=1000,
|
76 |
+
nms=dict(type='nms', iou_threshold=0.7),
|
77 |
+
min_bbox_size=0),
|
78 |
+
rcnn=dict(
|
79 |
+
assigner=dict(
|
80 |
+
type='MaxIoUAssigner',
|
81 |
+
pos_iou_thr=0.5,
|
82 |
+
neg_iou_thr=0.5,
|
83 |
+
min_pos_iou=0.5,
|
84 |
+
match_low_quality=False,
|
85 |
+
ignore_iof_thr=-1),
|
86 |
+
sampler=dict(
|
87 |
+
type='RandomSampler',
|
88 |
+
num=512,
|
89 |
+
pos_fraction=0.25,
|
90 |
+
neg_pos_ub=-1,
|
91 |
+
add_gt_as_proposals=True),
|
92 |
+
pos_weight=-1,
|
93 |
+
debug=False)),
|
94 |
+
test_cfg=dict(
|
95 |
+
rpn=dict(
|
96 |
+
nms_pre=1000,
|
97 |
+
max_per_img=1000,
|
98 |
+
nms=dict(type='nms', iou_threshold=0.7),
|
99 |
+
min_bbox_size=0),
|
100 |
+
rcnn=dict(
|
101 |
+
score_thr=0.05,
|
102 |
+
nms=dict(type='nms', iou_threshold=0.5),
|
103 |
+
max_per_img=100)))
|
104 |
+
classes = ['people', 'mask_weared_incorrect', 'with_mask', 'without_mask']
|
105 |
+
dataset_type = 'CocoDataset'
|
106 |
+
data_root = 'data/coco/'
|
107 |
+
img_norm_cfg = dict(
|
108 |
+
mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
|
109 |
+
train_pipeline = [
|
110 |
+
dict(type='LoadImageFromFile'),
|
111 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
112 |
+
dict(type='Resize', img_scale=(1333, 800), keep_ratio=True),
|
113 |
+
dict(type='RandomFlip', flip_ratio=0.5),
|
114 |
+
dict(
|
115 |
+
type='Normalize',
|
116 |
+
mean=[123.675, 116.28, 103.53],
|
117 |
+
std=[58.395, 57.12, 57.375],
|
118 |
+
to_rgb=True),
|
119 |
+
dict(type='Pad', size_divisor=32),
|
120 |
+
dict(type='DefaultFormatBundle'),
|
121 |
+
dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels'])
|
122 |
+
]
|
123 |
+
test_pipeline = [
|
124 |
+
dict(type='LoadImageFromFile'),
|
125 |
+
dict(
|
126 |
+
type='MultiScaleFlipAug',
|
127 |
+
img_scale=(1333, 800),
|
128 |
+
flip=False,
|
129 |
+
transforms=[
|
130 |
+
dict(type='Resize', keep_ratio=True),
|
131 |
+
dict(type='RandomFlip'),
|
132 |
+
dict(
|
133 |
+
type='Normalize',
|
134 |
+
mean=[123.675, 116.28, 103.53],
|
135 |
+
std=[58.395, 57.12, 57.375],
|
136 |
+
to_rgb=True),
|
137 |
+
dict(type='Pad', size_divisor=32),
|
138 |
+
dict(type='ImageToTensor', keys=['img']),
|
139 |
+
dict(type='Collect', keys=['img'])
|
140 |
+
])
|
141 |
+
]
|
142 |
+
data = dict(
|
143 |
+
samples_per_gpu=2,
|
144 |
+
workers_per_gpu=2,
|
145 |
+
train=dict(
|
146 |
+
type='CocoDataset',
|
147 |
+
ann_file=
|
148 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/train/_annotations.coco.json',
|
149 |
+
img_prefix=
|
150 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/train/',
|
151 |
+
classes=[
|
152 |
+
'people', 'mask_weared_incorrect', 'with_mask', 'without_mask'
|
153 |
+
],
|
154 |
+
pipeline=[
|
155 |
+
dict(type='LoadImageFromFile'),
|
156 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
157 |
+
dict(type='Resize', img_scale=(1333, 800), keep_ratio=True),
|
158 |
+
dict(type='RandomFlip', flip_ratio=0.5),
|
159 |
+
dict(
|
160 |
+
type='Normalize',
|
161 |
+
mean=[123.675, 116.28, 103.53],
|
162 |
+
std=[58.395, 57.12, 57.375],
|
163 |
+
to_rgb=True),
|
164 |
+
dict(type='Pad', size_divisor=32),
|
165 |
+
dict(type='DefaultFormatBundle'),
|
166 |
+
dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels'])
|
167 |
+
]),
|
168 |
+
val=dict(
|
169 |
+
type='CocoDataset',
|
170 |
+
ann_file=
|
171 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/valid/_annotations.coco.json',
|
172 |
+
img_prefix=
|
173 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/valid/',
|
174 |
+
classes=[
|
175 |
+
'people', 'mask_weared_incorrect', 'with_mask', 'without_mask'
|
176 |
+
],
|
177 |
+
pipeline=[
|
178 |
+
dict(type='LoadImageFromFile'),
|
179 |
+
dict(
|
180 |
+
type='MultiScaleFlipAug',
|
181 |
+
img_scale=(1333, 800),
|
182 |
+
flip=False,
|
183 |
+
transforms=[
|
184 |
+
dict(type='Resize', keep_ratio=True),
|
185 |
+
dict(type='RandomFlip'),
|
186 |
+
dict(
|
187 |
+
type='Normalize',
|
188 |
+
mean=[123.675, 116.28, 103.53],
|
189 |
+
std=[58.395, 57.12, 57.375],
|
190 |
+
to_rgb=True),
|
191 |
+
dict(type='Pad', size_divisor=32),
|
192 |
+
dict(type='ImageToTensor', keys=['img']),
|
193 |
+
dict(type='Collect', keys=['img'])
|
194 |
+
])
|
195 |
+
]),
|
196 |
+
test=dict(
|
197 |
+
type='CocoDataset',
|
198 |
+
ann_file=
|
199 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/test/_annotations.coco.json',
|
200 |
+
img_prefix=
|
201 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/test/',
|
202 |
+
classes=[
|
203 |
+
'people', 'mask_weared_incorrect', 'with_mask', 'without_mask'
|
204 |
+
],
|
205 |
+
pipeline=[
|
206 |
+
dict(type='LoadImageFromFile'),
|
207 |
+
dict(
|
208 |
+
type='MultiScaleFlipAug',
|
209 |
+
img_scale=(1333, 800),
|
210 |
+
flip=False,
|
211 |
+
transforms=[
|
212 |
+
dict(type='Resize', keep_ratio=True),
|
213 |
+
dict(type='RandomFlip'),
|
214 |
+
dict(
|
215 |
+
type='Normalize',
|
216 |
+
mean=[123.675, 116.28, 103.53],
|
217 |
+
std=[58.395, 57.12, 57.375],
|
218 |
+
to_rgb=True),
|
219 |
+
dict(type='Pad', size_divisor=32),
|
220 |
+
dict(type='ImageToTensor', keys=['img']),
|
221 |
+
dict(type='Collect', keys=['img'])
|
222 |
+
])
|
223 |
+
]))
|
224 |
+
evaluation = dict(interval=1, metric='bbox')
|
225 |
+
optimizer = dict(type='SGD', lr=0.005, momentum=0.9, weight_decay=0.0001)
|
226 |
+
optimizer_config = dict(grad_clip=None)
|
227 |
+
lr_config = dict(
|
228 |
+
policy='step',
|
229 |
+
warmup='linear',
|
230 |
+
warmup_iters=500,
|
231 |
+
warmup_ratio=0.001,
|
232 |
+
step=[8, 11])
|
233 |
+
runner = dict(type='EpochBasedRunner', max_epochs=24)
|
234 |
+
checkpoint_config = dict(interval=1)
|
235 |
+
log_config = dict(interval=50, hooks=[dict(type='TextLoggerHook')])
|
236 |
+
custom_hooks = [dict(type='NumClassCheckHook')]
|
237 |
+
dist_params = dict(backend='nccl')
|
238 |
+
log_level = 'INFO'
|
239 |
+
load_from = None
|
240 |
+
resume_from = './workdirs/faster_rcnn_r50_fpn_1x/latest.pth'
|
241 |
+
workflow = [('train', 1)]
|
242 |
+
opencv_num_threads = 0
|
243 |
+
mp_start_method = 'fork'
|
244 |
+
auto_scale_lr = dict(enable=False, base_batch_size=16)
|
245 |
+
work_dir = './workdirs/faster_rcnn_r50_fpn_1x'
|
246 |
+
auto_resume = False
|
247 |
+
gpu_ids = [0]
|
configs/yolov3.py
ADDED
@@ -0,0 +1,210 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
checkpoint_config = dict(interval=50)
|
2 |
+
log_config = dict(interval=50, hooks=[dict(type='TextLoggerHook')])
|
3 |
+
custom_hooks = [dict(type='NumClassCheckHook')]
|
4 |
+
dist_params = dict(backend='nccl')
|
5 |
+
log_level = 'INFO'
|
6 |
+
load_from = None
|
7 |
+
resume_from = './workdirs/yolov3_d53_320_273e/latest.pth'
|
8 |
+
workflow = [('train', 1)]
|
9 |
+
opencv_num_threads = 0
|
10 |
+
mp_start_method = 'fork'
|
11 |
+
auto_scale_lr = dict(enable=False, base_batch_size=64)
|
12 |
+
model = dict(
|
13 |
+
type='YOLOV3',
|
14 |
+
backbone=dict(
|
15 |
+
type='Darknet',
|
16 |
+
depth=53,
|
17 |
+
out_indices=(3, 4, 5),
|
18 |
+
init_cfg=dict(type='Pretrained', checkpoint='open-mmlab://darknet53')),
|
19 |
+
neck=dict(
|
20 |
+
type='YOLOV3Neck',
|
21 |
+
num_scales=3,
|
22 |
+
in_channels=[1024, 512, 256],
|
23 |
+
out_channels=[512, 256, 128]),
|
24 |
+
bbox_head=dict(
|
25 |
+
type='YOLOV3Head',
|
26 |
+
num_classes=4,
|
27 |
+
in_channels=[512, 256, 128],
|
28 |
+
out_channels=[1024, 512, 256],
|
29 |
+
anchor_generator=dict(
|
30 |
+
type='YOLOAnchorGenerator',
|
31 |
+
base_sizes=[[(116, 90), (156, 198), (373, 326)],
|
32 |
+
[(30, 61), (62, 45), (59, 119)],
|
33 |
+
[(10, 13), (16, 30), (33, 23)]],
|
34 |
+
strides=[32, 16, 8]),
|
35 |
+
bbox_coder=dict(type='YOLOBBoxCoder'),
|
36 |
+
featmap_strides=[32, 16, 8],
|
37 |
+
loss_cls=dict(
|
38 |
+
type='CrossEntropyLoss',
|
39 |
+
use_sigmoid=True,
|
40 |
+
loss_weight=1.0,
|
41 |
+
reduction='sum'),
|
42 |
+
loss_conf=dict(
|
43 |
+
type='CrossEntropyLoss',
|
44 |
+
use_sigmoid=True,
|
45 |
+
loss_weight=1.0,
|
46 |
+
reduction='sum'),
|
47 |
+
loss_xy=dict(
|
48 |
+
type='CrossEntropyLoss',
|
49 |
+
use_sigmoid=True,
|
50 |
+
loss_weight=2.0,
|
51 |
+
reduction='sum'),
|
52 |
+
loss_wh=dict(type='MSELoss', loss_weight=2.0, reduction='sum')),
|
53 |
+
train_cfg=dict(
|
54 |
+
assigner=dict(
|
55 |
+
type='GridAssigner',
|
56 |
+
pos_iou_thr=0.5,
|
57 |
+
neg_iou_thr=0.5,
|
58 |
+
min_pos_iou=0)),
|
59 |
+
test_cfg=dict(
|
60 |
+
nms_pre=1000,
|
61 |
+
min_bbox_size=0,
|
62 |
+
score_thr=0.05,
|
63 |
+
conf_thr=0.005,
|
64 |
+
nms=dict(type='nms', iou_threshold=0.45),
|
65 |
+
max_per_img=100))
|
66 |
+
dataset_type = 'CocoDataset'
|
67 |
+
data_root = 'data/coco/'
|
68 |
+
img_norm_cfg = dict(mean=[0, 0, 0], std=[255.0, 255.0, 255.0], to_rgb=True)
|
69 |
+
train_pipeline = [
|
70 |
+
dict(type='LoadImageFromFile'),
|
71 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
72 |
+
dict(type='Expand', mean=[0, 0, 0], to_rgb=True, ratio_range=(1, 2)),
|
73 |
+
dict(
|
74 |
+
type='MinIoURandomCrop',
|
75 |
+
min_ious=(0.4, 0.5, 0.6, 0.7, 0.8, 0.9),
|
76 |
+
min_crop_size=0.3),
|
77 |
+
dict(type='Resize', img_scale=(416, 416), keep_ratio=True),
|
78 |
+
dict(type='RandomFlip', flip_ratio=0.5),
|
79 |
+
dict(type='PhotoMetricDistortion'),
|
80 |
+
dict(
|
81 |
+
type='Normalize',
|
82 |
+
mean=[0, 0, 0],
|
83 |
+
std=[255.0, 255.0, 255.0],
|
84 |
+
to_rgb=True),
|
85 |
+
dict(type='Pad', size_divisor=32),
|
86 |
+
dict(type='DefaultFormatBundle'),
|
87 |
+
dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels'])
|
88 |
+
]
|
89 |
+
test_pipeline = [
|
90 |
+
dict(type='LoadImageFromFile'),
|
91 |
+
dict(
|
92 |
+
type='MultiScaleFlipAug',
|
93 |
+
img_scale=(416, 416),
|
94 |
+
flip=False,
|
95 |
+
transforms=[
|
96 |
+
dict(type='Resize', keep_ratio=True),
|
97 |
+
dict(type='RandomFlip'),
|
98 |
+
dict(
|
99 |
+
type='Normalize',
|
100 |
+
mean=[0, 0, 0],
|
101 |
+
std=[255.0, 255.0, 255.0],
|
102 |
+
to_rgb=True),
|
103 |
+
dict(type='Pad', size_divisor=32),
|
104 |
+
dict(type='ImageToTensor', keys=['img']),
|
105 |
+
dict(type='Collect', keys=['img'])
|
106 |
+
])
|
107 |
+
]
|
108 |
+
data = dict(
|
109 |
+
samples_per_gpu=8,
|
110 |
+
workers_per_gpu=8,
|
111 |
+
train=dict(
|
112 |
+
type='CocoDataset',
|
113 |
+
ann_file=
|
114 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/train/_annotations.coco.json',
|
115 |
+
img_prefix=
|
116 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/train/',
|
117 |
+
classes=[
|
118 |
+
'people', 'mask_weared_incorrect', 'with_mask', 'without_mask'
|
119 |
+
],
|
120 |
+
pipeline=[
|
121 |
+
dict(type='LoadImageFromFile'),
|
122 |
+
dict(type='LoadAnnotations', with_bbox=True),
|
123 |
+
dict(
|
124 |
+
type='Expand', mean=[0, 0, 0], to_rgb=True,
|
125 |
+
ratio_range=(1, 2)),
|
126 |
+
dict(
|
127 |
+
type='MinIoURandomCrop',
|
128 |
+
min_ious=(0.4, 0.5, 0.6, 0.7, 0.8, 0.9),
|
129 |
+
min_crop_size=0.3),
|
130 |
+
dict(type='Resize', img_scale=(416, 416), keep_ratio=True),
|
131 |
+
dict(type='RandomFlip', flip_ratio=0.5),
|
132 |
+
dict(type='PhotoMetricDistortion'),
|
133 |
+
dict(
|
134 |
+
type='Normalize',
|
135 |
+
mean=[0, 0, 0],
|
136 |
+
std=[255.0, 255.0, 255.0],
|
137 |
+
to_rgb=True),
|
138 |
+
dict(type='Pad', size_divisor=32),
|
139 |
+
dict(type='DefaultFormatBundle'),
|
140 |
+
dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels'])
|
141 |
+
]),
|
142 |
+
val=dict(
|
143 |
+
type='CocoDataset',
|
144 |
+
ann_file=
|
145 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/valid/_annotations.coco.json',
|
146 |
+
img_prefix=
|
147 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/valid/',
|
148 |
+
classes=[
|
149 |
+
'people', 'mask_weared_incorrect', 'with_mask', 'without_mask'
|
150 |
+
],
|
151 |
+
pipeline=[
|
152 |
+
dict(type='LoadImageFromFile'),
|
153 |
+
dict(
|
154 |
+
type='MultiScaleFlipAug',
|
155 |
+
img_scale=(416, 416),
|
156 |
+
flip=False,
|
157 |
+
transforms=[
|
158 |
+
dict(type='Resize', keep_ratio=True),
|
159 |
+
dict(type='RandomFlip'),
|
160 |
+
dict(
|
161 |
+
type='Normalize',
|
162 |
+
mean=[0, 0, 0],
|
163 |
+
std=[255.0, 255.0, 255.0],
|
164 |
+
to_rgb=True),
|
165 |
+
dict(type='Pad', size_divisor=32),
|
166 |
+
dict(type='ImageToTensor', keys=['img']),
|
167 |
+
dict(type='Collect', keys=['img'])
|
168 |
+
])
|
169 |
+
]),
|
170 |
+
test=dict(
|
171 |
+
type='CocoDataset',
|
172 |
+
ann_file=
|
173 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/test/_annotations.coco.json',
|
174 |
+
img_prefix=
|
175 |
+
'/content/drive/MyDrive/ComputerVisionPP/Data/mmdet/FaceMaskDetection-2/test/',
|
176 |
+
classes=[
|
177 |
+
'people', 'mask_weared_incorrect', 'with_mask', 'without_mask'
|
178 |
+
],
|
179 |
+
pipeline=[
|
180 |
+
dict(type='LoadImageFromFile'),
|
181 |
+
dict(
|
182 |
+
type='MultiScaleFlipAug',
|
183 |
+
img_scale=(416, 416),
|
184 |
+
flip=False,
|
185 |
+
transforms=[
|
186 |
+
dict(type='Resize', keep_ratio=True),
|
187 |
+
dict(type='RandomFlip'),
|
188 |
+
dict(
|
189 |
+
type='Normalize',
|
190 |
+
mean=[0, 0, 0],
|
191 |
+
std=[255.0, 255.0, 255.0],
|
192 |
+
to_rgb=True),
|
193 |
+
dict(type='Pad', size_divisor=32),
|
194 |
+
dict(type='ImageToTensor', keys=['img']),
|
195 |
+
dict(type='Collect', keys=['img'])
|
196 |
+
])
|
197 |
+
]))
|
198 |
+
optimizer = dict(type='SGD', lr=0.001, momentum=0.9, weight_decay=0.0005)
|
199 |
+
optimizer_config = dict(grad_clip=dict(max_norm=35, norm_type=2))
|
200 |
+
lr_config = dict(
|
201 |
+
policy='step',
|
202 |
+
warmup='linear',
|
203 |
+
warmup_iters=2000,
|
204 |
+
warmup_ratio=0.1,
|
205 |
+
step=[218, 246])
|
206 |
+
runner = dict(type='EpochBasedRunner', max_epochs=300)
|
207 |
+
evaluation = dict(interval=1, metric=['bbox'])
|
208 |
+
work_dir = './workdirs/yolov3_d53_320_273e'
|
209 |
+
auto_resume = False
|
210 |
+
gpu_ids = [0]
|
demo_page-0001.jpg
ADDED
environment.yml
ADDED
@@ -0,0 +1,227 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: demo-mm-st
|
2 |
+
channels:
|
3 |
+
- pytorch
|
4 |
+
- nvidia
|
5 |
+
- defaults
|
6 |
+
dependencies:
|
7 |
+
- altair=4.1.0=py_1
|
8 |
+
- arrow-cpp=8.0.0=py310h38b8b19_1
|
9 |
+
- asttokens=2.0.5=pyhd3eb1b0_0
|
10 |
+
- attrs=22.1.0=py310haa95532_0
|
11 |
+
- aws-c-common=0.4.57=ha925a31_1
|
12 |
+
- aws-c-event-stream=0.1.6=hd77b12b_5
|
13 |
+
- aws-checksums=0.1.9=ha925a31_0
|
14 |
+
- aws-sdk-cpp=1.8.185=hd77b12b_0
|
15 |
+
- backcall=0.2.0=pyhd3eb1b0_0
|
16 |
+
- blas=1.0=mkl
|
17 |
+
- blinker=1.4=py310haa95532_0
|
18 |
+
- boost-cpp=1.73.0=h2bbff1b_12
|
19 |
+
- bottleneck=1.3.5=py310h9128911_0
|
20 |
+
- brotlipy=0.7.0=py310h2bbff1b_1002
|
21 |
+
- bzip2=1.0.8=he774522_0
|
22 |
+
- c-ares=1.19.0=h2bbff1b_0
|
23 |
+
- ca-certificates=2023.01.10=haa95532_0
|
24 |
+
- cachetools=4.2.2=pyhd3eb1b0_0
|
25 |
+
- certifi=2022.12.7=py310haa95532_0
|
26 |
+
- cffi=1.15.1=py310h2bbff1b_3
|
27 |
+
- charset-normalizer=2.0.4=pyhd3eb1b0_0
|
28 |
+
- colorama=0.4.6=py310haa95532_0
|
29 |
+
- comm=0.1.2=py310haa95532_0
|
30 |
+
- commonmark=0.9.1=pyhd3eb1b0_0
|
31 |
+
- cryptography=39.0.1=py310h21b164f_0
|
32 |
+
- cuda-cccl=12.1.55=0
|
33 |
+
- cuda-cudart=11.8.89=0
|
34 |
+
- cuda-cudart-dev=11.8.89=0
|
35 |
+
- cuda-cupti=11.8.87=0
|
36 |
+
- cuda-libraries=11.8.0=0
|
37 |
+
- cuda-libraries-dev=11.8.0=0
|
38 |
+
- cuda-nvrtc=11.8.89=0
|
39 |
+
- cuda-nvrtc-dev=11.8.89=0
|
40 |
+
- cuda-nvtx=11.8.86=0
|
41 |
+
- cuda-profiler-api=12.1.55=0
|
42 |
+
- cuda-runtime=11.8.0=0
|
43 |
+
- dataclasses=0.8=pyh6d0b6a4_7
|
44 |
+
- debugpy=1.5.1=py310hd77b12b_0
|
45 |
+
- decorator=5.1.1=pyhd3eb1b0_0
|
46 |
+
- eigen=3.3.7=h59b6b97_1
|
47 |
+
- entrypoints=0.4=py310haa95532_0
|
48 |
+
- executing=0.8.3=pyhd3eb1b0_0
|
49 |
+
- ffmpeg=4.2.2=he774522_0
|
50 |
+
- filelock=3.9.0=py310haa95532_0
|
51 |
+
- flit-core=3.8.0=py310haa95532_0
|
52 |
+
- freetype=2.12.1=ha860e81_0
|
53 |
+
- future=0.18.3=py310haa95532_0
|
54 |
+
- gflags=2.2.2=ha925a31_0
|
55 |
+
- giflib=5.2.1=h8cc25b3_3
|
56 |
+
- gitdb=4.0.7=pyhd3eb1b0_0
|
57 |
+
- gitpython=3.1.30=py310haa95532_0
|
58 |
+
- glib=2.69.1=h5dc1a3c_2
|
59 |
+
- glog=0.5.0=hd77b12b_0
|
60 |
+
- gst-plugins-base=1.18.5=h9e645db_0
|
61 |
+
- gstreamer=1.18.5=hd78058f_0
|
62 |
+
- hdf5=1.10.6=h1756f20_1
|
63 |
+
- icc_rt=2022.1.0=h6049295_2
|
64 |
+
- icu=58.2=ha925a31_3
|
65 |
+
- idna=3.4=py310haa95532_0
|
66 |
+
- importlib-metadata=6.0.0=py310haa95532_0
|
67 |
+
- intel-openmp=2021.4.0=haa95532_3556
|
68 |
+
- ipykernel=6.19.2=py310h9909e9c_0
|
69 |
+
- ipython=8.10.0=py310haa95532_0
|
70 |
+
- ipywidgets=8.0.4=py310haa95532_0
|
71 |
+
- jedi=0.18.1=py310haa95532_1
|
72 |
+
- jinja2=3.1.2=py310haa95532_0
|
73 |
+
- jpeg=9e=h2bbff1b_1
|
74 |
+
- jsonschema=4.17.3=py310haa95532_0
|
75 |
+
- jupyter_client=7.4.9=py310haa95532_0
|
76 |
+
- jupyter_core=5.2.0=py310haa95532_0
|
77 |
+
- jupyterlab_widgets=3.0.5=py310haa95532_0
|
78 |
+
- lerc=3.0=hd77b12b_0
|
79 |
+
- libboost=1.73.0=h6c2663c_12
|
80 |
+
- libbrotlicommon=1.0.9=h2bbff1b_7
|
81 |
+
- libbrotlidec=1.0.9=h2bbff1b_7
|
82 |
+
- libbrotlienc=1.0.9=h2bbff1b_7
|
83 |
+
- libclang=12.0.0=default_h627e005_2
|
84 |
+
- libcublas=11.11.3.6=0
|
85 |
+
- libcublas-dev=11.11.3.6=0
|
86 |
+
- libcufft=10.9.0.58=0
|
87 |
+
- libcufft-dev=10.9.0.58=0
|
88 |
+
- libcurand=10.3.2.56=0
|
89 |
+
- libcurand-dev=10.3.2.56=0
|
90 |
+
- libcurl=7.88.1=h86230a5_0
|
91 |
+
- libcusolver=11.4.1.48=0
|
92 |
+
- libcusolver-dev=11.4.1.48=0
|
93 |
+
- libcusparse=11.7.5.86=0
|
94 |
+
- libcusparse-dev=11.7.5.86=0
|
95 |
+
- libdeflate=1.17=h2bbff1b_0
|
96 |
+
- libffi=3.4.2=hd77b12b_6
|
97 |
+
- libiconv=1.16=h2bbff1b_2
|
98 |
+
- libnpp=11.8.0.86=0
|
99 |
+
- libnpp-dev=11.8.0.86=0
|
100 |
+
- libnvjpeg=11.9.0.86=0
|
101 |
+
- libnvjpeg-dev=11.9.0.86=0
|
102 |
+
- libogg=1.3.5=h2bbff1b_1
|
103 |
+
- libpng=1.6.39=h8cc25b3_0
|
104 |
+
- libprotobuf=3.20.3=h23ce68f_0
|
105 |
+
- libsodium=1.0.18=h62dcd97_0
|
106 |
+
- libssh2=1.10.0=hcd4344a_0
|
107 |
+
- libthrift=0.15.0=he1d8c1a_0
|
108 |
+
- libtiff=4.5.0=h6c2663c_2
|
109 |
+
- libuv=1.44.2=h2bbff1b_0
|
110 |
+
- libvorbis=1.3.7=he774522_0
|
111 |
+
- libwebp=1.2.4=hbc33d0d_1
|
112 |
+
- libwebp-base=1.2.4=h2bbff1b_1
|
113 |
+
- libxml2=2.9.14=h0ad7f3c_0
|
114 |
+
- libxslt=1.1.35=h2bbff1b_0
|
115 |
+
- lz4-c=1.9.4=h2bbff1b_0
|
116 |
+
- markupsafe=2.1.1=py310h2bbff1b_0
|
117 |
+
- matplotlib-inline=0.1.6=py310haa95532_0
|
118 |
+
- mkl=2021.4.0=haa95532_640
|
119 |
+
- mkl-service=2.4.0=py310h2bbff1b_0
|
120 |
+
- mkl_fft=1.3.1=py310ha0764ea_0
|
121 |
+
- mkl_random=1.2.2=py310h4ed8f06_0
|
122 |
+
- mpmath=1.2.1=py310haa95532_0
|
123 |
+
- nest-asyncio=1.5.6=py310haa95532_0
|
124 |
+
- networkx=2.8.4=py310haa95532_1
|
125 |
+
- numexpr=2.8.4=py310hd213c9f_0
|
126 |
+
- numpy=1.23.5=py310h60c9a35_0
|
127 |
+
- numpy-base=1.23.5=py310h04254f7_0
|
128 |
+
- opencv=4.6.0=py310h4ed8f06_3
|
129 |
+
- openssl=1.1.1t=h2bbff1b_0
|
130 |
+
- packaging=23.0=py310haa95532_0
|
131 |
+
- pandas=1.5.3=py310h4ed8f06_0
|
132 |
+
- parso=0.8.3=pyhd3eb1b0_0
|
133 |
+
- pcre=8.45=hd77b12b_0
|
134 |
+
- pickleshare=0.7.5=pyhd3eb1b0_1003
|
135 |
+
- pillow=9.4.0=py310hd77b12b_0
|
136 |
+
- pip=23.0.1=py310haa95532_0
|
137 |
+
- platformdirs=2.5.2=py310haa95532_0
|
138 |
+
- prompt-toolkit=3.0.36=py310haa95532_0
|
139 |
+
- protobuf=3.20.3=py310hd77b12b_0
|
140 |
+
- psutil=5.9.0=py310h2bbff1b_0
|
141 |
+
- pure_eval=0.2.2=pyhd3eb1b0_0
|
142 |
+
- pyarrow=8.0.0=py310h26aae1b_0
|
143 |
+
- pycparser=2.21=pyhd3eb1b0_0
|
144 |
+
- pydeck=0.7.1=py310haa95532_0
|
145 |
+
- pympler=0.9=py_0
|
146 |
+
- pyopenssl=23.0.0=py310haa95532_0
|
147 |
+
- pyrsistent=0.18.0=py310h2bbff1b_0
|
148 |
+
- pysocks=1.7.1=py310haa95532_0
|
149 |
+
- python=3.10.10=h966fe2a_2
|
150 |
+
- python-dateutil=2.8.2=pyhd3eb1b0_0
|
151 |
+
- pytorch=2.0.0=py3.10_cuda11.8_cudnn8_0
|
152 |
+
- pytorch-cuda=11.8=h24eeafa_3
|
153 |
+
- pytorch-mutex=1.0=cuda
|
154 |
+
- pywin32=305=py310h2bbff1b_0
|
155 |
+
- pyyaml=6.0=py310h2bbff1b_1
|
156 |
+
- pyzmq=23.2.0=py310hd77b12b_0
|
157 |
+
- qt-main=5.15.2=he8e5bd7_7
|
158 |
+
- qt-webengine=5.15.9=hb9a9bb5_5
|
159 |
+
- qtwebkit=5.212=h3ad3cdb_4
|
160 |
+
- re2=2022.04.01=hd77b12b_0
|
161 |
+
- requests=2.28.1=py310haa95532_1
|
162 |
+
- semver=2.13.0=pyhd3eb1b0_0
|
163 |
+
- setuptools=65.6.3=py310haa95532_0
|
164 |
+
- six=1.16.0=pyhd3eb1b0_1
|
165 |
+
- smmap=4.0.0=pyhd3eb1b0_0
|
166 |
+
- snappy=1.1.9=h6c2663c_0
|
167 |
+
- sqlite=3.41.1=h2bbff1b_0
|
168 |
+
- stack_data=0.2.0=pyhd3eb1b0_0
|
169 |
+
- sympy=1.11.1=py310haa95532_0
|
170 |
+
- tk=8.6.12=h2bbff1b_0
|
171 |
+
- toml=0.10.2=pyhd3eb1b0_0
|
172 |
+
- toolz=0.12.0=py310haa95532_0
|
173 |
+
- tornado=6.2=py310h2bbff1b_0
|
174 |
+
- traitlets=5.7.1=py310haa95532_0
|
175 |
+
- typing_extensions=4.4.0=py310haa95532_0
|
176 |
+
- tzdata=2022g=h04d1e81_0
|
177 |
+
- tzlocal=2.1=py310haa95532_1
|
178 |
+
- urllib3=1.26.14=py310haa95532_0
|
179 |
+
- utf8proc=2.6.1=h2bbff1b_0
|
180 |
+
- validators=0.18.2=pyhd3eb1b0_0
|
181 |
+
- vc=14.2=h21ff451_1
|
182 |
+
- vs2015_runtime=14.27.29016=h5e58377_2
|
183 |
+
- watchdog=2.1.6=py310haa95532_0
|
184 |
+
- wcwidth=0.2.5=pyhd3eb1b0_0
|
185 |
+
- wheel=0.38.4=py310haa95532_0
|
186 |
+
- widgetsnbextension=4.0.5=py310haa95532_0
|
187 |
+
- win_inet_pton=1.1.0=py310haa95532_0
|
188 |
+
- wincertstore=0.2=py310haa95532_2
|
189 |
+
- xz=5.2.10=h8cc25b3_1
|
190 |
+
- yaml=0.2.5=he774522_0
|
191 |
+
- zeromq=4.3.4=hd77b12b_0
|
192 |
+
- zipp=3.11.0=py310haa95532_0
|
193 |
+
- zlib=1.2.13=h8cc25b3_0
|
194 |
+
- zstd=1.5.2=h19a0ad4_0
|
195 |
+
- pip:
|
196 |
+
- addict==2.4.0
|
197 |
+
- click==8.1.3
|
198 |
+
- contourpy==1.0.7
|
199 |
+
- cycler==0.11.0
|
200 |
+
- cython==0.29.33
|
201 |
+
- fonttools==4.39.2
|
202 |
+
- kiwisolver==1.4.4
|
203 |
+
- markdown==3.4.3
|
204 |
+
- markdown-it-py==2.2.0
|
205 |
+
- matplotlib==3.7.1
|
206 |
+
- mdurl==0.1.2
|
207 |
+
- mmcls==0.25.0
|
208 |
+
- mmcv==1.7.1
|
209 |
+
- mmcv-full==1.7.1
|
210 |
+
- mmpycocotools==12.0.3
|
211 |
+
- model-index==0.1.11
|
212 |
+
- openmim==0.3.7
|
213 |
+
- ordered-set==4.1.0
|
214 |
+
- pycocotools==2.0.6
|
215 |
+
- pygments==2.14.0
|
216 |
+
- pyparsing==3.0.9
|
217 |
+
- pytz==2023.2
|
218 |
+
- regex==2023.3.23
|
219 |
+
- rich==13.3.2
|
220 |
+
- scipy==1.10.1
|
221 |
+
- streamlit==1.20.0
|
222 |
+
- tabulate==0.9.0
|
223 |
+
- terminaltables==3.1.10
|
224 |
+
- torchaudio==2.0.0
|
225 |
+
- torchvision==0.15.0
|
226 |
+
- yapf==0.32.0
|
227 |
+
prefix: C:\Users\laich\anaconda3\envs\demo-mm-st
|
generate.py
ADDED
@@ -0,0 +1,182 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import cv2
|
3 |
+
import numpy as np
|
4 |
+
import requests
|
5 |
+
from mmdet.apis import init_detector, inference_detector
|
6 |
+
import mmcv
|
7 |
+
import torch
|
8 |
+
from mmdet.utils.contextmanagers import concurrent
|
9 |
+
from pprint import pprint
|
10 |
+
from PIL import Image
|
11 |
+
import datetime
|
12 |
+
|
13 |
+
|
14 |
+
|
15 |
+
# Specify the path to model config and checkpoint file
|
16 |
+
config_file = 'configs/fasterrcnn.py'
|
17 |
+
checkpoint_file = 'models/fasterrcnn.pth'
|
18 |
+
|
19 |
+
# build the model from a config file and a checkpoint file
|
20 |
+
model = init_detector(config_file, checkpoint_file, device='cuda:0')
|
21 |
+
|
22 |
+
# test a single image and show the results
|
23 |
+
img = 'demo2.png' # or img = mmcv.imread(img), which will only load it once
|
24 |
+
result = inference_detector(model, img)
|
25 |
+
# visualize the results in a new window
|
26 |
+
model.show_result(img, result)
|
27 |
+
# or save the visualization results to image files
|
28 |
+
model.show_result(img, result, out_file='result.jpg')
|
29 |
+
|
30 |
+
list_objects = []
|
31 |
+
|
32 |
+
for i in result[1]:
|
33 |
+
temp = i
|
34 |
+
temp = np.append(temp, 1)
|
35 |
+
list_objects.append(temp)
|
36 |
+
|
37 |
+
for i in result[2]:
|
38 |
+
temp = i
|
39 |
+
temp = np.append(temp, 2)
|
40 |
+
list_objects.append(temp)
|
41 |
+
|
42 |
+
for i in result[3]:
|
43 |
+
temp = i
|
44 |
+
temp = np.append(temp, 3)
|
45 |
+
list_objects.append(temp)
|
46 |
+
|
47 |
+
img = cv2.imread(img)
|
48 |
+
for i in list_objects:
|
49 |
+
if i[5] == 1:
|
50 |
+
color = (255, 0, 0)
|
51 |
+
text = "Mask weared incorrect"
|
52 |
+
elif i[5] == 2:
|
53 |
+
color = (0, 255, 0)
|
54 |
+
text = "With mask"
|
55 |
+
elif i[5] == 3:
|
56 |
+
color = (0, 0, 255)
|
57 |
+
text = "Without mask"
|
58 |
+
text += ": " + str(round(i[4], 2))
|
59 |
+
x1 = i[0]
|
60 |
+
y1 = i[1]
|
61 |
+
x2 = i[2] - 1
|
62 |
+
y2 = i[3] - 1
|
63 |
+
|
64 |
+
x1 = round(x1)
|
65 |
+
y1 = round(y1)
|
66 |
+
x2 = round(x2)
|
67 |
+
y2 = round(y2)
|
68 |
+
|
69 |
+
img = cv2.rectangle(img, (x1, y1), (x2, y2), color, 3)
|
70 |
+
img = cv2.putText(img, text, (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2)
|
71 |
+
cv2.imwrite('Original_result.jpg', img)
|
72 |
+
|
73 |
+
def IoU(bbox1, bbox2):
|
74 |
+
|
75 |
+
x1_left = bbox1[0]
|
76 |
+
y1_top = bbox1[1]
|
77 |
+
x1_right = bbox1[2]
|
78 |
+
y1_bot = bbox1[3]
|
79 |
+
|
80 |
+
x2_left = bbox2[0]
|
81 |
+
y2_top = bbox2[1]
|
82 |
+
x2_right = bbox2[2]
|
83 |
+
y2_bot = bbox2[3]
|
84 |
+
|
85 |
+
x_left = max(x1_left, x2_left)
|
86 |
+
x_right = min(x1_right, x2_right)
|
87 |
+
y_top = max(y1_top, y2_top)
|
88 |
+
y_bot = min(y1_bot, y2_bot)
|
89 |
+
|
90 |
+
inter = (x_right - x_left) * (y_bot - y_top)
|
91 |
+
if x_right < x_left or y_bot < y_top:
|
92 |
+
return 0.0
|
93 |
+
area1 = (x1_right - x1_left) * (y1_bot - y1_top)
|
94 |
+
area2 = (x2_right - x2_left) * (y2_bot - y2_top)
|
95 |
+
union = area1 + area2 - inter
|
96 |
+
|
97 |
+
IoU = inter / union
|
98 |
+
return IoU
|
99 |
+
|
100 |
+
total_people = 0
|
101 |
+
incorrect = 0
|
102 |
+
withmask = 0
|
103 |
+
withoutmask = 0
|
104 |
+
list_objects = []
|
105 |
+
isRemove = []
|
106 |
+
for i in result[1]:
|
107 |
+
temp = i
|
108 |
+
temp = np.append(temp, 1)
|
109 |
+
list_objects.append(temp)
|
110 |
+
isRemove.append(0)
|
111 |
+
|
112 |
+
for i in result[2]:
|
113 |
+
temp = i
|
114 |
+
temp = np.append(temp, 2)
|
115 |
+
list_objects.append(temp)
|
116 |
+
isRemove.append(0)
|
117 |
+
|
118 |
+
for i in result[3]:
|
119 |
+
temp = i
|
120 |
+
temp = np.append(temp, 3)
|
121 |
+
list_objects.append(temp)
|
122 |
+
isRemove.append(0)
|
123 |
+
|
124 |
+
for i in range(len(list_objects) - 1):
|
125 |
+
for j in range(i + 1, len(list_objects)):
|
126 |
+
bbox1 = [list_objects[i][0], list_objects[i][1], list_objects[i][2], list_objects[i][3]]
|
127 |
+
bbox2 = [list_objects[j][0], list_objects[j][1], list_objects[j][2], list_objects[j][3]]
|
128 |
+
if abs(IoU(bbox1, bbox2)) > 0.7:
|
129 |
+
if list_objects[i][4] > list_objects[j][4]:
|
130 |
+
isRemove[j] = 1
|
131 |
+
else:
|
132 |
+
isRemove[i] = 1
|
133 |
+
# print("IoU", abs(IoU(bbox1, bbox2)))
|
134 |
+
|
135 |
+
|
136 |
+
if list_objects[i][4] < 0.4:
|
137 |
+
isRemove[i] = 1
|
138 |
+
if list_objects[j][4] < 0.4:
|
139 |
+
isRemove[j] = 1
|
140 |
+
|
141 |
+
selected_list = []
|
142 |
+
for i in range(len(list_objects)):
|
143 |
+
if isRemove[i] == 0:
|
144 |
+
selected_list.append(list_objects[i])
|
145 |
+
|
146 |
+
for i in selected_list:
|
147 |
+
if i[5] == 1:
|
148 |
+
incorrect += 1
|
149 |
+
elif i[5] == 2:
|
150 |
+
withmask += 1
|
151 |
+
elif i[5] ==3:
|
152 |
+
withoutmask += 1
|
153 |
+
|
154 |
+
total_people += incorrect + withmask + withoutmask
|
155 |
+
|
156 |
+
img = 'demo2.png' # or img = mmcv.imread(img), which will only load it once
|
157 |
+
|
158 |
+
img = cv2.imread(img)
|
159 |
+
for i in selected_list:
|
160 |
+
if i[5] == 1:
|
161 |
+
color = (255, 0, 0)
|
162 |
+
text = "Mask weared incorrect"
|
163 |
+
elif i[5] == 2:
|
164 |
+
color = (0, 255, 0)
|
165 |
+
text = "With mask"
|
166 |
+
elif i[5] == 3:
|
167 |
+
color = (0, 0, 255)
|
168 |
+
text = "Without mask"
|
169 |
+
text += ": " + str(round(i[4], 2))
|
170 |
+
x1 = i[0]
|
171 |
+
y1 = i[1]
|
172 |
+
x2 = i[2] - 1
|
173 |
+
y2 = i[3] - 1
|
174 |
+
|
175 |
+
x1 = round(x1)
|
176 |
+
y1 = round(y1)
|
177 |
+
x2 = round(x2)
|
178 |
+
y2 = round(y2)
|
179 |
+
|
180 |
+
img = cv2.rectangle(img, (x1, y1), (x2, y2), color, 3)
|
181 |
+
img = cv2.putText(img, text, (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2)
|
182 |
+
cv2.imwrite('New_result.jpg', img)
|
models/dump.txt
ADDED
File without changes
|