2017-06-16 319 views
0

我曾希望实现keras中的PointNet(https://arxiv.org/pdf/1612.00593.pdf)的变体,但我无法重复上下文向量(g)的次数可变,所以我可以将它连接起来与前一层缺少上下文(前)的行。我尝试了Repeat()和keras.backend.Tile()。将张量与keras中的向量合并为一个向量

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]]) 

但出现以下错误:

类型错误:在列表张量传递给“包”作品的“价值”有类型[INT32,INT32]并不都匹配。

UPDATE:

所以我能得到的层不是做给错误如下:

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' 

回答

0

我怀疑罪魁祸首是K.get_variable_shape(v[0])。由于v[0]的类型为int32(按照您的错误指定),因此当您获取形状时,它将返回无。连接要求所有输入都是相同的类型。