-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (27 loc) · 1.21 KB
/
Copy pathmain.py
File metadata and controls
40 lines (27 loc) · 1.21 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
from pathlib import Path
from PIL.Image import Image as Img
from cppn import CPPN
from render import render_image
import datetime
import random
PRESETS = {'xxxsmall':32, 'xxsmall':64, 'xsmall':128, 'small':256, 'medium':512, 'large':1024, 'huge':2048}
OUTPUT_CHANNELS = {'rgb':3, 'grayscale':1}
def main():
output_folder = 'output'
size = PRESETS['large']
color_mode = 'rgb'
Path(output_folder).mkdir(exist_ok=True)
tileable = True
z_dim = 4
spatial_dim = 4 if tileable else 3
sigma = random.uniform(0.3, 3)
model = CPPN(input_dim=spatial_dim + z_dim, weight_sigma=sigma, output_channels=OUTPUT_CHANNELS[color_mode])
r_strength = random.uniform(0.0, 10.0) if not tileable else 1.0
generate_images(model, size, size, output_folder, 1, tileable, r_strength)
def generate_images(model, width, height, output_folder: str, quantity: int, tileable: bool, r_strength: float):
for i in range(quantity):
image: Img = render_image(model, width, height, r_strength=r_strength, tileable=tileable)
img_name = str(datetime.datetime.now().strftime('%Y%m%d_%H%M%S')) + f'{i:02d}'
image.save(f'{output_folder}/image-{img_name}.png')
if __name__ == '__main__':
main()