【问题标题】:When using the Deepbrain libary error message "module 'tensorflow' has no attribute 'Session"使用 Deepbrain 库时出现错误消息“模块 'tensorflow' 没有属性 'Session”
【发布时间】:2021-04-26 22:10:40
【问题描述】:

我正在尝试使用库 Deepbrain 从我正在使用的代码的整个 MRI 扫描中提取大脑

def Reduce_Brain(img):
     img_data = img.get_fdata()
     prob = ext.run(img)
     print(prob)

img = nib.load('ADNI_002_S_0295.nii')
Reduce_Brain(img)

但是,当我尝试这个时,我得到了错误模块 'tensorflow' has no attribute 'Session' 我发现这是与错误版本的 tensorflow 相关的错误,因此我按照另一个问题中的说明更改了库代码(见下文)。但这产生了更多错误,例如模块“tensorflow”没有属性“gfile”

Tensorflow 2.0 - AttributeError: module 'tensorflow' has no attribute 'Session'

https://github.com/iitzco/deepbrain

【问题讨论】:

    标签: python tensorflow


    【解决方案1】:

    在 TF 2.x 中,您应该使用 tf.compat.v1.Session() 而不是 tf.Session()。 查看Migrate_tf2 guide了解更多信息

    要在 TF 2.0 中获得类似 TF 1.x 的行为,请添加以下代码

    import tensorflow.compat.v1 as tf
    tf.disable_v2_behavior()
    

    【讨论】:

      猜你喜欢
      • 2019-08-04
      • 2021-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-29
      • 1970-01-01
      • 2020-07-20
      相关资源
      最近更新 更多