tensorflow eager bug记录

tensorflow eager通过把静态图计算转换为动态图计算,让人能直接输出tensor的结果,用来debug十分方便。但是其中也有一些坑需要避免。
由于scipy.sparse和SparseTensor的很多运算兼容性相比numpy和Tensor运算的兼容性差很多,建议在sparse运算很多的时候用tensor debugger调试。
以下是用eager进行debug的时候遇到的一些bug和解决方案

1.

......
tfe.enable_eager_execution()

ValueError: tf.enable_eager_execution must be called at program startup.
解决方案:import tensorflow之后程序开始执行之前启动
eager execution,这个bug将会在未来版本中修复

import tensorflow.contrib.eager as tfe
tfe.enable_eager_execution()

2.

rowsum = np.array([6,6,6])
np.power(rowsum, -1).

ValueError: Integers to negative integer powers are not allowed.
解决方案:rowsum dtype设为float

rowsum = np.array([6,6,6], dtype=np.float32)
np.power(rowsum, -1)
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容