【问题标题】:Convert the tensor variable(not constant) into numpy array? [duplicate]将张量变量(非常数)转换为 numpy 数组? [复制]
【发布时间】:2018-12-30 11:26:25
【问题描述】:

我正在将 CNN 模型的最后一个全连接层的嵌入转换为 numpy 数组。目前,嵌入是一个可变张量,它不是恒定的。我也想知道如何将其转换为 numpy 数组。

【问题讨论】:

  • 总是有一条消息说 InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder' with dtype float [[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=, _device= "/job:localhost/replica:0/task:0/device:GPU:0"]()]]

标签: tensorflow deep-learning conv-neural-network tensor


【解决方案1】:

您应该将张量值分配给会话中的变量! 像这样的东西。这是为了从一开始就取出瓶颈值。希望这会有所帮助。

with tf.Session(graph=graph) as sess:
    im_input = graph.get_tensor_by_name('inception/ExpandDims:0')
    Bottle_neck_values = []
    m = train.shape[0]
    indices = np.arange(m)
    for index in tqdm(range(0, m, 1)):
        batch = indices[index:index + 1]
        Bottle_neck_values.append(sess.run(bottleneck, feed_dict= 
                                                   {im_input:train[batch]}))
    df = pd.DataFrame(np.array(np.squeeze(Bottle_neck_values)))
    df.to_csv("./bottleneck/Bottle_neck_values.csv", index=False)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-17
    • 2018-11-28
    • 2021-10-13
    • 2018-06-27
    • 2020-12-31
    • 2021-01-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多