对于每个卷积激活映射,我想连接一层常量——更具体地说,我想连接一个网格网格。(这是为了复制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页)
,然后下一个卷积层出错。
我尝试过其他事情,但没有成功。
PS:我试图实现的文件已经
implemented here
是的。