【问题标题】:Why shape is changed in feeding to Tensorflow graph for Batch processing为什么形状在输入到 TensorFlow 图以进行批处理时会发生变化
【发布时间】:2020-01-13 01:28:27
【问题描述】:

图需要批量处理,输入形状定义为(None,60,80,19)(None,60,80,38)

TensorFlow图定义如下:

def __init__(self, tf_config=None):
     self.tensor_heatMat = tf.placeholder(
         dtype=tf.float32, shape=(None, 60, 80, 19), name='heatMat_in')
     self.tensor_pafMat = tf.placeholder(
         dtype=tf.float32, shape=(None, 60, 80, 38), name='pafMat_in')
     self.upsample_size = tf.placeholder(
         dtype=tf.int32, shape=(2,), name='upsample_size')
     self.tensor_heatMat_up = tf.image.resize_area(
         self.tensor_heatMat, self.upsample_size, align_corners=False, name='upsample_heatmat')
     self.tensor_pafMat_up = tf.image.resize_area(
         self.tensor_pafMat, self.upsample_size, align_corners=False, name='upsample_pafmat')
     smoother = Smoother({'data': self.tensor_heatMat_up}, 25, 3.0)
     gaussian_heatMat = smoother.get_output()
     max_pooled_in_tensor = tf.nn.pool(gaussian_heatMat, window_shape=(
         3, 3), pooling_type='MAX', padding='SAME')
     self.tensor_peaks = tf.where(tf.equal(
         gaussian_heatMat, max_pooled_in_tensor), gaussian_heatMat, tf.zeros_like(gaussian_heatMat))
     self.heatMat = self.pafMat = None
     self.persistent_sess = tf.InteractiveSession()
     self.persistent_sess.run(tf.variables_initializer(
        [v for v in tf.global_variables() if
         v.name.split(':')[0] in [x.decode('utf-8') for x in
                                  self.persistent_sess.run(tf.report_uninitialized_variables())]
         ])
     )


def inference(self, heatmat, pafmat, upsample_size=4.0):
    peaks, heatMat_up, pafMat_up = self.persistent_sess.run(
        [self.tensor_peaks, self.tensor_heatMat_up, self.tensor_pafMat_up], feed_dict={
            self.tensor_heatMat: [heatmat], self.tensor_pafMat: [pafmat], self.upsample_size: (240, 320)
        })
    peaks = peaks[0]
    self.heatMat = heatMat_up[0]
    self.pafMat = pafMat_up[0
    humans = PoseEstimator.estimate_paf(peaks, self.heatMat, self.pafMat)
    return humans

所以self.tensor_heatMatself.tensor_pafMat 需要批量张量。

我对这些占位符的输入数据是:

outputs = outputs.reshape(32, 60, 80, 57)
heat_maps = outputs[:, :, :, : 19]
puf_maps = outputs[:, :, :, 19:]     
humans = inference(heat_maps, puf_maps,4.0)

heat_mapspuf_maps 形状是 (32, 60, 80, 19)(32, 60, 80, 38)。 但是当我使用输入张量运行会话时,出现错误:

ValueError: 无法为形状为“(?, 60, 80, 19)”的张量“heatMat_in:0”提供形状 (1, 32, 60, 80, 19) 的值

可能是什么问题?

【问题讨论】:

    标签: python numpy tensorflow deep-learning conv-neural-network


    【解决方案1】:

    错误在feed_dict 中。如果将张量放在列表中,TensorFlow 会将列表解释为张量的第一维。这就是相同的(1, 32, ...) 的来源。你应该这样做

    feed_dict={
        self.tensor_heatMat: heatmat,
        self.tensor_pafMat: pafmat,
        self.upsample_size:(240,320)}
    

    第一个维度是 32,这是您在模型初始化方法中保留为 None 的变量批次。

    【讨论】:

      猜你喜欢
      • 2014-04-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2017-06-11
      • 2021-02-16
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多