forked from arogozhnikov/einops
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b928179
commit 3156a42
Showing
2 changed files
with
19 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,9 @@ | ||
from tensorflow.keras.layers import Layer | ||
|
||
from .._backends import UnknownSize | ||
from . import RearrangeMixin, ReduceMixin | ||
|
||
__author__ = 'Alex Rogozhnikov' | ||
|
||
from ..layers.tensorflow import Rearrange, Reduce, WeightedEinsum | ||
|
||
def _compute_output_shape(self, input_shape): | ||
input_shape = tuple(UnknownSize() if d is None else int(d) for d in input_shape) | ||
init_shapes, reduced_axes, axes_reordering, added_axes, final_shape = \ | ||
self.recipe().reconstruct_from_shape(input_shape) | ||
final_shape = tuple(None if isinstance(d, UnknownSize) else int(d) for d in final_shape) | ||
return final_shape | ||
|
||
|
||
class Rearrange(RearrangeMixin, Layer): | ||
def compute_output_shape(self, input_shape): | ||
return _compute_output_shape(self, input_shape) | ||
|
||
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): | ||
return _compute_output_shape(self, input_shape) | ||
|
||
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} | ||
keras_custom_objects = { | ||
Rearrange.__name__: Rearrange, | ||
Reduce.__name__: Reduce, | ||
WeightedEinsum.__name__: WeightedEinsum, | ||
} |
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