Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 新的Tensorflow库_Python_Tensorflow - Fatal编程技术网

Python 新的Tensorflow库

Python 新的Tensorflow库,python,tensorflow,Python,Tensorflow,如何创建新的tensorflow库?例如,我想写一些tensorflow代码,矩阵乘法: # File custom_matmul.py import tensorflow as tf matrixA = ... matrixB = ... matrixC = tf.matmul(...) 在另一个python文件中,我想做如下操作: import tensorflow as tf tf.custom_matmul... 或使库成为库层的一部分 tf.layers.custom_ma

如何创建新的tensorflow库?例如,我想写一些tensorflow代码,矩阵乘法:

# File custom_matmul.py

import tensorflow as tf

matrixA = ...
matrixB = ...

matrixC = tf.matmul(...)
在另一个python文件中,我想做如下操作:

import tensorflow as tf

tf.custom_matmul...
或使库成为库层的一部分

tf.layers.custom_matmul

更简单的是,我想创建自己的库,并将其集成到标准的tensorflow库/框架中。

我建议您创建自己的模块,以您想要的方式导入和扩展tensorflow,而不是更改源代码。比如说

import tensorflow as tf
import mytf
那你就可以做了

mytf.layers.custom_matmul
您甚至可以在mytf中向tensorflow公开您自己的属性。我不建议这样做,因为它会让任何阅读您的代码的人感到困惑(可能将来也包括您自己),但您可以这样做

tf.layers.custom_matmul = MyCustomMatMul()

然后可以使用问题中描述的tf.layers.custom_matmul。同样,不推荐。

为什么不制作一个模块并使用它公开的属性呢?好的,谢谢。这是一个选择,但如果我想改变TF,这可能吗,就像我想做的那样?我会在这里指导你。你可以用叉子叉它,直接使用它