-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.py
56 lines (37 loc) · 1.34 KB
/
renderer.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
#!/bin/python
### data loading
import numpy as np
# TODO: will need some added functionality there for per-instance *.npy
image_array = np.load("images.npy")
### progress bar
from tqdm import tqdm
import sys
if len(sys.argv) == 1:
pbar = tqdm(total=len(image_array), miniters=0, smoothing=0)
### image rendering from raw data
import matplotlib as mlp ; mlp.use('agg') ;
import matplotlib.pyplot as plt
dpi = 258 # dpi 258 -> 720p ; dpi 387 -> 1080p output image resolution
def render(index):
pbar.update(1)
name = 'Output/neural_art_{:04d}.png'.format(index + 1)
plt.axis('off')
plt.imshow(image_array[index])
plt.savefig(name, dpi=dpi, bbox_inches='tight', pad_inches=0)
plt.close('all')
### multi-threading
import os ; n_cores = os.cpu_count() // 2 ;
if len(sys.argv) == 1:
from concurrent.futures import ThreadPoolExecutor
with ThreadPoolExecutor(max_workers=n_cores) as executor:
executor.map(render, range(0, len(image_array)))
exit()
if sys.argv[1] == "--fix":
for index in range(0, 64):
### some artifacts may have slipped
### because of the thread pool
name = 'Output/neural_art_{:04d}.png'.format(index + 1)
plt.axis('off')
plt.imshow(image_array[index])
plt.savefig(name, dpi=dpi, bbox_inches='tight', pad_inches=0)
plt.close('all')