-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffline2.py
More file actions
42 lines (35 loc) · 1.1 KB
/
offline2.py
File metadata and controls
42 lines (35 loc) · 1.1 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
# ~5:45 hrs+ (Parallel - 2 Cores)
#import os
#os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
from PIL import Image
from feature_extractor import FeatureExtractor
from pathlib import Path
import multiprocessing
import numpy as np
fe = FeatureExtractor()
img_paths = pickle.load(open('img_paths.pkl','rb'))
print("img_paths.pkl loaded")
def worker1(img_paths):
for img_path in img_paths:
print(img_path)
feature = fe.extract(img=Image.open(img_path))
feature_path = Path("./static/feature") / (img_path.stem + ".npy")
np.save(feature_path, feature)
def worker2(img_paths):
for img_path in img_paths:
print(img_path)
feature = fe.extract(img=Image.open(img_path))
feature_path = Path("./static/feature") / (img_path.stem + ".npy")
np.save(feature_path, feature)
if __name__ == "__main__":
p1 = multiprocessing.Process(target=worker1)
p2 = multiprocessing.Process(target=worker2)
p1.start()
p2.start()
p1.join()
p2.join()
p1.join()
p2.join()
n = int(50000/2)
worker1(img_paths[:n])
worker2(img_paths[n:2*n])