|
a |
|
b/10x/launcher.py |
|
|
1 |
# python launcher.py N |
|
|
2 |
# Spawns N processes of batch.py, dividing images in ./data into N batches |
|
|
3 |
# Processes are run in background |
|
|
4 |
|
|
|
5 |
import os |
|
|
6 |
import sys |
|
|
7 |
import pickle |
|
|
8 |
from numpy import ceil |
|
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
# Remove any old pickle files |
|
|
13 |
L = os.listdir(".") |
|
|
14 |
for l in L : |
|
|
15 |
if l.endswith(".p") : |
|
|
16 |
os.remove(l) |
|
|
17 |
|
|
|
18 |
|
|
|
19 |
# Create results directory if it doesn't exist |
|
|
20 |
if not os.path.exists("results/") : |
|
|
21 |
os.makedirs("results/") |
|
|
22 |
|
|
|
23 |
|
|
|
24 |
# Read files |
|
|
25 |
files = [] |
|
|
26 |
directory = "data/" |
|
|
27 |
for f in os.listdir(directory) : |
|
|
28 |
if f.endswith(".jpg") : # if it's a jpg |
|
|
29 |
if not f.endswith("_processed.jpg") : # and isn't a processed image |
|
|
30 |
files.append(directory + f) # then add it to the list to be processed |
|
|
31 |
|
|
|
32 |
|
|
|
33 |
# Confirm files |
|
|
34 |
print "%d files, requires %d simultaneous runs." % (len(files), ceil(float(len(files)) / float(sys.argv[1]))) |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
|
|
|
38 |
# Generate a list of files for each batch.py to process, and spawn processes |
|
|
39 |
for i in range(int(sys.argv[1])) : |
|
|
40 |
F = open("filelist%i.p" % i, "w") |
|
|
41 |
l = [f for f in files[i :: int(sys.argv[1])]] |
|
|
42 |
pickle.dump(l, F) |
|
|
43 |
F.close() |
|
|
44 |
#os.system("python batch.py %i &" % i) |