tensorflow_hmm使用Session模块时报错:AttributeError: module ‘tensorflow‘ has no attribute ‘Session‘,已解决

45 篇文章 0 订阅

 tensorflow_hmm:https://pypi.org/project/tensorflow_hmm/

当运行https://github.com/dwiel/tensorflow_hmm中的examples时候,

tf_s = tf.Session().run(tf_s_graph)

出现了如下的错误:

错误的意思是tensortflow模块没有Session属性,后来查阅资料发现,tensorflow2.0版本中的确没有Session这个属性:

 如果安装的是tensorflow2.0版本又想利用Session属性,可以将tf.Session()更改为:

tf.compat.v1.Session()

这个方法可以解决此类问题,不仅仅适用于Session属性。

再次运行时,程序又报了另一个错误:

 查阅资料发现,原因是2.0与1.0版本不兼容,在程序开始部分添加以下代码:

tf.compat.v1.disable_eager_execution()

就可以正常运行了。

 tensorflow的官网对disable_eager_execution()方法是这样解释的:

1

This function can only be called before any Graphs, Ops, or Tensors have been created. <br>It can be used at the beginning of the program for complex migration projects from TensorFlow 1.x to 2.x.

翻译过来为:此函数只能在创建任何图、运算或张量之前调用。它可以用于从TensorFlow 1.x到2.x的复杂迁移项目的程序开头。

于是在引用tensorflow时,直接用:

import tensorflow.compat.v1 as tf

但是 tf.compat.v1.disable_eager_execution()还是要将继续用的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据提供的引用内容,AttributeError: module 'options_storage' has no attribute 'hmm_mode' 是由于在程序中引用了名为'options_storage'的模块,但该模块中没有名为'hmm_mode'的属性。这个错误通常表示在代码中尝试访问一个不存在的属性或方法。要解决这个问题,你可以检查代码中对'options_storage'模块的导入语句,并确保在该模块中存在名为'hmm_mode'的属性。 请注意,这个问题的解决方法可能因具体的代码和环境而异。如果你能提供更多的代码和上下文信息,我可以给出更具体的建议。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [求解报错AttributeError:module ‘os’ has no attribute ‘exit’](https://download.csdn.net/download/weixin_38590309/14856609)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [How rdp passwords are encrypted](https://blog.csdn.net/sun280/article/details/10472169)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值