-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffline.py
31 lines (28 loc) · 904 Bytes
/
offline.py
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
import glob
import os
import pickle
from PIL import Image
from feature_extractor import FeatureExtractor
fe = FeatureExtractor()
print("Extracting feature vectors from gallery images.")
f=[]
i=1
for img_path in sorted(glob.glob('static/img/*.jpg')):
img = Image.open(img_path) # PIL image
feature = fe.extract(img)
#feature_path = 'static/feature/' + os.path.splitext(os.path.basename(img_path))[0] + '.pkl'
f.append(feature)
if i %100 ==0:
print(i)
i+=1
print(len(f))
pickle.dump(f, open('static/feature/features.pkl', 'wb'))
print("Feature extraction finished.")
"""
for img_path in sorted(glob.glob('static/img/*.jpg')):
print(img_path)
img = Image.open(img_path) # 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'))
"""