forked from hctomkins/caffe-gui-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CaffeNodes.py
1867 lines (1569 loc) · 67.4 KB
/
CaffeNodes.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
bl_info = {
"name": "Caffe Nodes",
"category": "Object",
}
import bpy
import subprocess
from bpy.types import NodeTree, Node, NodeSocket
def calcsize(self, context,axis='x'):
'''NOTE - this function works out the dimensions of an image by the time it has reached a certain layer.
It traverses all the layers, builds up several lists about the properties of each layer, then computes the
size up to a given layer.'''
x = 0.0
node = self
# print (node.bl_idname)
try:
node.inputs[0].links[0].from_node
except IndexError:
return 0
#These are the lists to be populated
kernelsizes = []
strides = []
paddings = []
poolstrides = []
poolsizes = []
offsets = []
fcsizes = []
reversals = []
passes = []
while 1 == 1:
if node.bl_idname == "ConvNodeType":
#print (node.inputs[0])
#print(dir(node.inputs[0]))
#print(type(node.inputs[0]))
if not node.nonsquare:
kernelsizes.extend([node.kernelsize])
elif axis == 'x':
kernelsizes.extend([node.kernelsizex])
elif axis == 'y':
kernelsizes.extend([node.kernelsizey])
else:
raise RuntimeError
strides.extend([node.Stride])
paddings.extend([node.Padding])
poolsizes.extend([1])
poolstrides.extend([1])
offsets.extend([0])
fcsizes.extend([0])
passes.extend([0])
reversals.extend([0])
node = node.inputs[0].links[0].from_node
if node.bl_idname == "DeConvNodeType":
#print (node.inputs[0])
#print(dir(node.inputs[0]))
#print(type(node.inputs[0]))
if not node.nonsquare:
kernelsizes.extend([node.kernelsize])
elif axis == 'x':
kernelsizes.extend([node.kernelsizex])
elif axis == 'y':
kernelsizes.extend([node.kernelsizey])
else:
raise RuntimeError
strides.extend([node.Stride])
paddings.extend([node.Padding])
poolsizes.extend([1])
poolstrides.extend([1])
offsets.extend([0])
fcsizes.extend([0])
passes.extend([0])
reversals.extend([1])
node = node.inputs[0].links[0].from_node
elif node.bl_idname == "FCNodeType":
#print (node.inputs[0])
#print(dir(node.inputs[0]))
#print(type(node.inputs[0]))
kernelsizes.extend([0])
strides.extend([0])
paddings.extend([0])
poolsizes.extend([0])
poolstrides.extend([0])
offsets.extend([0])
passes.extend([0])
reversals.extend([0])
fcsizes.extend([node.outputnum])
node = node.inputs[0].links[0].from_node
#print (node)
elif node.bl_idname == "PoolNodeType":
kernelsizes.extend([0])
paddings.extend([0])
strides.extend([1])
fcsizes.extend([0])
passes.extend([0])
reversals.extend([0])
poolsizes.extend([node.kernel])
poolstrides.extend([node.stride])
offsets.extend([1])
node = node.inputs[0].links[0].from_node
elif node.bl_idname == "DataNodeType":
# When the data node is reached, we must be at the back of the nodetree, so start to work forwards
if not node.rim:
x = float(node.imsize)
elif axis=='x':
x = float(node.imsizex)
else:
x = float(node.imsizey)
# work forwards
numofnodes = len(passes)
for node in range(numofnodes):
# - 1 as starts from 0
node = (numofnodes - 1) - node
padding = paddings[node]
stride = strides[node]
ksize = kernelsizes[node]
offset = offsets[node]
poolstride = poolstrides[node]
poolsize = poolsizes[node]
reversal = reversals[node]
if passes[node] == 0:
if fcsizes[node] == 0:
if reversal ==0:
#########################
x = ((x + (2 * padding) - ksize) / stride + 1 - offset)
x = (x - poolsize) / poolstride + 1
###################
else:
x = (x*stride - stride) + ksize - 2*padding
else:
x = fcsizes[node]
break
else:
kernelsizes.extend([0])
strides.extend([0])
paddings.extend([0])
poolsizes.extend([0])
poolstrides.extend([0])
offsets.extend([0])
reversals.extend([0])
fcsizes.extend([0])
passes.extend([1])
node = node.inputs[0].links[0].from_node
return str(round(x, 2))
############################## Function for determining number of gpus
def getgpus():
command = ['nvidia-smi','-L']
try:
proc = subprocess.Popen(command, bufsize=1,stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True)
except OSError:
return 'Error'
lines = []
while proc.poll() is None: # while alive
line = proc.stdout.readline()
if line:
# Process output here
lines.append(line)
return len(lines)
##################################
# Derived from the NodeTree base type, similar to Menu, Operator, Panel, etc.
class CaffeTree(NodeTree):
# Description string
'''A custom node tree type that will show up in the node editor header'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'CaffeNodeTree'
# Label for nice name display
bl_label = 'Caffe Node Tree'
bl_icon = 'NODETREE'
# Custom socket type
class ImageSocket(NodeSocket):
# Description string
'''Blob socket type'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'ImageSocketType'
# Label for nice name display
bl_label = 'Image Socket'
# Enum items list
# Optional function for drawing the socket input value
def draw(self, context, layout, node, text):
layout.label(text)
# Socket color
def draw_color(self, context, node):
return (0.0, 1.0, 1.0, 0.5)
class OutputSocket(NodeSocket):
# Description string
'''Custom node socket type'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'OutputSocketType'
# Label for nice name display
bl_label = 'Output Socket'
# Enum items list
output_name = bpy.props.StringProperty(name='')
# Optional function for drawing the socket input value
def draw(self, context, layout, node, text):
layout.prop(self, "output_name")
# Socket color
def draw_color(self, context, node):
return (0.0, 1.0, 1.0, 0.5)
class LabelSocket(NodeSocket):
# Description string
'''Label socket type'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'LabelSocketType'
# Label for nice name display
bl_label = 'Label Socket'
# Enum items list
# Optional function for drawing the socket input value
def draw(self, context, layout, node, text):
layout.label(text)
# Socket color
def draw_color(self, context, node):
return (0.5, 1.0, 0.2, 0.5)
class LossSocket(NodeSocket):
# Description string
'''Loss socket type'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'LossSocketType'
# Label for nice name display
bl_label = 'Loss Socket'
# Enum items list
# Optional function for drawing the socket input value
def draw(self, context, layout, node, text):
layout.label(text)
# Socket color
def draw_color(self, context, node):
return (1.0, 0.3, 1.0, 0.5)
class NAFlatSocket(NodeSocket):
# Description string
'''NAFlat socket type'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'NAFlatSocketType'
# Label for nice name display
bl_label = 'Linear Flat Socket'
# Enum items list
# Optional function for drawing the socket input value
def draw(self, context, layout, node, text):
layout.label(text)
# Socket color
def draw_color(self, context, node):
return (1.0, 0.2, 0.2, 0.5)
class AFlatSocket(NodeSocket):
# Description string
'''AFlat socket type'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'AFlatSocketType'
# Label for nice name display
bl_label = 'Non linear Flat Socket'
# Enum items list
# Optional function for drawing the socket input value
def draw(self, context, layout, node, text):
layout.label(text)
# Socket color
def draw_color(self, context, node):
return (0.0, 0.8, 0.8, 0.5)
class params_p_g(bpy.types.PropertyGroup):
name = bpy.props.StringProperty(name='Shared name')
lr_mult = bpy.props.FloatProperty(default=1.0)
decay_mult = bpy.props.FloatProperty(default=1.0)
def draw(self, context, layout):
layout.prop(self, "name")
layout.prop(self, "lr_mult")
layout.prop(self, "decay_mult")
class CaffeTreeNode:
@classmethod
def poll(cls, ntree):
return ntree.bl_idname == 'CaffeNodeTree'
extra_params = bpy.props.BoolProperty(name='Extra Parameters', default=False)
weight_params = bpy.props.PointerProperty(type=params_p_g)
bias_params = bpy.props.PointerProperty(type=params_p_g)
phases = [("TRAIN", "TRAIN", "Train only"),
("TEST", "TEST", "Test only"),
("BOTH", "BOTH", "Both")]
include_in = bpy.props.EnumProperty(items=phases, default="BOTH")
use_custom_weight = bpy.props.BoolProperty(name="Use custom weights", default=False)
custom_weight = bpy.props.StringProperty(name="Custom weights",
default="",
description="Custom weights and bias from file",
subtype='FILE_PATH')
def draw_include_in(self, layout):
layout.prop(self, "include_in")
def draw_extra_params(self, context, layout):
layout.prop(self, "extra_params")
if self.extra_params:
layout.label("Weight Params")
self.weight_params.draw(context, layout)
if (not hasattr(self, 'bias_term')) or self.bias_term:
layout.label("Bias Params")
self.bias_params.draw(context, layout)
def copy(self, node):
print("Copying from node ", node)
for output in self.outputs:
output.output_name = output.output_name + '0'
class DataNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''A data node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'DataNodeType'
# Label for nice name display
bl_label = 'Data input'
# Icon identifier
bl_icon = 'SOUND'
DBs = [
("LMDB", "LMDB", "Lmdb database"),
("LEVELDB", "LEVELDB", "LevelDB database"),
("ImageData","ImageData","Image files"),
("HDF5Data", "HDF5Data", "HDF5 Data")
]
# === Custom Properties ===
db_type = bpy.props.EnumProperty(name="Database type", description="Type of Data", items=DBs, default='HDF5Data')
train_batch_size = bpy.props.IntProperty(min=1, default=100)
test_batch_size = bpy.props.IntProperty(min=1, default=100)
def update_tops(self, context):
while len(self.outputs) < self.output_amount:
self.outputs.new('OutputSocketType', "Out%i" % len(self.outputs))
while len(self.outputs) > self.output_amount:
self.outputs.remove(self.outputs[len(self.outputs)-1])
output_amount = bpy.props.IntProperty(min=1, default=2, update=update_tops)
train_path = bpy.props.StringProperty (
name="Train Data Path",
default="",
description="Get the path to the data",
subtype='DIR_PATH'
)
test_path = bpy.props.StringProperty (
name="Test Data Path",
default="",
description="Get the path to the data",
subtype='DIR_PATH'
)
train_data = bpy.props.StringProperty (
name="Train Data Path",
default="",
description="Get the path to the data",
subtype='FILE_PATH'
)
test_data = bpy.props.StringProperty (
name="Test Data Path",
default="",
description="Get the path to the data",
subtype='FILE_PATH'
)
# Transformation params
scale = bpy.props.FloatProperty(default=1.0, min=0)
mirror = bpy.props.BoolProperty(name='Random Mirror',default=False)
use_mean_file = bpy.props.BoolProperty(name='Use mean file',default=False)
mean_file = bpy.props.StringProperty (
name="Mean File Path",
default="",
description="Mean file location",
subtype='FILE_PATH'
)
# TODO: Add Mean Value and random crop
# Image data params
new_height = bpy.props.IntProperty(name="New image height",min=0, default=0, soft_max=1000)
new_width = bpy.props.IntProperty(name="New image width",min=0, default=0, soft_max=1000)
is_color = bpy.props.BoolProperty(name="Is color image",default=True)
# For Image data + HDF5 data
shuffle = bpy.props.BoolProperty(name='Shuffle', default=False)
# For Data + Image data
rand_skip = bpy.props.IntProperty(name="Random skip",min=0, default=0, soft_max=1000)
# TODO: Add non supervised property
# === Optional Functions ===
def init(self, context):
self.outputs.new('OutputSocketType', "Image Stack")
self.outputs.new('OutputSocketType', "Label")
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
layout.prop(self, "output_amount")
layout.prop(self, "db_type")
if self.db_type in ('ImageData', 'HDF5Data'):
layout.prop(self, "train_data")
layout.prop(self, "test_data")
else:
layout.prop(self, "train_path")
layout.prop(self, "test_path")
layout.prop(self, "train_batch_size")
layout.prop(self, "test_batch_size")
if self.db_type in ('ImageData', 'LMDB', 'LEVELDB'):
layout.label("Transformation Parameters")
layout.prop(self, "scale")
layout.prop(self, "mirror")
layout.prop(self, "use_mean_file")
if self.use_mean_file:
layout.prop(self, "mean_file")
layout.label("Special Parameters")
if self.db_type == 'ImageData':
layout.prop(self, "shuffle")
layout.prop(self, "new_height")
layout.prop(self, "new_width")
layout.prop(self, "is_color")
layout.prop(self, "rand_skip")
elif self.db_type == 'HDF5Data':
layout.prop(self, "shuffle")
else:
layout.prop(self, "rand_skip")
def draw_label(self):
return "Data Node"
class filler_p_g(bpy.types.PropertyGroup):
types = [("constant", "constant", "Constant val"),
("uniform", "uniform", "Uniform dist"),
("gaussian", "gaussian", "Gaussian dist"),
("positive_unitball", "positive_unitball", "Positive unit ball dist"),
("xavier", "xavier", "Xavier dist"),
("msra", "msra", "MSRA dist"),
("bilinear", "bilinear", "Bi-linear upsample weights")]
vnormtypes = [("FAN_IN", "FAN_IN", "Constant val"),
("FAN_OUT", "FAN_OUT", "Uniform dist"),
("AVERAGE", "AVERAGE", "Gaussian dist")]
type = bpy.props.EnumProperty(name='Type', items=types, default='xavier')
value = bpy.props.FloatProperty(default=0.0, soft_max=1000.0, soft_min=-1000.0)
min = bpy.props.FloatProperty(default=0.0, soft_max=1000.0, soft_min=-1000.0)
max = bpy.props.FloatProperty(default=1.0, soft_max=1000.0, soft_min=-1000.0)
mean = bpy.props.FloatProperty(default=0.0, soft_max=1000.0, soft_min=-1000.0)
std = bpy.props.FloatProperty(default=1.0, soft_max=1000.0, soft_min=-1000.0)
variance_norm = bpy.props.EnumProperty(name='Weight variance norm', default='FAN_IN', items=vnormtypes)
is_sparse = bpy.props.BoolProperty(name="Use Sprasity", default=False)
sparse = bpy.props.IntProperty(default=100, min=1)
def draw(self, context, layout):
layout.prop(self, "type")
if self.type == 'constant':
layout.prop(self, "value")
elif self.type in ('xavier', 'msra'):
layout.prop(self, "variance_norm")
elif self.type == 'gaussian':
layout.prop(self, "mean")
layout.prop(self, "std")
layout.prop(self, "is_sparse")
if self.is_sparse:
layout.prop(self, "sparse")
elif self.type == 'uniform':
layout.prop(self, "min")
layout.prop(self, "max")
class PoolNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''A pooling node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'PoolNodeType'
# Label for nice name display
bl_label = 'Pooling Node'
# Icon identifier
bl_icon = 'SOUND'
n_type = 'Pooling'
# === Custom Properties ===
modes = [
("MAX", "MAX", "Max pooling"),
("AVE", "AVE", "Average pooling"),
("STOCHASTIC", "SGD", "Stochastic pooling"),
]
kernel_size = bpy.props.IntProperty(default=2, min=1, soft_max=5)
stride = bpy.props.IntProperty(default=2, min=1, soft_max=5)
mode = bpy.props.EnumProperty(name='Mode', default='MAX', items=modes)
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input image")
self.outputs.new('OutputSocketType', "Output image")
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
# if calcsize(self, context,axis='x') != calcsize(self, context,axis='y'):
# layout.label("image x,y output is %s,%s pixels" %
# (calcsize(self, context,axis='x'),calcsize(self, context,axis='y')))
# else:
# layout.label("image output is %s pixels" %calcsize(self, context,axis='x'))
layout.prop(self, "kernel_size")
layout.prop(self, "stride")
layout.prop(self, "mode")
class eltwise_coeff_p_g(bpy.types.PropertyGroup):
coeff = bpy.props.FloatProperty(default=1)
def draw(self, context, layout):
layout.prop(self, "coeff")
class EltwiseNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''An element-wise node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'EltwiseNodeType'
# Label for nice name display
bl_label = 'Element-wise Node'
# Icon identifier
bl_icon = 'SOUND'
n_type = 'Eltwise'
# === Custom Properties ===
eltwiseOps = [
("PROD", "PROD", "Eltwise prod: c(i) -> a(i)*b(i)"),
("SUM", "SUM", "Eltwise sum: c(i) -> a(i)+b(i)"),
("MAX", "MAX", "Eltwise max: c(i) -> max [a(i),b(i)]"),
]
coeffs = bpy.props.CollectionProperty(type=eltwise_coeff_p_g)
stable_prod_grad = bpy.props.BoolProperty(name='Stable(slower) gradient',default=1)
operation = bpy.props.EnumProperty(name='Operation', default='SUM', items=eltwiseOps)
def update_bottoms(self, context):
while len(self.inputs) < self.input_amount:
self.coeffs.add()
self.inputs.new('ImageSocketType', "Input %i" % (len(self.inputs)+1))
while len(self.inputs) > self.input_amount:
self.coeffs.remove(len(self.coeffs)-1)
self.inputs.remove(self.inputs[len(self.inputs)-1])
input_amount = bpy.props.IntProperty(min=1, default=2, update=update_bottoms)
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input 1")
self.inputs.new('ImageSocketType', "Input 2")
self.outputs.new('OutputSocketType', "Output blob")
self.coeffs.add()
self.coeffs.add()
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
layout.prop(self, "input_amount")
layout.prop(self, "operation")
if self.operation == 'PROD':
layout.prop(self, "stable_prod_grad")
elif self.operation == 'SUM':
for coeff in self.coeffs:
coeff.draw(context, layout)
class ExpNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''An exponential node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'ExpNodeType'
# Label for nice name display
bl_label = 'Exponential Node'
# Icon identifier
bl_icon = 'SOUND'
n_type = 'Exp'
# === Custom Properties ===
base = bpy.props.FloatProperty(default=-1.0,soft_max=10.0,min=0)
scale = bpy.props.FloatProperty(default=1.0,soft_max=10.0,min=0)
shift = bpy.props.FloatProperty(default=0.0,soft_max=10.0,min=-10)
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input blob")
self.outputs.new('OutputSocketType', "Output blob")
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
layout.prop(self, "base")
layout.prop(self, "scale")
layout.prop(self, "shift")
self.draw_extra_params(context, layout)
class MVNNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''Mean variance normalization node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'MVNNodeType'
# Label for nice name display
bl_label = 'MVN Node'
# Icon identifier
bl_icon = 'SOUND'
# === Custom Properties ===
normalize_variance = bpy.props.BoolProperty(default=True)
across_channels = bpy.props.BoolProperty(default=False)
eps = bpy.props.FloatProperty(default=1e-9,soft_max=1.0,min=1e-20)
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input blob")
self.outputs.new('OutputSocketType', "Output blob")
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
layout.prop(self, "normalize_variance")
layout.prop(self, "across_channels")
layout.prop(self, "eps")
self.draw_extra_params(context, layout)
class ConvNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''A Convolution node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'ConvNodeType'
# Label for nice name display
bl_label = 'Convolution Node'
# Icon identifier
bl_icon = 'SOUND'
n_type = "Convolution"
# === Custom Properties ===
num_output = bpy.props.IntProperty(name="Number of outputs", default=20, min=1, soft_max=300)
bias_term = bpy.props.BoolProperty(name='Include Bias term',default=True)
square_padding = bpy.props.BoolProperty(name="Equal x,y padding", default=True)
pad = bpy.props.IntProperty(name="Padding", default=0, min=0, soft_max=5)
pad_h = bpy.props.IntProperty(name="Padding height", default=0, min=0, soft_max=5)
pad_w = bpy.props.IntProperty(name="Padding width", default=0, min=0, soft_max=5)
square_kernel = bpy.props.BoolProperty(name="Equal x,y kernel", default=True)
kernel_size = bpy.props.IntProperty(name="Kernel size", default=5, min=1, soft_max=25)
kernel_h = bpy.props.IntProperty(name="Kernel height", default=5, min=1, soft_max=25)
kernel_w = bpy.props.IntProperty(name="Kernel width", default=5, min=1, soft_max=25)
group = bpy.props.IntProperty(name="Group size", default=1, min=1, soft_max=25)
square_stride = bpy.props.BoolProperty(name="Equal x,y stride", default=True)
stride = bpy.props.IntProperty(name="Stride", default=1, min=1, soft_max=5)
stride_h = bpy.props.IntProperty(name="Stride height", default=1, min=1, soft_max=5)
stride_w = bpy.props.IntProperty(name="Stride width", default=1, min=1, soft_max=5)
weight_filler = bpy.props.PointerProperty(type=filler_p_g)
bias_filler = bpy.props.PointerProperty(type=filler_p_g)
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input image")
self.outputs.new('OutputSocketType', "Output image")
self.color = [1, 0 ,1]
self.use_custom_color = True
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
#TODO: Finish calcsize
# if calcsize(self, context,axis='x') != calcsize(self, context,axis='y'):
# layout.label("image x,y output is %s,%s pixels" %
# (calcsize(self, context,axis='x'),calcsize(self, context,axis='y')))
# else:
# layout.label("image output is %s pixels" %calcsize(self, context,axis='x'))
layout.prop(self, "num_output")
layout.prop(self, "bias_term")
layout.prop(self, "group")
layout.prop(self, "square_padding")
if self.square_padding:
layout.prop(self, "pad")
else:
layout.prop(self, "pad_h")
layout.prop(self, "pad_w")
layout.prop(self, "square_kernel")
if self.square_kernel:
layout.prop(self, "kernel_size")
else:
layout.prop(self, "kernel_h")
layout.prop(self, "kernel_w")
layout.prop(self, "square_stride")
if self.square_stride:
layout.prop(self, "stride")
else:
layout.prop(self, "stride_h")
layout.prop(self, "stride_w")
layout.prop(self, "use_custom_weight")
if self.use_custom_weight:
layout.prop(self, "custom_weight")
else:
layout.label("Weight Filler")
self.weight_filler.draw(context, layout)
if self.bias_term:
layout.label("bias Filler")
self.bias_filler.draw(context, layout)
self.draw_extra_params(context, layout)
class DeConvNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''A DeConvolution node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'DeConvNodeType'
# Label for nice name display
bl_label = 'DeConvolution Node'
# Icon identifier
bl_icon = 'SOUND'
n_type = "Deconvolution"
# === Custom Properties ===
num_output = bpy.props.IntProperty(name="Number of outputs", default=20, min=1, soft_max=300)
bias_term = bpy.props.BoolProperty(name='Include Bias term',default=True)
square_padding = bpy.props.BoolProperty(name="Equal x,y padding", default=True)
pad = bpy.props.IntProperty(name="Padding", default=0, min=0, soft_max=5)
pad_h = bpy.props.IntProperty(name="Padding height", default=0, min=0, soft_max=5)
pad_w = bpy.props.IntProperty(name="Padding width", default=0, min=0, soft_max=5)
square_kernel = bpy.props.BoolProperty(name="Equal x,y kernel", default=True)
kernel_size = bpy.props.IntProperty(name="Kernel size", default=5, min=1, soft_max=25)
kernel_h = bpy.props.IntProperty(name="Kernel height", default=5, min=1, soft_max=25)
kernel_w = bpy.props.IntProperty(name="Kernel width", default=5, min=1, soft_max=25)
group = bpy.props.IntProperty(name="Group size", default=1, min=1, soft_max=25)
square_stride = bpy.props.BoolProperty(name="Equal x,y stride", default=True)
stride = bpy.props.IntProperty(name="Stride", default=1, min=1, soft_max=5)
stride_h = bpy.props.IntProperty(name="Stride height", default=1, min=1, soft_max=5)
stride_w = bpy.props.IntProperty(name="Stride width", default=1, min=1, soft_max=5)
weight_filler = bpy.props.PointerProperty(type=filler_p_g)
bias_filler = bpy.props.PointerProperty(type=filler_p_g)
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input image")
self.outputs.new('OutputSocketType', "Output image")
self.color = [1, 0 ,1]
self.use_custom_color = True
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
#TODO: Finish calcsize
# if calcsize(self, context,axis='x') != calcsize(self, context,axis='y'):
# layout.label("image x,y output is %s,%s pixels" %
# (calcsize(self, context,axis='x'),calcsize(self, context,axis='y')))
# else:
# layout.label("image output is %s pixels" %calcsize(self, context,axis='x'))
layout.prop(self, "num_output")
layout.prop(self, "bias_term")
layout.prop(self, "group")
layout.prop(self, "square_padding")
if self.square_padding:
layout.prop(self, "pad")
else:
layout.prop(self, "pad_h")
layout.prop(self, "pad_w")
layout.prop(self, "square_kernel")
if self.square_kernel:
layout.prop(self, "kernel_size")
else:
layout.prop(self, "kernel_h")
layout.prop(self, "kernel_w")
layout.prop(self, "square_stride")
if self.square_stride:
layout.prop(self, "stride")
else:
layout.prop(self, "stride_h")
layout.prop(self, "stride_w")
layout.prop(self, "use_custom_weight")
if self.use_custom_weight:
layout.prop(self, "custom_weight")
else:
layout.label("Weight Filler")
self.weight_filler.draw(context, layout)
if self.bias_term:
layout.label("bias Filler")
self.bias_filler.draw(context, layout)
self.draw_extra_params(context, layout)
class FCNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''An inner product node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'FCNodeType'
# Label for nice name display
bl_label = 'Fully connected Node'
# Icon identifier
bl_icon = 'SOUND'
n_type = 'InnerProduct'
# === Custom Properties ===
num_output = bpy.props.IntProperty(name="Number of outputs", default=10, min=1)
bias_term = bpy.props.BoolProperty(name='Include Bias term',default=True)
weight_filler = bpy.props.PointerProperty(type=filler_p_g)
bias_filler = bpy.props.PointerProperty(type=filler_p_g)
axis = bpy.props.IntProperty(name="Starting axis", default=1)
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input image")
self.outputs.new('OutputSocketType', "Output Activations")
self.color = [1, 0 ,0]
self.use_custom_color = True
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
# layout.label("Network is now %s neurons" % calcsize(self, context))
layout.prop(self, "num_output")
layout.prop(self, "bias_term")
layout.prop(self, "axis")
layout.label("Weight Filler")
self.weight_filler.draw(context, layout)
layout.label("bias Filler")
self.bias_filler.draw(context, layout)
self.draw_extra_params(context, layout)
class FlattenNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''Flatten layer node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'FlattenNodeType'
# Label for nice name display
bl_label = 'Flatten Node'
# Icon identifier
bl_icon = 'SOUND'
n_type = 'Flatten'
# === Custom Properties ===
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input image")
self.outputs.new('OutputSocketType', "Flat output")
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
layout.label("Flatten")
self.draw_extra_params(context, layout)
class AbsValNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''AbsVal layer node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'AbsValNodeType'
# Label for nice name display
bl_label = 'AbsVal Node'
# Icon identifier
bl_icon = 'SOUND'
n_type = 'AbsVal'
# === Custom Properties ===
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input image")
self.outputs.new('OutputSocketType', "AbsVal output")
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
layout.label("AbsVal")
# self.draw_extra_params(context, layout)
class SilenceNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''A Silence node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'SilenceNodeType'
# Label for nice name display
bl_label = 'Silence Node'
# Icon identifier
bl_icon = 'SOUND'
n_type = 'Silence'
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input")
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
layout.label("Silence")
class LRNNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''A Convolution node'''
# Optional identifier string. If not explicitly defined, the python class name is used.
bl_idname = 'LRNNodeType'
# Label for nice name display
bl_label = 'LRN Node'
# Icon identifier
bl_icon = 'SOUND'
n_type = 'LRN'
modes = [
("ACROSS_CHANNELS", "ACROSS_CHANNELS", "Go across Channels"),
("WITHIN_CHANNEL", "WITHIN_CHANNEL", "Go by location"),
]
# === Custom Properties ===
alpha = bpy.props.FloatProperty(default=1, min=0, soft_max=50)
beta = bpy.props.FloatProperty(default=5, min=0, soft_max=50)
size = bpy.props.IntProperty(default=5, min=1, soft_max=50)
mode = bpy.props.EnumProperty(name="Mode", default='ACROSS_CHANNELS', items=modes)
# === Optional Functions ===
def init(self, context):
self.inputs.new('ImageSocketType', "Input image")
self.outputs.new('OutputSocketType', "Normalized output")
# Additional buttons displayed on the node.
def draw_buttons(self, context, layout):
layout.prop(self, "alpha")
layout.prop(self, "beta")
layout.prop(self, "size")
layout.prop(self, "mode")
self.draw_extra_params(context, layout)
class ActivationNode(Node, CaffeTreeNode):
# === Basics ===
# Description string
'''A Convolution node'''
# Optional identifier string. If not explicitly defined, the python class name is used.