首页 > 解决方案 > ImportError:无法从部分初始化的模块“tensorflow_estimator.python.estimator.canned.dnn”导入名称“dnn_logit_fn_builder”

问题描述

导入时使用jupyter notebookin aconda env会导致该错误tensorflow_hub

ImportError: cannot import name 'dnn_logit_fn_builder' from partially initialized module 
'tensorflow_estimator.python.estimator.canned.dnn' (most likely due to a circular import) 
(C:\Users\Anaconda3\envs\my_env\lib\site-packages\tensorflow_estimator\python\estimator\canned\dnn.py)

我的环境是通过安装 pandas、tensorflow-hub、numpy、tensorflow 和 python=3.8.5 创建的。

更多细节:

tensorflow                2.3.0           
tensorflow-base           2.3.0           
tensorflow-estimator      2.3.0              conda-forge
tensorflow-hub            0.12.0             conda-forge

为什么我会收到此错误?

标签: pythontensorflowconda

解决方案


与 Tensorflow 2.6.0 一起使用,api 名称几乎没有变化tf.compat.v1.estimator.experimental.dnn_logit_fn_builder

import tensorflow as tf
tf.compat.v1.estimator.experimental.dnn_logit_fn_builder

推荐阅读