keras - 导入错误: cannot import name '_obtain_input_shape'

标签 keras anaconda

当我运行时

from keras_vggface.vggface import VGGFace

# Based on VGG16 architecture -> old paper(2015)
vggface = VGGFace(model='vgg16') # or VGGFace() as default

# Based on RESNET50 architecture -> new paper(2017)
vggface = VGGFace(model='resnet50')

# Based on SENET50 architecture -> new paper(2017)
vggface = VGGFace(model='senet50')

instructions .

我收到这个错误

导入错误:无法导入名称“_obtain_input_shape”

我关注instructions安装 keras_vggface。这是我的包裹的列表信息。

# packages in environment at /Users/lzq/anaconda3/envs/py36_faceRec:
#
# Name                    Version                   Build  Channel
bleach                    1.5.0                     <pip>
ca-certificates           2018.03.07                    0  
certifi                   2018.10.15               py36_0  
enum34                    1.1.6                     <pip>
h5py                      2.8.0                     <pip>
html5lib                  0.9999999                 <pip>
Keras                     2.1.1                     <pip>
keras-vggface             0.5                       <pip>
libcxx                    4.0.1                hcfea43d_1  
libcxxabi                 4.0.1                hcfea43d_1  
libedit                   3.1.20170329         hb402a30_2  
libffi                    3.2.1                h475c297_4  
Markdown                  3.0.1                     <pip>
ncurses                   6.1                  h0a44026_0  
numpy                     1.15.4                    <pip>
openssl                   1.1.1                h1de35cc_0  
Pillow                    5.3.0                     <pip>
pip                       18.1                     py36_0  
protobuf                  3.6.1                     <pip>
python                    3.6.7                haf84260_0  
PyYAML                    3.13                      <pip>
readline                  7.0                  h1de35cc_5  
scipy                     1.1.0                     <pip>
setuptools                40.5.0                   py36_0  
six                       1.11.0                    <pip>
sqlite                    3.25.2               ha441bb4_0  
tensorflow                1.4.0                     <pip>
tensorflow-tensorboard    0.4.0                     <pip>
tk                        8.6.8                ha441bb4_0  
Werkzeug                  0.14.1                    <pip>
wheel                     0.32.2                   py36_0  
xz                        5.2.4                h1de35cc_4  
zlib                      1.2.11               hf3cbc9b_2 

最佳答案

您使用的 VGGFace 软件包是针对旧版本的 Keras 配置的。最简单的解决方案是编辑 vvgface 目录中的 keras-vggface/keras_vggface/models.py 文件并将第 15 行更改为:

从 keras.applications.imagenet_utils 导入 _obtain_input_shape

从 keras_applications.imagenet_utils 导入 _obtain_input_shape

或者,如果您觉得更简单,也可以将 Keras 降级到 2.2.0

关于keras - 导入错误: cannot import name '_obtain_input_shape' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53284746/

相关文章:

python - keras 调谐器的 'INFO:tensorflow:Oracle triggered exit' 是什么意思?

python - ValueError : Error when checking input: expected lstm_1_input to have shape (973, 215) 但得到形状为 (61, 215) 的数组

python-3.x - 怎么修?导入错误 : pycurl: libcurl link-time version is older than compile-time version

python - linux64 和 glibc 的 Conda UnsatisfiableError

python - Jupyter 笔记本显示空白页

keras - 如何使用 VGG-16 中的预训练特征作为 Keras 中 GlobalAveragePooling2D() 层的输入

python - 准确率始终为零

python - Keras 中的数据增强是如何工作的?

python - Jupyter:安装新模块

python - 导入 matplotlib ImportError : DLL load failed: The specified procedure could not be found