关于keras中的set_image_dim_ordering('tf')

时间:2016-11-19 21:10:01

标签: tensorflow keras

在尝试使用Keras实现时,我做了如下:

from keras import backend as K
K.set_image_dim_ordering('tf') 

它会生成以下错误消息。这是什么意思?我认为set_image_dim_ordering包含在Keras中。

File "train.py", line 14, in <module>
K.set_image_dim_ordering('tf')

AttributeError:'module'对象没有属性'set_image_dim_ordering'

8 个答案:

答案 0 :(得分:3)

尝试一下:

from keras import backend as K K.tensorflow_backend.set_image_dim_ordering('th')

答案 1 :(得分:2)

Keras 是深度学习框架,可以使用来自“TensorFlow”、“Theano”和“CNTK”作为后端。 每个后端都有自己的偏好使用频道排序

  • Theano:通道一阶
  • Tensorflow:通道最后一个订单
  • CNTK:渠道最后订单

如果你使用'Theano'作为后端,你应该设置“channels_first order”并且在导入keras库之后你可以使用这行代码:

keras.backend.set_image_data_format('channels_first')

和数据形状如下:(通道,行,列)。

注意“数据形状”中的通道顺序应与“后端”中的通道顺序相同。例如,如果您使用 Tensorflow 作为后端,则数据的输入形状应该是 channel last order(对于 RGB 图像:(行、列、channel ))

答案 2 :(得分:1)

在Keras 2.3.1中使用:

from keras as backend as K
K.common.set_image_dim_ordering('th')

是的。它适用于Keras 2.3.1版

答案 3 :(得分:0)

在Keras 2.3.1中使用:

from keras as backend as K
K.common.set_image_dim_ordering('th')

答案 4 :(得分:0)

您使用的是什么版本?

”“在后端,set_image_orderingimage_ordering现在是set_data_formatdata_format.

Keras 2.0 Release notes

答案 5 :(得分:0)

对于tensorflow V2.3

import tensorflow.keras.backend as K
# to know the image order
K.image_data_format()
# to set the image order
K.set_image_data_format()

答案 6 :(得分:0)

要同时支持新旧版本的 Keras,对于 theano 和 tensorflow,您可以使用:

try:
    if K.backend() == 'theano':
        K.set_image_data_format('channels_first')
    else:
        K.set_image_data_format('channels_last')
except AttributeError:
    if K._BACKEND == 'theano':
        K.set_image_dim_ordering('th')
    else:
        K.set_image_dim_ordering('tf') 

(摘自“https://github.com/Arsey/keras-transfer-learning-for-oxford102/blob/master/util.py”)

答案 7 :(得分:-1)

您可能需要这样做:

from keras import backend as K
K.set_image_dim_ordering("th")