Sathiyakugan
Sathiyakugan

Reputation: 684

How to add addition in concatenate Layers keras

Y = Dense(2)(Y)
Z = LSTM(128, return_sequences=False)(X)
Z = Dense(2)(Z)
M = concatenate([Y, Z,Y+Z])
M=Dense(4)(M)
M = Dense(2)(M)
# Add a softmax activation
M = Activation('softmax')(M)

# Create Model instance which converts sentence_indices into X.
model = Model(inputs=sentence_indices, outputs=M)

return model

The given block is my code. Here, I have given the partial code. What I want is I want to merge layers using M = concatenate([Y, Z]), it is working fine. Then I thought of adding more variables to the Dense layer so I add M = concatenate([Y, Z,Y+Z]); however, it's not working. It gave me this error:

Traceback (most recent call last):
  File "/home/sathiyakugan/PycharmProjects/internal-apps/apps/support-tools/EscalationApp/IMDBmodified.py", line 213, in <module>
    model = buildModel((maxLen,), word_to_vec_map, word_to_index)
  File "/home/sathiyakugan/PycharmProjects/internal-apps/apps/support-tools/EscalationApp/IMDBmodified.py", line 206, in buildModel
    model = Model(inputs=sentence_indices, outputs=M)
  File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/keras/engine/network.py", line 91, in __init__
    self._init_graph_network(*args, **kwargs)
  File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/keras/engine/network.py", line 235, in _init_graph_network
    self.inputs, self.outputs)
  File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/keras/engine/network.py", line 1412, in _map_graph_network
    tensor_index=tensor_index)
  File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/keras/engine/network.py", line 1399, in build_map
    node_index, tensor_index)
  File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/keras/engine/network.py", line 1399, in build_map
    node_index, tensor_index)
  File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/keras/engine/network.py", line 1399, in build_map
    node_index, tensor_index)
  File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/keras/engine/network.py", line 1399, in build_map
    node_index, tensor_index)
  File "/home/sathiyakugan/PycharmProjects/Python/venv/lib/python3.5/site-packages/keras/engine/network.py", line 1371, in build_map
    node = layer._inbound_nodes[node_index]
AttributeError: 'NoneType' object has no attribute '_inbound_nodes' 

Could you please help me to resolve this problem?

Upvotes: 0

Views: 140

Answers (1)

today
today

Reputation: 33430

You can use add functional interface (or its equivalent Add layer):

A = add([Y, Z])
M = concatenate([Y, Z, A])

Upvotes: 1

Related Questions