在tensorflow中使用keras作为高层接口
tensorflow
一个面向所有人的开源机器学习框架
项目地址:https://gitcode.com/gh_mirrors/te/tensorflow

·
最近从keras转战tensorflow,原先的代码又不想重写,幸好keras代码可以在tensorflow中使用。详情请参考将Keras作为tensorflow的精简接口。
简单应用的话,就是把keras当作tf.layers里面的层来用,placeholder等价于Keras.Input,然后基本和keras里面使用model模块的时候构建方式相同。最后的model也可以使用的,但是我就是想要这部分灵活一些,所以也没有研究,就直接用了tensorflow里面的包装。有两个需要注意的地方:
1 keras里面有一个learning_phase()需要在sess.run的时候feed进去,这个量主要用于区分是训练(1)还是测试(0)(比如dropout在两种状态下行为不同)。
from keras import backend as K
K.learning_phase()
2 keras层的输入输出都是tensorflow里面的Tensor,而不是Keras的Tensor了。所以可以直接使用tensorflow里面的任意函数对该Tensor进行操作。(完美的无缝链接)
tensorflow里面直接对keras做了包装,具体没有实验过,详情请参考Module: tf.contrib.keras。




一个面向所有人的开源机器学习框架
最近提交(Master分支:12 天前 )
4f64a3d5
Instead, check for this case in `ResolveUsers` and `ResolveOperand`, by querying whether the `fused_expression_root` is part of the `HloFusionAdaptor`.
This prevents us from stepping into nested fusions.
PiperOrigin-RevId: 724311958
12 天前
aa7e952e
Fix a bug in handling negative strides, and add a test case that exposes it.
We can have negative strides that are not just -1, e.g. with a combining
reshape.
PiperOrigin-RevId: 724293790
12 天前
更多推荐
所有评论(0)