summaryrefslogtreecommitdiff
path: root/renderer.py
diff options
context:
space:
mode:
authorxAlpharax <42233094+xAlpharax@users.noreply.github.com>2023-02-27 22:44:09 +0200
committerxAlpharax <42233094+xAlpharax@users.noreply.github.com>2023-02-27 22:44:09 +0200
commitbd19b46d7544ff94be0e8eaccb4e1bd18d44b996 (patch)
tree4ca021df24e00b9b8c4a219fa4dc8fea3f8d989a /renderer.py
parent6fe8a3228e3170600b68d9b19e3b8f07e51222fe (diff)
Multi-threaded renderer implemented successfully. Better error handling. Minor changes in multiple areas
Diffstat (limited to 'renderer.py')
-rw-r--r--renderer.py43
1 files changed, 33 insertions, 10 deletions
diff --git a/renderer.py b/renderer.py
index 7eaae9a..992b4ab 100644
--- a/renderer.py
+++ b/renderer.py
@@ -1,32 +1,55 @@
#!/bin/python
-### very slow step that will be assigned to multiple
-### jobs later in the development of this tool
-
### data loading
import numpy as np
-image_array = np.load("images.npy", allow_pickle=True)
+# will need some added functionality there for *.npy
+image_array = np.load("images.npy")
### progress bar
from tqdm import tqdm
+import sys
-pbar = tqdm(total = len(image_array))
+if len(sys.argv) == 1:
+ pbar = tqdm(total=len(image_array), miniters=0, smoothing=0)
-### rendering of images
+### image rendering from raw data
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, bbox_inches='tight', pad_inches=0) # dpi 258 -> 720p ; dpi 387 -> 1080p output image resolution
+ plt.savefig(name, dpi=dpi, bbox_inches='tight', pad_inches=0)
plt.close('all')
-for index in range(0, len(image_array)):
- render(index)
- pbar.update(1)
+### 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, 32):
+ ### 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')