Please make sure that the boxes below are checked before you submit your issue. Thank you!
I am implement a model ,that take input: a sequence of image and a sequence of word. And I do this
with keras functional API. the code is below:
VGG_model = VGG_16()
VGG_model.trainable = False
from keras.layers import Input, Dense
from keras.models import Model
input_sequences = Input(shape=(5,3,244,244))
processed_sequences = TimeDistributed(VGG_model)(input_sequences) #outputshape=(None, 5, 4096)
processed_sequences=GRU(output_dim=4096, return_sequences=False)(processed_sequences)
processed_sequences=RepeatVector(1)(processed_sequences)#(None, 1, 4096)
max_caption_len = 21
vocab_size = 43
input_sequences_0=Input(shape=(max_caption_len-1,), dtype='int32')
input_sequences_l=Embedding(input_dim=vocab_size, output_dim=256,input_length=max_caption_len-1)(input_sequences_0)
input_sequences_l=GRU(output_dim=128, return_sequences=True)(input_sequences_l)
input_sequences_l=TimeDistributed(Dense(4096))(input_sequences_l)
merged=Merge([processed_sequences,input_sequences_l],mode='concat', concat_axis=1)
model = Model(input=[input_sequences,input_sequences_0], output=merged)
But I get the error at "merged=Merge([processed_sequences,input_sequences_l],mode='concat', concat_axis=1)
"
the error message is below, I am new to keras, Is anyone know why? thanks in advance
AttributeError Traceback (most recent call last)
<ipython-input-5-e58a6d91d287> in <module>()
15 input_sequences_l=TimeDistributed(Dense(4096))(input_sequences_l)#(None,max_caption_len-1,4096)input_sequences_lEGD=TimeDistributedDense(4096)(input_sequences_lEG)#(None,max_caption_len,4096)
16
---> 17 merged=Merge([processed_sequences,input_sequences_l],mode='concat', concat_axis=1)
18
19 model = Model(input=[input_sequences,input_sequences_0], output=merged)
C:\Anaconda2\lib\site-packages\keras\engine\topology.pyc in __init__(self, layers, mode, concat_axis, dot_axes, output_shape, node_indices, tensor_indices, name)
1112 concat_axis, dot_axes,
1113 output_shape,
-> 1114 node_indices, tensor_indices)
1115 self.built = True
1116 self.add_inbound_node(layers, node_indices, tensor_indices)
C:\Anaconda2\lib\site-packages\keras\engine\topology.pyc in _arguments_validation(self, layers, mode, concat_axis, dot_axes, output_shape, node_indices, tensor_indices)
1135 input_shapes = []
1136 for i, layer in enumerate(layers):
-> 1137 layer_output_shape = layer.get_output_shape_at(node_indices[i])
1138 if type(layer_output_shape) is list:
1139 # case: the layer has multiple output tensors
AttributeError: 'TensorVariable' object has no attribute 'get_output_shape_at'
Can you at least use syntax highlighting for your code?
@joelthchao I has edited it ,Is it clear now?
Merge is for model, while merge is for tensor. You can check the code and some useful docstrings.
from keras.layers import merge
merged = merge([processed_sequences, input_sequences_l], mode='concat', concat_axis=1)
@joelthchao
Thanks for help, now the error is gone !
Most helpful comment
Mergeis for model, whilemergeis for tensor. You can check the code and some useful docstrings.