Repository navigation
Expand file tree
/
Copy pathdihedral_fast.py
More file actions
executable file
·53 lines (39 loc) · 1.65 KB
/
Copy pathdihedral_fast.py
File metadata and controls
executable file
·53 lines (39 loc) · 1.65 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
41
42
43
44
45
46
47
48
49
50
51
52
53
import numpy as np
import theano
import theano.tensor as T
import lasagne as nn
import dihedral_ops
class CyclicRollLayer(nn.layers.Layer):
"""
This layer turns (n_views * batch_size, num_features) into
(n_views * batch_size, n_views * num_features) by rolling
and concatenating feature maps.
fast version using a PyCUDA-based op
"""
def get_output_shape_for(self, input_shape):
return (input_shape[0], 4*input_shape[1])
def get_output_for(self, input, *args, **kwargs):
return dihedral_ops.cyclic_roll(input)
class CyclicConvRollLayer(CyclicRollLayer):
"""
This layer turns (n_views * batch_size, num_channels, r, c) into
(n_views * batch_size, n_views * num_channels, r, c) by rolling
and concatenating feature maps.
It also applies the correct inverse transforms to the r and c
dimensions to align the feature maps.
fast version using PyCUDA-based op
"""
def get_output_shape_for(self, input_shape):
return (input_shape[0], 4*input_shape[1]) + input_shape[2:]
def get_output_for(self, input, *args, **kwargs):
return dihedral_ops.cyclic_convroll(input)
class DihedralRollLayer(nn.layers.Layer):
def get_output_shape_for(self, input_shape):
return (input_shape[0], 8*input_shape[1])
def get_output_for(self, input, *args, **kwargs):
return dihedral_ops.dihedral_roll(input)
class DihedralConvRollLayer(DihedralRollLayer):
def get_output_shape_for(self, input_shape):
return (input_shape[0], 8*input_shape[1]) + input_shape[2:]
def get_output_for(self, input, *args, **kwargs):
return dihedral_ops.dihedral_convroll(input)