Vladimir Canic
Vladimir Canic

Reputation: 81

New Tensorflow library

How to make new tensorflow library ? For e.g. I want to write some tensorflow code, matrix multiplication:

# File custom_matmul.py

import tensorflow as tf

matrixA = ...
matrixB = ...

matrixC = tf.matmul(...)

And in another python file, I want to do something like this:

import tensorflow as tf

tf.custom_matmul...

Or make library to be part of library layers

tf.layers.custom_matmul

Much more simpler, I want to make my own library and integrate it to the standard tensorflow library/framework.

Upvotes: 0

Views: 42

Answers (1)

krflol
krflol

Reputation: 1155

I would recommend making your own module that imports and extends tensorflow the way you want rather than changing the source. For example

import tensorflow as tf
import mytf

Then you could do

mytf.layers.custom_matmul

you could even, within mytf, expose your own attributes to tensorflow. I wouldn't recommend this because it would be confusing to anyone reading your code (including possibly yourself in the future), but you could

tf.layers.custom_matmul = MyCustomMatMul()

you could then use tf.layers.custom_matmul as described in the question. Again, not recommended.

Upvotes: 1

Related Questions