Keras 卷积选项 "channels_first" 是否适用于 Tensorflow?
Does Keras convolution option "channels_first" work with Tensorflow?
Conv2D 层的 Keras 文档暗示 "channels_first" 的值可用于参数 data_format,支持 "NCHW" 格式的数据,而不是默认的 "NHWC"格式。但这在下面的代码中似乎不起作用。
import tensorflow as tf
tf.enable_eager_execution()
#this works:
data = tf.random.uniform((1,5,5,1))
model = tf.keras.Sequential([tf.keras.layers.Conv2D(1,(3,3),data_format="channels_last")])
model(data)
#this doesn't:
data = tf.random.uniform((1,1,5,5))
model = tf.keras.Sequential([tf.keras.layers.Conv2D(1,(3,3),data_format="channels_first")])
model(data)
对于 "channels_first" 案例,我收到消息:
UnimplementedError: Generic conv implementation only supports NHWC tensor format for now. [Op:Conv2D]
我是不是犯了一些愚蠢的错误?
Keras 可与两个后端一起使用:Theano 和 TensorFlow。
Theano 使用 "channels_first" 格式 (NCHW) 而 TensorFlow 使用 "channels_last" 格式 (NHWC)。据我所知,TensorFlow 后端不支持 "channels_first" 格式 。
Conv2D 层的 Keras 文档暗示 "channels_first" 的值可用于参数 data_format,支持 "NCHW" 格式的数据,而不是默认的 "NHWC"格式。但这在下面的代码中似乎不起作用。
import tensorflow as tf
tf.enable_eager_execution()
#this works:
data = tf.random.uniform((1,5,5,1))
model = tf.keras.Sequential([tf.keras.layers.Conv2D(1,(3,3),data_format="channels_last")])
model(data)
#this doesn't:
data = tf.random.uniform((1,1,5,5))
model = tf.keras.Sequential([tf.keras.layers.Conv2D(1,(3,3),data_format="channels_first")])
model(data)
对于 "channels_first" 案例,我收到消息:
UnimplementedError: Generic conv implementation only supports NHWC tensor format for now. [Op:Conv2D]
我是不是犯了一些愚蠢的错误?
Keras 可与两个后端一起使用:Theano 和 TensorFlow。
Theano 使用 "channels_first" 格式 (NCHW) 而 TensorFlow 使用 "channels_last" 格式 (NHWC)。据我所知,TensorFlow 后端不支持 "channels_first" 格式 。