Skip to content

Instantly share code, notes, and snippets.

@backnotprop
Last active January 12, 2018 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save backnotprop/4d0900fcd3dbf5ef6c253cc23cf113f3 to your computer and use it in GitHub Desktop.
Save backnotprop/4d0900fcd3dbf5ef6c253cc23cf113f3 to your computer and use it in GitHub Desktop.
# 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