forked from matsui528/sis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffline_multi.py
More file actions
47 lines (40 loc) · 1.02 KB
/
offline_multi.py
File metadata and controls
47 lines (40 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#
# 不要用这个版本导入数据,最终运行结果千差万别 (使用 offline.py )
#
import glob
import os
import pickle
from PIL import Image
from feature_extractor import FeatureExtractor
from threading import Thread
import threading
import time
fe = FeatureExtractor()
def GetFeature(imgPath):
try:
img = Image.open(imgPath) # PIL image
feature = fe.extract(img)
feature_path = 'static/feature/' + os.path.splitext(os.path.basename(img_path))[0] + '.pkl'
pickle.dump(feature, open(feature_path, 'wb'))
pass
except Exception as e:
print(e)
semlock.release()
idx = 0
semlock = threading.BoundedSemaphore(50)
startTime = time.time()
for img_path in sorted(glob.glob('static/img/*.jpg')):
try:
idx = idx+1
nowTIme = time.time()
detTime = nowTIme - startTime
print(img_path, idx, threading.activeCount())
if detTime > 0:
print('qps', idx / detTime)
semlock.acquire()
t = Thread(target=GetFeature, args=(img_path,))
t.start()
# GetFeature(img_path)
pass
except Exception as e:
print(e)