【问题标题】:How to convert TensorVariable to numpy如何将 TensorVariable 转换为 numpy
【发布时间】:2020-06-09 14:06:54
【问题描述】:

我想将 TensorVariable 转换为 numpy 数组并尝试:

feature_vector = keras_model.get_layer(blob_name).output.numpy()

但得到错误。

AttributeError: 'TensorVariable' 对象没有属性 'numpy'

我也试过了:

feature_vector = keras_model.get_layer(blob_name).output
init = tf.compat.v1.global_variables_initializer()

with tf.compat.v1.Session() as sess:
    sess.run(init)
    print(feature_vector.eval())

但报错

theano.gof.fg.MissingInputError: 图表的输入 0(索引开始 从 0),用于计算 Shape(/input_1),没有提供,也没有 给定一个值。使用 Theano 标志 exception_verbosity='high',对于 有关此错误的更多信息。

【问题讨论】:

  • 您的错误消息指出,您将 theano 后端用于 keras。如果您提供导入,我们可以解决此问题。

标签: numpy tensorflow keras keras-layer tensor


【解决方案1】:

谢谢@Lau。是的,我使用 theano 并修复了这个错误,如this

【讨论】:

    猜你喜欢
    • 2014-09-04
    • 2020-03-27
    • 1970-01-01
    • 2017-11-04
    • 1970-01-01
    • 2021-12-14
    • 2017-01-29
    • 2016-07-01
    • 2015-12-17
    相关资源
    最近更新 更多