python - Keras Backend Modeling Issue -
i having issue declaring model. inputs x_input , y_input, , outputs predictions. follows:
model = model(inputs = [x_input, y_input], outputs = predictions )
my inputs (x,y) both embedded, matmult together. follows:
# build x branch x_input = input(shape = (maxlen_x,), dtype = 'int32' ) x_embed = embedding( maxvocab_x + 1, 16, input_length = maxlen_x ) xe = x_embed(x_input) # result: tensor("embedding_1/gather:0", shape=(?, 31, 16), dtype=float32) # 31 happens maxlen_x
similarly y branch...
# build y branch y_input = input(shape = (maxlen_y,), dtype = 'int32' ) y_embed = embedding( maxvocab_y + 1, 16, input_length = maxlen_y ) ye = y_embed(y_input) # result: tensor("embedding_1/gather:0", shape=(?, 13, 16), dtype=float32) # 13 happens maxlen_y
i batch dot between two. (simply dotting data each instance)
from keras import backend k dot_merged = k.batch_dot(xe, ye, axes=[2,2] ) # choose 2nd component of both inputs dot, using batch_dot # result: tensor("matmul:0", shape=(?, 31, 13), dtype=float32)`
i flattened last 2 dimensions of tensor.
dim = np.prod(list(dot_merged.shape)[1:]) flattened= k.reshape(dot_merged, (-1,int(dim)) )
ultimately, fed flattened data simple logistic regressor.
predictions = dense(1,activation='sigmoid')(flattened)
and, predictions are, of course, output model.
i list output of each layer output shape of tensor.
tensor("embedding_1/gather:0", shape=(?, 31, 16), dtype=float32) tensor("embedding_2/gather:0", shape=(?, 13, 16), dtype=float32) tensor("matmul:0", shape=(?, 31, 13), dtype=float32) tensor("reshape:0", shape=(?, 403), dtype=float32) tensor("dense_1/sigmoid:0", shape=(?, 1), dtype=float32)
i following error, specifically.
traceback (most recent call last): file "model.py", line 53, in <module> model = model(inputs = [dx_input, rx_input], outputs = [predictions] ) file "/users/jiangq/tensorflow/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 88, in wrapper return func(*args, **kwargs) file "/users/jiangq/tensorflow/lib/python3.6/site-packages/keras/engine/topology.py", line 1705, in __init__ build_map_of_graph(x, finished_nodes, nodes_in_progress) file "/users/jiangq/tensorflow/lib/python3.6/site-packages/keras/engine/topology.py", line 1695, in build_map_of_graph layer, node_index, tensor_index) file "/users/jiangq/tensorflow/lib/python3.6/site-packages/keras/engine/topology.py", line 1665, in build_map_of_graph layer, node_index, tensor_index = tensor._keras_history attributeerror: 'tensor' object has no attribute '_keras_history'
volia. did go wrong? ahead of time!
-anthony
did tried wrapping backend functions lambda
layer? think there necessary operations within keras layer's __call__()
method keras model
built, not executed if call backend functions directly.
Comments
Post a Comment