python-3.x - tf.contrib.metrics.f1_score 无法导入
问题描述
我正在尝试使用 tf.contrib.metrics.f1_score 计算 F1 分数,但它给了我一个错误。我知道如何使用精度和召回率来计算它,但我想使用这个函数。
我已经在 ubuntu 16.04 LTS 上使用 tensorflow 版本 1.9.0 和 gpu 支持但没有 gpu 支持
from tensorflow.contrib.metrics import f1_score as ms
我收到此错误:
ImportError: Traceback (most recent call last)
<ipython-input-6-627f14191ea2> in <module>()----> 1 from tensorflow.contrib.metrics import f1_score as ms
ImportError: cannot import name 'f1_score'
和
from tensorflow.contrib import metrics as ms
ms.f1_score
我收到此错误:
AttributeError Traceback (most recent call last)
<ipython-input-8-c19f57465581> in <module>()
1 from tensorflow.contrib import metrics as ms
----> 2 ms.f1_score
AttributeError: module 'tensorflow.contrib.metrics' has no attribute 'f1_score'
我希望 ms.f1_score 会加载
解决方案
如果您确定您有tf.contrib
可用的并且这对您不起作用,那么您可能需要重新安装 tensorflow 使用pip install -U tensorflow
或使用 -GPU 如果您正在使用该版本。
如果失败,请到安装tensorflow的地方手动检查是否可用,如果可用,请确保在同一目录(当前工作目录)下没有名为tensorflow的文件。 py 或 tf.py
更新:正如用户@grwlf 所指出的
自 TensorFlow 2.0 起,tf.contrib 模块已移至 Addons 存储库。请参阅 github.com/tensorflow/addons。在那里,F1 mesure 可作为 F1Score 从tensorflow_addons.metrics import F1Score
推荐阅读
- python - 使用pandas按列分组,然后根据条件新建一列
- android - Android Studio上的gradle项目同步失败错误
- c# - 如何处理 Controller 的 Initialize 方法抛出的异常?
- tensorflow - LSTM 或任何其他层的 TimeDistributed 包装器有什么用途
- assertion - 如何在 Junit 中使用 Assert array Equals 比较 2 个对象数组
- php - 更改会话目录 PHP
- python - 为 n 维数组推广 Cython 代码
- javascript - 需要创建一个新数组而不是为我的 React 组件推送数据
- javascript - Vue js 事件中的命名空间
- jquery - 滚动在移动设备上不起作用,特别是在 chrome 浏览器中