【发布时间】:2018-07-18 05:22:39
【问题描述】:
对于每个卷积激活图,我想连接一层常量——更具体地说,我想连接一个网格。 (这是为了转载 Uber 的一篇论文。)
例如,假设我有一个(?, 256, 256, 32) 的激活图;然后我想连接一个形状为(?, 256, 256, 1)的常量层。
这就是我的做法:
from keras import layers
import tensorflow as tf
import numpy as np
input_layer = layers.Input((256, 256, 3))
conv = layers.Conv2D(32, 3, padding='same')(input_layer)
print('conv:', conv.shape)
xx, yy = np.mgrid[:256, :256] # [(256, 256), (256, 256)]
xx = tf.constant(xx, np.float32)
yy = tf.constant(yy, np.float32)
xx = tf.reshape(xx, (-1, 256, 256, -1))
yy = tf.reshape(yy, (-1, 256, 256, -1))
print('xx:', xx.shape, 'yy:', yy.shape)
concat = layers.Concatenate()([conv, xx, yy])
print('concat:', concat.shape)
conv2 = layers.Conv2D(32, 3, padding='same')(concat)
print('conv2:', conv2.shape)
但我得到了错误:
conv: (?, 256, 256, 32)
xx: (?, 256, 256, ?) yy: (?, 256, 256, ?)
concat: (?, 256, 256, ?)
Traceback (most recent call last):
File "temp.py", line 21, in <module>
conv2 = layers.Conv2D(32, 3, padding='same')(concat)
[...]
raise ValueError('The channel dimension of the inputs '
ValueError: The channel dimension of the inputs should be defined. Found `None`.
问题是我的常量层是(?, 256, 256, ?),而不是(?, 256, 256, 1),然后下一个卷积层error-out。
我尝试了其他方法但没有成功。
PS:我试图实现的论文已经是implemented here。
【问题讨论】:
标签: tensorflow keras