Last active
January 12, 2018 19:41
-
-
Save backnotprop/4d0900fcd3dbf5ef6c253cc23cf113f3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# tfcoreml src | |
# file1 : _interpret_shapes.py | |
# | |
# in the _SHAPE_TRANSLATOR_REGISTRY we need to add the Pow operation | |
_SHAPE_TRANSLATOR_REGISTRY = { | |
... previous keys ... | |
# add this: | |
'Pow': _identity, | |
} | |
# file 2: _ops_to_layers.py | |
# | |
# in the _OP_REGISTRY to add the Pow operation | |
_OP_REGISTRY = { | |
... previous keys ... | |
# add this: | |
'Pow': _layers.pow | |
} | |
# file 3: _layers.py | |
# | |
# in the _layers we need to define the conversion | |
def pow(op, context): | |
const_name = compat.as_bytes(op.inputs[1].name) | |
const_val = context.consts[const_name] ## Note: this is .5 here, you can toy around if you want | |
input_name = compat.as_bytes(op.inputs[0].name) | |
output_name = compat.as_bytes(op.outputs[0].name) | |
context.builder.add_unary(output_name, input_name, output_name, 'power', alpha=const_val) | |
context.translated[output_name] = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment