|
a |
|
b/darkflow/dark/darkop.py |
|
|
1 |
from .layer import Layer |
|
|
2 |
from .convolution import * |
|
|
3 |
from .connected import * |
|
|
4 |
|
|
|
5 |
|
|
|
6 |
class avgpool_layer(Layer): |
|
|
7 |
pass |
|
|
8 |
|
|
|
9 |
|
|
|
10 |
class crop_layer(Layer): |
|
|
11 |
pass |
|
|
12 |
|
|
|
13 |
|
|
|
14 |
class maxpool_layer(Layer): |
|
|
15 |
def setup(self, ksize, stride, pad): |
|
|
16 |
self.stride = stride |
|
|
17 |
self.ksize = ksize |
|
|
18 |
self.pad = pad |
|
|
19 |
|
|
|
20 |
|
|
|
21 |
class softmax_layer(Layer): |
|
|
22 |
def setup(self, groups): |
|
|
23 |
self.groups = groups |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
class dropout_layer(Layer): |
|
|
27 |
def setup(self, p): |
|
|
28 |
self.h['pdrop'] = dict({ |
|
|
29 |
'feed': p, # for training |
|
|
30 |
'dfault': 1.0, # for testing |
|
|
31 |
'shape': () |
|
|
32 |
}) |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
class route_layer(Layer): |
|
|
36 |
def setup(self, routes): |
|
|
37 |
self.routes = routes |
|
|
38 |
|
|
|
39 |
|
|
|
40 |
class reorg_layer(Layer): |
|
|
41 |
def setup(self, stride): |
|
|
42 |
self.stride = stride |
|
|
43 |
|
|
|
44 |
|
|
|
45 |
""" |
|
|
46 |
Darkop Factory |
|
|
47 |
""" |
|
|
48 |
|
|
|
49 |
darkops = { |
|
|
50 |
'dropout': dropout_layer, |
|
|
51 |
'connected': connected_layer, |
|
|
52 |
'maxpool': maxpool_layer, |
|
|
53 |
'convolutional': convolutional_layer, |
|
|
54 |
'avgpool': avgpool_layer, |
|
|
55 |
'softmax': softmax_layer, |
|
|
56 |
'crop': crop_layer, |
|
|
57 |
'local': local_layer, |
|
|
58 |
'select': select_layer, |
|
|
59 |
'route': route_layer, |
|
|
60 |
'reorg': reorg_layer, |
|
|
61 |
'conv-select': conv_select_layer, |
|
|
62 |
'conv-extract': conv_extract_layer, |
|
|
63 |
'extract': extract_layer |
|
|
64 |
} |
|
|
65 |
|
|
|
66 |
|
|
|
67 |
def create_darkop(ltype, num, *args): |
|
|
68 |
op_class = darkops.get(ltype, Layer) |
|
|
69 |
return op_class(ltype, num, *args) |