无法在Keras中实例化Xception模型

时间:2018-05-31 18:42:33

标签: python tensorflow keras

我在多GPU机器上的NVIDIA Docker容器中运行Keras。我想实例化一个相当标准的模型(Xception),但我一直都会遇到奇怪的错误。 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和&amp;的版本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')

1 个答案:

答案 0 :(得分:2)

对于keras和tensorflow 1.4版本来说,这似乎是一个众所周知的问题here。您可能希望将两者更新到最新版本以解决此问题。