深度学习
qq_42907161
这个作者很懒,什么都没留下…
展开
-
tensorflow问题:AttributeError: module ‘tensorflow‘ has no attribute ‘placeholder‘
AttributeError: module ‘tensorflow’ has no attribute ‘placeholder’以前遇到了一个问题,tensorflow 1.x和2.x代码不兼容,写下来记录,万一以后用到了。其实这是tensorflow版本问题,在2.x使用了1.x版本的库。所以需要转换一下。查到的一种解决方法是:用下面的代码替换原来的“import tensorflow as tf”。import tensorflow.compat.v1 as tftf.disable_原创 2020-12-10 09:41:54 · 3236 阅读 · 1 评论 -
RuntimeError: Trying to backward through the graph a second time, but the saved intermediate results
在Pytorch练习求梯度时出现错误错误:RuntimeError: Trying to backward through the graph a second time, but the saved intermediate results have already been freed. Specify retain_graph=True when calling backward the first time.因为pytorch求梯度时累加的,所以为了看第二次的梯度需要把以前的清零。x.grad原创 2020-11-07 17:29:54 · 10109 阅读 · 12 评论 -
Tensorflow版本1.0到2.0版本遇到的问题
遇到的第一个问题就是不同版本代码的不兼容问题。比如:module ‘tensorflow’ has no attribute ‘placeholder’?还有很多2.x版本中没有1.x模块的搜了很多博客,都说的是import tensorflow.compat.v1 as tftf.disable_v2_behavior()但是我这里提示是没有这个compat模块,后来查找到资料说是把代码中调用模块的代码部分tf换成tf.compat.v1,比如下面的。tf.placeholder(type原创 2020-10-17 11:36:32 · 718 阅读 · 0 评论