【问题标题】:Computation on a Tensor as numpy array in graph?将张量计算为图中的 numpy 数组?
【发布时间】:2016-12-11 10:15:12
【问题描述】:

有没有办法对图中的张量进行一些计算。

以我的图表为例:

slim = tf.contrib.slim

def slim_graph(images, train=False):
    with slim.arg_scope([slim.conv2d, slim.fully_connected],
                  activation_fn=tf.nn.relu,
                  weights_initializer=tf.truncated_normal_initializer(0.0, 0.01),
                  weights_regularizer=slim.l2_regularizer(0.0005)):
        net = slim.repeat(images, 2, slim.conv2d, 64, [3, 3], scope='conv1')
        // Do my compute by numpy on net

        np_array_result = my_func(net)

        // It will return a numpy array
        // Use numpy array as input of graph

        net = slim.max_pool2d(np_array_result, [2, 2], scope='pool1')

        ...
        return logits
  • 我们可以这样做吗?
  • 如何获取图中的特征图进行计算?

我可以将图形分成两部分并使用 Session.run([part1]) 之后使用结果输入我的函数,然后将其提供给 Session.run([part2])

但这似乎很奇怪。

【问题讨论】:

  • 是的,像你展示的那样分成两部分是这样做的方法
  • @YaroslavBulatov :当我做转发网时,似乎还可以。在进行训练步骤时,我们如何运行损失函数和梯度?得到part2的结果后计算loss并对其应用梯度?

标签: python numpy tensorflow deep-learning


【解决方案1】:

您可以使用tf.py_func 包装python 函数。

【讨论】:

    猜你喜欢
    • 2020-12-21
    • 2021-10-17
    • 2018-11-28
    • 1970-01-01
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 1970-01-01
    • 2016-03-09
    相关资源
    最近更新 更多