无法在Keras中实例化Xception模型 [英] cannot instantiate an Xception model in Keras

查看:317
本文介绍了无法在Keras中实例化Xception模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在多GPU机器上的NVIDIA Docker容器中运行Keras.我想实例化一个相当标准的模型(Xception),但是我总是收到奇怪的错误. MRE:

I'm running Keras in an NVIDIA Docker container on a multi-GPU machine. I'd like to instantiate a fairly standard model (Xception), but I keep getting weird errors. MRE:

import tensorflow as tf
from keras.applications import Xception

height = 299
width = 299
num_classes = 1000

# Instantiate model
model = Xception(weights=None, input_shape=(height, width, 3), classes=num_classes)

我得到了错误:

Traceback (most recent call last):
  File "basic_test.py", line 9, in <module>
    model = Xception(weights=None, input_shape=(height, width, 3), classes=num_classes)
  File "/usr/local/lib/python2.7/dist-packages/keras/applications/xception.py", line 235, in Xception
    x = Dense(classes, activation='softmax', name='predictions')(x)
  File "/usr/local/lib/python2.7/dist-packages/keras/engine/topology.py", line 619, in __call__
    output = self.call(inputs, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/keras/layers/core.py", line 881, in call
    output = self.activation(output)
  File "/usr/local/lib/python2.7/dist-packages/keras/activations.py", line 29, in softmax
    return K.softmax(x)
  File "/usr/local/lib/python2.7/dist-packages/keras/backend/tensorflow_backend.py", line 2963, in softmax
    return tf.nn.softmax(x, axis=axis)
TypeError: softmax() got an unexpected keyword argument 'axis'

适用于Python,Keras&的版本Tensorflow:

Versions for Python, Keras & Tensorflow:

python -c 'import keras; import tensorflow; import sys; print(sys.version, 'keras.__version__', 'tensorflow.__version__')'
Using TensorFlow backend.
('2.7.12 (default, Nov 20 2017, 18:23:56) \n[GCC 5.4.0 20160609]', '2.1.6', '1.4.0')

推荐答案

似乎是keras和tensorflow 1.4版本的已知问题,如

It seems its a known issue with keras and tensorflow 1.4 version as mentioned here. You may want to update both to the latest version to resolve this issue.

这篇关于无法在Keras中实例化Xception模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆