[英]How to convert Keras Tensor into numpy array
I'm struggling to convert a simple Keras tensor into a Numpy array.我正在努力将一个简单的 Keras 张量转换为 Numpy 数组。 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.
错误: Cannot convert a symbolic Keras input/output to a numpy array.
First things first.第一件事。 Your input
is not a tensor, but a symbolic tensor.您的input
不是张量,而是符号张量。
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.获得张量后,您可以继续从中取出 numpy 数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.