![](/img/trans.png)
[英]Error passing tensor/vector to a custom loss_function in keras
[英]Merging tensor rowwise with a vector in keras
我希望在keras中实现PointNet( https://arxiv.org/pdf/1612.00593.pdf )的变体,但是我在重复上下文向量(g)可变的次数时遇到麻烦,因此我无法进行串联它与缺少context(pre)的上一层按行排列。 我尝试过Repeat()和keras.backend.Tile()。
input = Input(shape=(None,3))
x = TimeDistributed(Dense(128, activation = 'relu'))(input)
pre = TimeDistributed(Dense(256, activation = 'relu'))(x)
g = GlobalMaxPooling1D()(pre)
x = Lambda(merge_on_single, output_shape=(None,512))([pre,g])
print(x.shape)
这是我想出的lambda定义。
def merge_on_single(v):
#v[0] is variable length tensor, v[1] is the single vector
return Concatenate()([K.repeat(v[1],K.get_variable_shape(v[0])),v[0]])
但是,发生以下错误:
TypeError:传递给“ Pack” Op的“ values”的列表中的张量具有不完全匹配的[int32,,int32]类型。
更新:
因此,通过执行以下操作,我可以使各层不出错:
input = Input(shape=(None,3))
num_point = K.placeholder(input.get_shape()[1].value, dtype=tf.int32)
#first global feature layer
x = TimeDistributed(Dense(512, activation = 'relu'))(input)
x = TimeDistributed(Dense(256, activation = 'relu'))(x)
g = GlobalMaxPooling1D()(x)
g = K.reshape(g,(-1,1,256))
g = K.tile(x, [1,num_point,1])
concat_feat = K.concatenate([x, g])
但是现在,我收到以下错误:
AttributeError: 'Tensor' object has no attribute '_keras_history'
我怀疑罪魁祸首是K.get_variable_shape(v[0])
。 由于v[0]
的类型为int32
(如您的错误所指定),因此当获得形状时,它将返回None。 串联希望所有输入为同一类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.