-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
separate layers for different frameworks into individual files
- Loading branch information
1 parent
d1534f4
commit a95d509
Showing
5 changed files
with
98 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import chainer | ||
|
||
from layers import RearrangeMixin, ReduceMixin | ||
|
||
__author__ = 'Alex Rogozhnikov' | ||
|
||
|
||
class Rearrange(RearrangeMixin, chainer.Link): | ||
def __call__(self, x): | ||
return self._apply_recipe(x) | ||
|
||
|
||
class Reduce(ReduceMixin, chainer.Link): | ||
def __call__(self, x): | ||
return self._apply_recipe(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import mxnet | ||
|
||
from layers import RearrangeMixin, ReduceMixin | ||
|
||
__author__ = 'Alex Rogozhnikov' | ||
|
||
|
||
# TODO symbolic is not working right now | ||
class Rearrange(RearrangeMixin, mxnet.gluon.HybridBlock): | ||
def hybrid_forward(self, F, x): | ||
return self._apply_recipe(x) | ||
|
||
|
||
class Reduce(ReduceMixin, mxnet.gluon.HybridBlock): | ||
def hybrid_forward(self, F, x): | ||
return self._apply_recipe(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from keras.engine import Layer | ||
|
||
from layers import RearrangeMixin, ReduceMixin | ||
|
||
__author__ = 'Alex Rogozhnikov' | ||
|
||
|
||
class Rearrange(RearrangeMixin, Layer): | ||
def compute_output_shape(self, input_shape): | ||
input_shape = tuple(None if d is None else int(d) for d in input_shape) | ||
init_shapes, reduced_axes, axes_reordering, final_shapes = self.recipe().reconstruct_from_shape(input_shape) | ||
return final_shapes | ||
|
||
def call(self, inputs): | ||
return self._apply_recipe(inputs) | ||
|
||
def get_config(self): | ||
return {'pattern': self.pattern, **self.axes_lengths} | ||
|
||
|
||
class Reduce(ReduceMixin, Layer): | ||
def compute_output_shape(self, input_shape): | ||
input_shape = tuple(None if d is None else int(d) for d in input_shape) | ||
init_shapes, reduced_axes, axes_reordering, final_shapes = self.recipe().reconstruct_from_shape(input_shape) | ||
return final_shapes | ||
|
||
def call(self, inputs): | ||
return self._apply_recipe(inputs) | ||
|
||
def get_config(self): | ||
return {'pattern': self.pattern, 'reduction': self.reduction, **self.axes_lengths} | ||
|
||
|
||
keras_custom_objects = {Rearrange.__name__: Rearrange, Reduce.__name__: Reduce} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import torch | ||
|
||
from layers import RearrangeMixin, ReduceMixin | ||
|
||
__author__ = 'Alex Rogozhnikov' | ||
|
||
|
||
class Rearrange(RearrangeMixin, torch.nn.Module): | ||
def forward(self, input): | ||
return self._apply_recipe(input) | ||
|
||
|
||
class Reduce(ReduceMixin, torch.nn.Module): | ||
def forward(self, input): | ||
return self._apply_recipe(input) |