简体   繁体   中英

How to convert Keras Tensor into numpy array

I'm struggling to convert a simple Keras tensor into a Numpy array. This is the code I want to perform:

input = tf.keras.Input(shape=(100, 1), name='input')
inputs = np.array(input) 

Error: Cannot convert a symbolic Keras input/output to a numpy array.

First things first. Your input is not a tensor, but a symbolic tensor.

  1. So, what is symbolic tensor? - You can consider it as tensor without any value associated with it.
  2. Now, what is the use of symbolic tensor? - it actually helps you build a model framework so that it is ready to accept the input anytime later.

More can be found in this answer

Now, coming back to answer your question. You need to convert the symbolic tensor to a tensor by first feeding the network with the data. Once you have the tensor, then you can proceed to get the numpy array out of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM