首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在keras中按行合并张量和向量

在keras中按行合并张量和向量
EN

Stack Overflow用户
提问于 2017-06-16 15:51:56
回答 1查看 383关注 0票数 0

我希望在keras中实现PointNet的一个变体(https://arxiv.org/pdf/1612.00593.pdf),但我在重复上下文向量(g)的可变次数时遇到了麻烦,这样我就可以按行将其与缺少上下文的前一层连接起来(Pre)。我尝试了Repeat()和keras.backend.Tile()。

代码语言:javascript
复制
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定义。

代码语言:javascript
复制
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。

更新:

因此,通过执行以下操作,我能够让这些层不给出错误:

代码语言:javascript
复制
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])

但是现在,我得到了以下错误:

代码语言:javascript
复制
AttributeError: 'Tensor' object has no attribute '_keras_history'
EN

回答 1

Stack Overflow用户

发布于 2017-06-16 18:05:33

我怀疑罪魁祸首是K.get_variable_shape(v[0])。由于v[0]的类型为int32 (正如您的错误所指定的那样),因此当您获得形状时,它将返回None。Concatenate希望所有输入都属于同一类型。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44583792

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档