-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre_works_test.py
65 lines (48 loc) · 1.88 KB
/
pre_works_test.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from glob import glob
from os.path import exists, join, basename, splitext
import multiprocessing as mp
# import helper_modules dir
import sys
sys.path.insert(0, './helper_modules')
import pre_works_SIFT_test as pwt
# import pre_works_BRISK_test as pwt
EXTENSIONS = [".jpg",".png"]
def get_image_paths(path='./dataset/test'):
"""Get the list of all the image files in the train directory"""
image_paths = []
image_paths.extend([join(path, basename(fname))
for fname in glob(path + "/*")
if splitext(fname)[-1].lower() in EXTENSIONS])
return image_paths
def begin_threaded_execution():
image_paths = get_image_paths()
No_of_images = len( image_paths )
No_of_cores = mp.cpu_count()
# Check if multiprocessing is really necessary
if No_of_images<No_of_cores:
No_of_cores = 1
print("MULTIPROCESSING : OFF")
else:
print("MULTIPROCESSING : ON")
print("No of cores : " + str(No_of_cores))
images_per_core = No_of_images / No_of_cores
threads = []
process_list = []
for ith_core in range(No_of_cores):
# Building processes list
start_point = images_per_core * ith_core
end_point = images_per_core * (ith_core+1)
if ith_core != No_of_cores-1:
sub_array = image_paths[start_point:end_point]
else:
sub_array = image_paths[start_point:]
print("Beginning execution of thread " + str(ith_core) + " with " + str(len(sub_array)) + " images")
process_list.append(mp.Process(target=pwt.process_images, args=(sub_array, ith_core)))
for p in process_list:
p.start()
for p in process_list:
p.join()
print("Processing done, saving paths.")
pwt.save_paths( image_paths )
print(str( len(image_paths) ) + " images processed. Proceed to testing.")
begin_threaded_execution()