-
Notifications
You must be signed in to change notification settings - Fork 1
/
dreamcli.py
1089 lines (950 loc) · 35.2 KB
/
dreamcli.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 4 11:45:48 2020
@author: M.K.
"""
import os as os
import settings as settings
import utils as utils
import dreamer as d
import json
import numpy as np
image_dir='./Images'
settings_dir='./Settings'
renderer_dir='./Settings/Renderer'
longline='------------------------'
mediumline='-----------'
shortline='-----'
"""
Input Parser
"""
def parse_input(lower=0, upper=1, msg="Enter selection: ", t="int"):
correct_input=False
while correct_input==False:
i=input(msg)
if len(i)>0:
if t=="int":
try:
c_i=int(i)
if c_i in range(lower, upper+1):
correct_input=True
else:
print('Input out of bounds: Input must be between '+str(lower)+" and "+str(upper))
except ValueError:
print('Invalid input: ValueError. Input must be a number e.g. 1')
elif t=='float':
try:
c_i=float(i)
if c_i <= upper and c_i>=lower:
correct_input=True
else:
print('Input out of bounds: Input must be between '+str(lower)+" and "+str(upper))
except ValueError:
print('Invalid input: ValueError. Input must be a number e.g. 0.5')
else:
c_i=i
if " " in c_i:
print('Input contains a blank space. Please use "_" instead to avert possible errors.')
else:
correct_input=True
else:
print('Invalid input: No input')
return c_i
def parse_yn(msg='Placeholder'):
correct_input=False
r_yn=False
while correct_input==False:
yn=input(msg)
if yn=="y" or yn=="Y":
correct_input=True
r_yn=True
elif yn=="n" or yn=="N":
correct_input=True
else:
print('Invalid input: Only y/Y (yes) and n/N (no) accepted')
return r_yn
def parse_or(msg='Enter "o" to overwrite or "r" to rename:'):
correct_input=False
overwrite=False
while correct_input==False:
yn=input(msg)
if yn=="o" or yn=="O":
correct_input=True
overwrite=True
elif yn=="r" or yn=="R":
correct_input=True
else:
print('Invalid input: Only o/O (letter) and r/R accepted')
return overwrite
"""
Main Menu
"""
def main_menu():
print(longline)
print(shortline+'Main menu')
print(longline)
if len(settings.orig_image)>0:
print('Selected image: '+settings.orig_image_name)
print('Image size:'+str(settings.orig_image.shape[0])+"x"+str(settings.orig_image.shape[1]))
else:
print('No image selected')
print('Settings: %s'%settings.c_settings['name'])
print('Renderer: %d Renderer selected'%len(settings.c_settings['renderers']))
# settings=settings.Setting()
# image_dir='./Images'
# settings_dir='./Settings'
print(longline)
##Print
print('0: Select image \n1: Edit Settings \n2: Edit Renderer \n3: Continue(deepdream Image)')
print(longline)
selection=parse_input(0, 3, 'Enter corrosponding number to navigate: ')
if selection==0:
settings.orig_img=select_image_menu()
if selection==1:
change_settings()
if selection==2:
renderer_menu()
if selection==3:
print(longline)
if len (settings.orig_image)>0:
if len(settings.c_settings['renderers'])>0:
dream()
else:
print('No renderer selected! Add a renderer to dream the image')
else:
print('No Image selected')
print(longline)
if not selection ==4:
main_menu()
"""
Image functions
"""
def load_jpg():
print('0: back')
#Lists of files
jpgs=[]
jpgs_names=[]
all_files=os.listdir(image_dir)
#Check for .jpg
jpg_index=0
for i in range(len(all_files)):
if all_files[i].endswith(".jpg") or all_files[i].endswith(".JPEG"):
print(str(jpg_index+1)+": "+all_files[i])
jpgs.append(os.path.join(image_dir, all_files[i]))
jpgs_names.append(all_files[i])
jpg_index+=1
#Input
selection=parse_input(0, len(jpgs))
if selection >0:
return utils.load_image(jpgs[selection-1]), jpgs_names[selection-1]
else:
return [], ""
def select_image_menu():
print('0: back')
#Lists of files
jpgs=[]
jpgs_names=[]
all_files=os.listdir(image_dir)
#Check for .jpg
jpg_index=0
for i in range(len(all_files)):
if all_files[i].endswith(".jpg") or all_files[i].endswith(".JPEG"):
print(str(jpg_index+1)+": "+all_files[i])
jpgs.append(os.path.join(image_dir, all_files[i]))
jpgs_names.append(all_files[i])
jpg_index+=1
#Input
selection=parse_input(0, len(jpgs))
if selection >0:
settings.orig_image=select_image(jpgs[selection-1])
settings.orig_image_name=jpgs_names[selection-1]
def select_image(image):
t_img=utils.load_image(image)
return t_img
"""
Settings Menu
"""
def change_settings():
print(longline)
print(shortline+'Settings menu')
print(longline)
print('0: Back')
print('1: Name: %s'%settings.c_settings['name'])
print('2: Iterations: %d'%settings.c_settings['iterations'])
print('3: Octaves: %d'%settings.c_settings['octaves'])
print('4: Octave scale: %.2f'%settings.c_settings['octave_scale'])
print('5: Iteration descent: %d'%settings.c_settings['iteration_descent'])
print('6: Background menu. Currently activated: '+str(settings.c_settings['save_gradient']))
print('7: Global color correction: '+str(settings.c_settings['color_correction']))
print('8: Renderer menu. Current number of renderer: %d'%len(settings.c_settings['renderers']))
print('9: New Settings')
print('10: Load Settings')
print('11: Save Settings')
print(longline)
selection=parse_input(0, 11, msg="Enter selection:")
switcher={1:edit_setting_name,
2:edit_iterations,
3:edit_octaves,
4:edit_octave_scale,
5:edit_iteration_descent,
6:edit_background,
7:edit_global_cc,
8:renderer_menu,
9:new_settings,
10:load_settings_menu,
11:save_settings}
if selection >0:
switcher[selection]()
change_settings()
def edit_setting_name():
print(mediumline)
print('Current name: %s'%settings.c_settings['name'])
print(mediumline)
print('0: Back \n1: Change Name')
print(mediumline)
selection=parse_input(0, 1, 'Enter selection:')
if selection==1:
n=parse_input(0, 2,'Enter Settings name:', t='string')
settings.c_settings['name']=n
def edit_iterations():
print(mediumline)
print('Current iterations: '+str(settings.c_settings['iterations']))
print(mediumline)
print('0: Back \n1: Change iterations')
print(mediumline)
selection=parse_input(0, 1, 'Enter selection:')
if selection==1:
i=parse_input(0, 10000, 'Enter new Iteration no.:')
settings.c_settings['iterations']=i
def edit_octaves():
print(mediumline)
print('Current octaves: '+str(settings.c_settings['octaves']))
print(mediumline)
print('0: Back \n1: Change Octaves')
print(mediumline)
selection=parse_input(0,1)
if selection ==1:
o=parse_input(1, 200, 'Enter Octave no.:')
settings.c_settings['octaves']=o
def edit_octave_scale():
print(mediumline)
print('Current octave_scale: '+str(settings.c_settings['octave_scale']))
print(mediumline)
print('0: Back \n1: Change octave_scale')
print(mediumline)
selection=parse_input(0,1, 'Enter selection:')
if selection ==1:
o=parse_input(1, 50, 'Enter Octave scale (Recommended: between 1.1 and 2.0):', t='float')
settings.c_settings['octave_scale']=o
def edit_iteration_descent():
print(mediumline)
print('Current iteration_descent: '+str(settings.c_settings['iteration_descent']))
print(mediumline)
print('0: Back \n1: Change iteration_descent')
print(mediumline)
selection=parse_input(0,1)
if selection==1:
max_descent=int(settings.c_settings['iterations']/settings.c_settings['octaves'])
i=parse_input(-100, max_descent, "Enter Iteration descent (Can not be higher than Iterations/octaves=%d):"%max_descent )
settings.c_settings['iteration_descent']=i
def edit_background_color():
print(shortline)
print('Current background color: '+str(settings.c_settings['background']))
print(shortline)
print('0: Back \n1: Change background color')
print(shortline)
selection=parse_input(0,1)
if selection==1:
r=parse_input(0,255, 'Enter Red value of background:')
g=parse_input(0,255, 'Enter Green value of background:')
b=parse_input(0,255, 'Enter Blue value of background:')
settings.c_settings['background']=[r,g,b]
def edit_background():
print(mediumline)
print('Write gradient onto empty background: '+str(settings.c_settings['save_gradient']))
print('Background color: '+str(settings.c_settings['background']))
print(mediumline)
print('0: Back \n1: Activate/Deactivate if gradient is saved onto background \n2: Change background color')
print(mediumline)
selection=parse_input(0, 2)
if selection==1:
print(shortline)
print('0: Back \n1: Activate \n2: Deactivate')
print(shortline)
selection=parse_input(0,2)
if selection==0:
edit_background()
if selection==1:
settings.c_settings['save_gradient']=True
edit_background()
if selection==2:
settings.c_c_settings['save_gradient']=False
edit_background()
if selection==2:
edit_background_color()
edit_background()
def new_settings():
settings.c_settings=settings.get_default_setting()
"""
Renderer
"""
def edit_global_cc():
print(mediumline)
print('Global color correction: '+str(settings.c_settings['color_correction']))
print('Method: '+str(settings.c_settings['cc_vars'][0]))
print('RGB multiplier: '+str(settings.c_settings['cc_vars'][1:]))
print(mediumline)
print('0: Back \n1: Activate multiplier \n2: Deactivate multiplier\n3: Edit color correction values')
selection=parse_input(0,3)
if selection==1:
settings.c_settings['color_correction']=True
edit_global_cc()
if selection==2:
settings.c_settings['color_correction']=False
edit_global_cc()
if selection==3:
settings.c_settings=edit_cc_vars(settings.c_settings)
edit_global_cc()
def renderer_menu():
print(longline)
print(shortline+'Renderer menu')
print(longline)
if len(settings.c_settings['renderers'])>0:
print('Current renderer:')
for i in range(0, len(settings.c_settings['renderers'])):
print("-"+settings.c_settings['renderers'][i]['name'])
else:
print('-No Renderer selected-')
print(longline)
print('0: Back \n1: Edit renderer \n2: New Renderer \n3: Load Renderer \n4: Remove Renderer \n5: Save Renderer')
print(longline)
selection=parse_input(0,5, 'Enter selection: ')
if selection ==1:
print(mediumline)
print('Select Renderer to edit:')
print(shortline)
print('0: Back')
for i in range(0, len(settings.c_settings['renderers'])):
print(str(i+1)+": "+settings.c_settings['renderers'][i]['name']+' | '+
settings.c_settings['renderers'][i]['layer']+
'['+str(settings.c_settings['renderers'][i]['f_channel'])
+":"+str(settings.c_settings['renderers'][i]['l_channel'])+"]")
print(shortline)
selected=parse_input(0, len(settings.c_settings['renderers'])+1)
if selected>0:
settings.c_settings['renderers'][selected-1]=edit_renderer_settings(settings.c_settings['renderers'][selected-1])
if selection==2:
add_renderer()
if selection==3:
load_renderer_menu()
if selection==4:
remove_renderer_menu()
if selection==5:
save_renderer_menu()
if not selection==0:
renderer_menu()
def remove_renderer_menu():
print(mediumline)
print('Select Renderer to remove:')
print(shortline)
print('0: Back')
for i in range(0, len(settings.c_settings['renderers'])):
print(str(i+1)+": "+settings.c_settings['renderers'][i]['name']+' | '+
settings.c_settings['renderers'][i]['layer']+
'['+str(settings.c_settings['renderers'][i]['f_channel'])
+":"+str(settings.c_settings['renderers'][i]['l_channel'])+"]")
print(shortline)
selected=parse_input(0, len(settings.c_settings['renderers'])+1)
if selected>0:
del settings.c_settings['renderers'][selected-1]
def edit_r_name(r):
print(mediumline)
print('Current name: '+str(r['name']))
print(mediumline)
print('0: Back \n1: Change name')
print(mediumline)
selection = parse_input(0,1)
if selection==1:
n=parse_input(0, 0,'Enter name:', t='string')
r['name']=n
return r
def add_renderer():
settings.c_settings['renderers'].append(settings.get_default_renderer())
settings.c_settings['renderers'][-1]=select_layer_menu(settings.c_settings['renderers'][-1])
settings.c_settings['renderers'][-1]=edit_renderer_settings(settings.c_settings['renderers'][-1])
def select_layer_menu(r):
print(mediumline)
print('Select layer:')
ll=get_layer_list()
for i in range(len(ll)):
print(str(i)+": "+ll[i][0]+" Channels: "+str(ll[i][1]))
selection=parse_input(0, len(ll))
r['layer']=(ll[selection][0])
r['l_channel']=ll[selection][1]
r['max_channel']=ll[selection][1]
return r
def edit_layer(r):
print(mediumline)
print('Current layer: '+str(r['layer']))
print(mediumline)
print('0: Back \n1: Change layer')
selection=parse_input(0,2)
if selection ==1:
r=select_layer_menu(r)
return r
def edit_channels(r):
print(mediumline)
print('Current channels: First channel: '+str(r['f_channel'])+" Last channel: "+str(r['l_channel']))
print(mediumline)
print('0: Back \n1: Change channels')
print(mediumline)
selection=parse_input(0, 2)
if selection ==1:
f=parse_input(0, r['max_channel']-1, "Enter first channel no. (Must be between 0 and "+str(r['max_channel']-1)+"):")
l=parse_input(f+1, r.max_channel,"Enter last channel no. (Must be between "+str(f+1)+" and "+str(r['max_channel'])+"):")
r['f_channel']=f
r['l_channel']=l
return r
def edit_squared(r):
print(mediumline)
print('Squared gradient activated: '+str(r['squared']))
print(mediumline)
print('0: Back \n1: Activate squared gradient \n2: Deactivate squared gradient')
print(mediumline)
selection=parse_input(0,3)
if selection==1:
r['squared']=True
if selection==2:
r['squared']=False
return r
def edit_step_size(r):
print(mediumline)
print('Current step_size: '+str(r['step_size']))
print(mediumline)
print('0: Back \n1: Edit step_size' )
print(mediumline)
selection=parse_input(0,2)
if selection ==1:
sz=parse_input(-100, 100,'Enter step size (Recommended: between 2 and 0.01): ', t='float')
r['step_size']=sz
return r
def edit_cropped(r):
print(mediumline)
print('Cropped renderer activated: '+str(r['cropped']))
print('Boundraries: '+str(r['boundraries']))
print(mediumline)
print('0: Back \n1: Activate cropped renderer \n2: Deactivate cropped renderer\n3: Edit boundraries')
print(mediumline)
selection=parse_input(0,3)
if selection ==1:
r['cropped']=True
if selection ==2:
r['cropped']=False
if selection ==3:
r=edit_boundraries(r)
r=edit_cropped(r)
return r
def edit_boundraries(r):
print(shortline)
print('All values most be between 0 and 1 on both axes starting on the top left corner (If this renderer should e.g. only render the bottom half choose x_min=0,x_max=1, y_min=0.5, y_max=1' )
print(shortline)
x_min=parse_input(0, 1,'Enter x_min:', t='float')
x_max=parse_input(x_min, 1,'Enter x_max:', t='float')
y_min=parse_input(0, 1,'Enter y_min:', t='float')
y_max=parse_input(y_min,1,'Enter y_max:', t='float')
r['boundraries']=[[x_min,x_max],[y_min, y_max]]
return r
def edit_mask(r):
print(mediumline)
print('Mask activated: '+str(r['masked']))
print('Mask:' +str(r['mask_name']))
print(mediumline)
print('0: Back \n1: Activate Mask \n2: Deactivate Mask \n3: Load mask \n4: Remove mask')
print(mediumline)
selection=parse_input(0, 4)
if selection==1 or selection==2:
r['masked']=not r['masked']
r=edit_mask(r)
if selection==3:
r['mask'],r['mask_name']=load_jpg()
r=edit_mask(r)
if selection ==4:
r['mask']=[]
r['mask_name']=''
r['maksed']=False
r=edit_mask(r)
if len(r['mask_name'])==0:
r['masked']=False
######set masked to false if mask is empty
return r
def edit_rotate(r):
print(mediumline)
print('Current rotation: %d° right'%(r['rotation']*90))
print(mediumline)
print('0: Back \n1: Rotate 0° right (deactivate rotation) \n2: Rotate 90° right\n3: Rotate 180° right \n4: Rotate 270° right')
print(mediumline)
selection=parse_input(0,4)
if selection>0:
if selection==1:
r['rotation']=0
r['rotate']=False
else:
r['rotation']=selection-1
r['rotate']=True
return r
def edit_tile_size(r):
print(mediumline)
print('Current tile size: '+str(r['tile_size']))
print(mediumline)
print('0: Back \n1: Edit tile size')
print(mediumline)
selection=parse_input(0,1)
if selection==1:
tz=parse_input(1, 10000, 'Enter Tile size (should be around 300):')
r['tile_size']=tz
return r
def edit_renderer_cc(r):
print(mediumline)
print('Renderer specific color correction: '+str(r['color_correction']))
print('Method: '+str(r['cc_vars'][0]))
print('RGB multiplier: '+str(r['cc_vars'][1:]))
print(mediumline)
print('0: Back \n1: Activate multiplier \n2: Deactivate multiplier\n3: Edit color correction values')
selection=parse_input(0,3)
if selection==1:
r['color_correction']=True
r=edit_renderer_cc(r)
if selection==2:
r=edit_renderer_cc(r)
r['color_correction']=False
if selection==3:
r=edit_cc_vars(r)
r=edit_renderer_cc(r)
return r
def edit_cc_vars(rs):
print(shortline)
print('Current Method: '+str(rs['cc_vars'][0]))
print('Current RGB multiplier: '+str(rs['cc_vars'][1:]))
print(shortline)
print('0: Back \n1: Edit Method \n2: Edit RGB multiplier')
print(shortline)
selection=parse_input(0,2)
if selection==1:
print('0: Back \n1: Simple Grayscale correction \n2: Retaining original colors \n3: Linear correction')
print(shortline)
new_selection=parse_input(0,3)
if selection>0:
rs['cc_vars'][0]=new_selection
rs=edit_cc_vars(rs)
if selection ==2:
print(shortline)
print('Current color multiplier: '+str(rs['cc_vars'][1:]))
print(shortline)
print('Enter the color multiplier (mult) for the Red, Green and Blue channel (r,g,b). Recommended values are between -5.0 and 5.0')
red=parse_input(-100,100,'Enter r_mult:', t='float')
green=parse_input(-100,100,'Enter g_mult:', t='float')
blue=parse_input(-100,100,'Enter b_mult:', t='float')
rs['cc_vars'][1:]=[red,green,blue]
rs=edit_cc_vars(rs)
return rs
def edit_render_x_iteration(r):
print(mediumline)
print('Currently rendering every %d iteration (1=render every Iteration)'%r['render_x_iteration'])
print(mediumline)
print('0: back \n1: Edit')
print(mediumline)
selection=parse_input(0,1)
if selection ==1:
x=parse_input(0, 10000, "Enter new value:")
r['render_x_iteration']=x
return r
def edit_renderer_settings(r):
print(longline)
print(shortline+'Renderer')
print(longline)
print('0: Back')
print('1: Name: %s'%r['name'])
print('2: Layer: %s'%r['layer'])
print('3: Channels: '+str(r['f_channel'])+"-"+str(r['l_channel']))
print('4: Squared: '+str(r['squared']))
print('5: Step size: %.5f'%r['step_size'])
if r['cropped']:
print('6: Cropped: Activated with Boundraries: '+str(r.boundraries))
else:
print('6: Cropped: '+str(r['cropped']))
if r['masked']:
print('7: Masked gradient activated ')
else:
print('7: Masked gradient deactivated')
if r['rotate']:
print('8: Rotation. Activated with '+ str(r['rotation']*90)+'° right')
else:
print('8: Rotation deactivated')
print('9: Tile size: %d'%r['tile_size'])
if r['color_correction']:
print('10: Renderer specific color correction activated ')
else:
print('10: Color correction deactivated')
print('11: Render every %d iteration'%r['render_x_iteration'])
print('12: Save current Renderer to file')
print(longline)
selection=parse_input(0,12, 'Enter selection:')
switcher={1:edit_r_name,
2:edit_layer,
3:edit_channels,
4:edit_squared,
5:edit_step_size,
6:edit_cropped,
7:edit_mask,
8:edit_rotate,
9:edit_tile_size,
10:edit_renderer_cc,
11:edit_render_x_iteration,
12:save_renderer}
if selection>0:
r=switcher[selection](r)
edit_renderer_settings(r)
return r
def save_settings():
t_name=settings.c_settings['name']+'_s.json'
file=os.path.join(settings_dir, t_name)
overwrite=False
while os.path.exists(file) and overwrite ==False:
print(t_name+ " already exists. Do you want to overwrite it or rename your current setting?")
overwrite=parse_or()
if not overwrite:
settings.c_settings['name']=parse_input(msg="Enter new name:", t='string')
t_name=settings.c_settings['name']+'_s.json'
file=os.path.join(settings_dir, t_name)
for r in settings.c_settings['renderers']:
if not r['mask_name']=='':
r['mask']=r['mask'].tolist()
with open(file, "w") as fp:
json.dump(settings.c_settings, fp, indent=4)
for r in settings.c_settings['renderers']:
if not r['mask_name']=='':
r['mask']=np.array(r['mask'])
def load_settings(name):
file_path = os.path.join(settings_dir, name)
file_path=name
if os.path.exists(file_path):
with open(file_path, 'r') as fp:
t_settings=json.load(fp)
"""
Backwards compatibility:
Get default settings
For key, value pair write settings to default settings
For layer in t_settings:
get default layer
for key, value pair writte renderer-settings to default renderer
"""
settings.c_settings=t_settings
for r in settings.c_settings['renderers']:
if not r['mask_name']=='':
r['mask']=np.array(r['mask'])
else:
print('File not found. Falling back to default settings')
t_settings=settings.get_default_setting()
return t_settings
def load_settings_menu():
print(mediumline)
print("0: Back")
ddss=[] #All .dds-files in folder
dds_names=[]
for file in os.listdir(settings_dir):
if file.endswith('_s.json'):
ddss.append(os.path.join(settings_dir, file))
dds_names.append(file)
for i in range(len(dds_names)):
print(str(i+1)+": "+dds_names[i])
print(mediumline)
selection=parse_input(0, len(dds_names), "Select File to load:")
if selection>0:
settings.c_settings['renderers']=[]
settings.c_settings['r_names']=[]
settings.c_settings=load_settings(ddss[selection-1])
def load_renderer_menu():
#change variable names2
print(mediumline)
print("0: Back")
ddrs=[]
ddr_names=[]
for file in os.listdir(renderer_dir):
if file.endswith('_r.json'):
ddrs.append(os.path.join(renderer_dir, file))
ddr_names.append(file)
for i in range(len(ddr_names)):
print(str(i+1)+": "+ddr_names[i])
print(mediumline)
selection=parse_input(0, len(ddr_names), "Select File to load:")
if selection>0:
settings.c_settings['renderers'].append(load_renderer(ddrs[selection-1]))
def save_renderer(t_renderer):
t_name=t_renderer['name']+'_r.json'
filepath=os.path.join(renderer_dir, t_name)
overwrite=False
while os.path.exists(filepath) and overwrite==False:
print(t_name+ " already exists. Do you want to overwrite it or rename your current Renderer?")
overwrite=parse_or()
if not overwrite:
t_renderer['name']=parse_input(msg="Enter new name:", t='string')
t_name=t_renderer['name']+'_r.json'
filepath=os.path.join(renderer_dir, t_name)
if not t_renderer['mask_name'] =='':
t_renderer['mask']=t_renderer['mask'].tolist()
with open(filepath, "w") as fp:
json.dump(t_renderer, fp, indent=4)
if not t_renderer['mask_name'] =='':
t_renderer['mask']=np.array(t_renderer['mask'])
return t_renderer
def save_renderer_menu():
print(mediumline)
print('Select Renderer to save:')
print(shortline)
print('0: Back')
for i in range(0, len(settings.c_settings['renderers'])):
print(str(i+1)+": "+settings.c_settings['renderers'][i]['name'] +' | '+
settings.c_settings['renderers'][i]['layer']+
'['+str(settings.c_settings['renderers'][i]['f_channel'])
+":"+str(settings.c_settings['renderers'][i]['l_channel'])+"]")
print(shortline)
selected=parse_input(0, len(settings.c_settings['renderers'])+1)
if selected>0:
settings.c_settings['renderers'][selected-1]=save_renderer(settings.c_settings['renderers'][selected-1])
def load_renderer(name):
file_path =name
print(file_path)
if os.path.exists(file_path):
with open(file_path, 'r') as fp:
t_renderer=json.load(fp)
"""
Backwards compatibility as in load_settings()
"""
else:
print('File not found. Adding default renderer')
t_renderer=settings.get_default_renderer()
if not t_renderer['mask_name'] =='':
t_renderer['mask']=np.array(t_renderer['mask'])
return t_renderer
"""
Dream
"""
def dream():
d.sess.close()
out_name=parse_input(msg='Enter output Filename. Will be overwritten if it already exists: ', t='string')
d.sess = d.tfc.InteractiveSession(graph=d.graph)
d.dream_image(settings.orig_image, settings.c_settings, out_name)
d.sess.close()
"""
Data
"""
def get_layer_list():
ll=[['conv2d0_pre_relu/conv', 64],
['conv2d0_pre_relu', 64],
['conv2d0', 64],
['maxpool0', 64],
['localresponsenorm0', 64],
['conv2d1_pre_relu/conv', 64],
['conv2d1_pre_relu', 64],
['conv2d1', 64],
['conv2d2_pre_relu/conv', 192],
['conv2d2_pre_relu', 192],
['conv2d2', 192],
['localresponsenorm1', 192],
['maxpool1', 192],
['mixed3a_1x1_pre_relu/conv', 64],
['mixed3a_1x1_pre_relu', 64],
['mixed3a_1x1', 64],
['mixed3a_3x3_bottleneck_pre_relu/conv', 96],
['mixed3a_3x3_bottleneck_pre_relu', 96],
['mixed3a_3x3_bottleneck', 96],
['mixed3a_3x3_pre_relu/conv', 128],
['mixed3a_3x3_pre_relu', 128],
['mixed3a_3x3', 128],
['mixed3a_5x5_bottleneck_pre_relu/conv', 16],
['mixed3a_5x5_bottleneck_pre_relu', 16],
['mixed3a_5x5_bottleneck', 16],
['mixed3a_5x5_pre_relu/conv', 32],
['mixed3a_5x5_pre_relu', 32],
['mixed3a_5x5', 32],
['mixed3a_pool', 192],
['mixed3a_pool_reduce_pre_relu/conv', 32],
['mixed3a_pool_reduce_pre_relu', 32],
['mixed3a_pool_reduce', 32],
['mixed3a', 256],
['mixed3b_1x1_pre_relu/conv', 128],
['mixed3b_1x1_pre_relu', 128],
['mixed3b_1x1', 128],
['mixed3b_3x3_bottleneck_pre_relu/conv', 128],
['mixed3b_3x3_bottleneck_pre_relu', 128],
['mixed3b_3x3_bottleneck', 128],
['mixed3b_3x3_pre_relu/conv', 192],
['mixed3b_3x3_pre_relu', 192],
['mixed3b_3x3', 192],
['mixed3b_5x5_bottleneck_pre_relu/conv', 32],
['mixed3b_5x5_bottleneck_pre_relu', 32],
['mixed3b_5x5_bottleneck', 32],
['mixed3b_5x5_pre_relu/conv', 96],
['mixed3b_5x5_pre_relu', 96],
['mixed3b_5x5', 96],
['mixed3b_pool', 256],
['mixed3b_pool_reduce_pre_relu/conv', 64],
['mixed3b_pool_reduce_pre_relu', 64],
['mixed3b_pool_reduce', 64],
['mixed3b', 480],
['maxpool4', 480],
['mixed4a_1x1_pre_relu/conv', 192],
['mixed4a_1x1_pre_relu', 192],
['mixed4a_1x1', 192],
['mixed4a_3x3_bottleneck_pre_relu/conv', 96],
['mixed4a_3x3_bottleneck_pre_relu', 96],
['mixed4a_3x3_bottleneck', 96],
['mixed4a_3x3_pre_relu/conv', 204],
['mixed4a_3x3_pre_relu', 204],
['mixed4a_3x3', 204],
['mixed4a_5x5_bottleneck_pre_relu/conv', 16],
['mixed4a_5x5_bottleneck_pre_relu', 16],
['mixed4a_5x5_bottleneck', 16],
['mixed4a_5x5_pre_relu/conv', 48],
['mixed4a_5x5_pre_relu', 48],
['mixed4a_5x5', 48],
['mixed4a_pool', 480],
['mixed4a_pool_reduce_pre_relu/conv', 64],
['mixed4a_pool_reduce_pre_relu', 64],
['mixed4a_pool_reduce', 64],
['mixed4a', 508],
['mixed4b_1x1_pre_relu/conv', 160],
['mixed4b_1x1_pre_relu', 160],
['mixed4b_1x1', 160],
['mixed4b_3x3_bottleneck_pre_relu/conv', 112],
['mixed4b_3x3_bottleneck_pre_relu', 112],
['mixed4b_3x3_bottleneck', 112],
['mixed4b_3x3_pre_relu/conv', 224],
['mixed4b_3x3_pre_relu', 224],
['mixed4b_3x3', 224],
['mixed4b_5x5_bottleneck_pre_relu/conv', 24],
['mixed4b_5x5_bottleneck_pre_relu', 24],
['mixed4b_5x5_bottleneck', 24],
['mixed4b_5x5_pre_relu/conv', 64],
['mixed4b_5x5_pre_relu', 64],
['mixed4b_5x5', 64],
['mixed4b_pool', 508],
['mixed4b_pool_reduce_pre_relu/conv', 64],
['mixed4b_pool_reduce_pre_relu', 64],
['mixed4b_pool_reduce', 64],
['mixed4b', 512],
['mixed4c_1x1_pre_relu/conv', 128],
['mixed4c_1x1_pre_relu', 128],
['mixed4c_1x1', 128],
['mixed4c_3x3_bottleneck_pre_relu/conv', 128],
['mixed4c_3x3_bottleneck_pre_relu', 128],
['mixed4c_3x3_bottleneck', 128],
['mixed4c_3x3_pre_relu/conv', 256],
['mixed4c_3x3_pre_relu', 256],
['mixed4c_3x3', 256],
['mixed4c_5x5_bottleneck_pre_relu/conv', 24],
['mixed4c_5x5_bottleneck_pre_relu', 24],
['mixed4c_5x5_bottleneck', 24],
['mixed4c_5x5_pre_relu/conv', 64],
['mixed4c_5x5_pre_relu', 64],
['mixed4c_5x5', 64],
['mixed4c_pool', 512],
['mixed4c_pool_reduce_pre_relu/conv', 64],
['mixed4c_pool_reduce_pre_relu', 64],
['mixed4c_pool_reduce', 64],
['mixed4c', 512],
['mixed4d_1x1_pre_relu/conv', 112],
['mixed4d_1x1_pre_relu', 112],
['mixed4d_1x1', 112],
['mixed4d_3x3_bottleneck_pre_relu/conv', 144],
['mixed4d_3x3_bottleneck_pre_relu', 144],
['mixed4d_3x3_bottleneck', 144],
['mixed4d_3x3_pre_relu/conv', 288],
['mixed4d_3x3_pre_relu', 288],
['mixed4d_3x3', 288],