Keras: How can keras unpack a tensor to a list

Created on 29 Mar 2017  路  5Comments  路  Source: keras-team/keras

My idea is as follow

question = Input(shape=(enc_timesteps,), dtype='int32', name='question_base')
answer_good = Input(shape=(dec_timesteps,), dtype='int32', name='answer_good_base')
answer_bad = Input(shape=(random_size,dec_timesteps,), dtype='int32', name='answer_bad_base')
good_sim = basic_model([question,answer_good])
bad_sim_list = [basic_model([question,bad_answer_single]) for bad_answer_single in keras.unpack(bad_answer)] 
# NOTICE!!! I want to know how to realize keras.unpack
assert len(bad_sim_list) == random_size
bad_sim = merge(bad_sim_list,mode="sum")

Thanks for everybody's reply.

stale

Most helpful comment

@Dref360 can you give an example how please ?
why is there a stack in keras backend but no unstack
https://www.tensorflow.org/api_docs/python/tf/keras/backend/stack

All 5 comments

This question is best suited for StackOverflow.
Unpack is not implemented in Keras, but there is tf.unstack if you use Tensorflow backend.
https://www.tensorflow.org/api_docs/python/tf/unstack

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.

Thanks. But with tensorflow backend, after using tf.unstack, keras seems don't work with tf-tensor

TypeError: Input tensors to a Model must be Keras tensors. Found: Tensor("unstack:0", shape=(?, 2048), dtype=float32) (missing Keras metadata).

Use a Lambda layer

@Dref360 can you give an example how please ?
why is there a stack in keras backend but no unstack
https://www.tensorflow.org/api_docs/python/tf/keras/backend/stack

Was this page helpful?
0 / 5 - 0 ratings