Traceback (most recent call last): File "D:/SteganoGAN-master/research/psnr.py", line 26, in <module> _main() File "D:/SteganoGAN-master/research/psnr.py", line 20, in _main sess.run(tf.global_variables_initializer()) AttributeError: module 'tensorflow' has no attribute 'global_variables_initializer'
时间: 2023-07-16 17:12:16 浏览: 50
这个错误是因为你使用的 TensorFlow 版本较旧,而 `global_variables_initializer()` 函数在旧版本中不存在。可以尝试使用以下代码替换 `tf.global_variables_initializer()`:
```python
init_op = tf.compat.v1.global_variables_initializer()
sess.run(init_op)
```
这应该能够解决你的问题。如果还有其他问题,请随时提出。
相关问题
Traceback (most recent call last): File "D:/SteganoGAN-master/research/psnr.py", line 25, in <module> _main() File "D:/SteganoGAN-master/research/psnr.py", line 16, in _main t1 = read_img('D:/SteganoGAN-master/research/ruanjian.png') File "D:/SteganoGAN-master/research/psnr.py", line 8, in read_img return tf.image.decode_image(tf.read_file(path)) AttributeError: module 'tensorflow' has no attribute 'read_file'
这个错误提示是说在你的代码中使用了 `tensorflow` 模块中不存在的 `read_file` 属性。
在 `tensorflow` 2.0 版本之后,`read_file` 方法已经被移动到了 `tf.io` 模块中,所以你需要将代码中的 `tf.read_file` 替换为 `tf.io.read_file`。
下面是修改后的代码示例:
```python
import tensorflow as tf
def read_img(path):
return tf.image.decode_image(tf.io.read_file(path))
def _main():
t1 = read_img('D:/SteganoGAN-master/research/ruanjian.png')
t2 = read_img('D:/SteganoGAN-master/research/ruanjian_steg.png')
psnr = tf.image.psnr(t1, t2, max_val=255)
print("PSNR:", psnr)
if __name__ == '__main__':
_main()
```
修改后的代码中使用了 `tf.io.read_file` 方法来读取图像文件,应该可以解决你遇到的问题。
Traceback (most recent call last): File "D:/SteganoGAN-master/research/psnr.py", line 26, in <module> _main() File "D:/SteganoGAN-master/research/psnr.py", line 19, in _main with tf.Session() as sess: AttributeError: module 'tensorflow' has no attribute 'Session'
这个错误通常是因为 TensorFlow 版本不兼容导致的。在较新的 TensorFlow 版本中,`Session` 已经被移除了。如果你使用的是 TensorFlow 2.0 或更新版本,你需要使用 `tf.compat.v1.Session()` 来代替 `tf.Session()`。如果你使用的是 TensorFlow 1.x 版本,那么这个错误可能是因为你的 TensorFlow 安装没有正确完成,你可以尝试重新安装 TensorFlow,或者检查你的环境变量是否正确设置。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)