本文介绍了张量流,图像分割卷积InvalidArgumentError:重塑的输入是具有28800000值的张量,但请求的形状为57600的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对BRATS挑战中的图像进行细分。我在这两个存储库的组合中使用U-net:

I am trying to segment images from the BRATS challenge. I am using U-net in a combination of these two repositories:

何时我尝试输出预测统计信息,出现不匹配形状错误:

When I try to output the prediction statistics a mismatch shape error come up:

我正在使用240x240的图像切片,batch_verification_size = 500

I am using image slices 240x240, with a batch_verification_size = 500

然后,


  • 这是形状test_x:(500,240,240, 1)

  • 这是形状test_y:(500, 240,240,1)

  • 这是形状测试x:(500,240,240,1)

  • 这是形状测试y:( 500,240,240,1)

  • 这是形状批次x:(500,240,240,1)

  • 这是形状批次y :(500,240,240,1)

  • 这是形状预测:(500,240,240,1)

  • 这是成本: Tensor( add_88:0,shape =(),dtype = float32)

  • 这是成本:Tensor( Mean_2:0,shape =(),dtype = float32)

  • 这是形状预测:(?,?,?,1)

  • 这是形状批处理x:(500,240,240,1)

  • 这是形状批次y:(500、240、240、1)

  • this is shape test_x: (500, 240, 240, 1)
  • this is shape test_y: (500, 240, 240, 1)
  • this is shape test x: (500, 240, 240, 1)
  • this is shape test y: (500, 240, 240, 1)
  • this is shape batch x: (500, 240, 240, 1)
  • this is shape batch y: (500, 240, 240, 1)
  • this is shape prediction: (500, 240, 240, 1)
  • this is cost : Tensor("add_88:0", shape=(), dtype=float32)
  • this is cost : Tensor("Mean_2:0",shape=(), dtype=float32)
  • this is shape prediction: (?, ?, ?, 1)
  • this is shape batch x: (500, 240, 240, 1)
  • this is shape batch y: (500, 240, 240, 1)

240 x 240 x 500 = 28800000
我不知道为什么要请求57600

240 x 240 x 500 = 28800000I don't know why is requesting 57600

似乎错误是由 output_minibatch_stats 函数:

summary_str, loss, acc, predictions = sess.run([self.summary_op,
                                                self.net.cost, self.net.accuracy,
self.net.predicter],
feed_dict={self.net.x: batch_x,
self.net.y: batch_y,
self.net.keep_prob: 1.})

因此sess.run tf函数出了点问题。以下是一些出现错误的代码。有人知道会发生什么吗?

Therefore something is wrong in sess.run tf function. Below is some code where the error come up. Anybody got any idea what would happen?

def store_prediction(self, sess, batch_x, batch_y, name):
    print('track 1')
            prediction = sess.run(self.net.predicter, feed_dict={self.net.x: batch_x,
                                                                 self.net.y: batch_y,
                                                                 self.net.keep_prob: 1.})
            print('track 2')
            pred_shape = prediction.shape



loss = sess.run(self.net.cost, feed_dict={self.net.x: batch_x,
                                                       self.net.y: batch_y, `
                                                       self.net.keep_prob: 1.})
        print('track 3')
        logging.info("Verification error= {:.1f}%, loss= {:.4f}".format(error_rate(prediction,
                                                                          util.crop_to_shape(batch_y,
                                                                                             prediction.shape)),
                                                                          loss))
        print('track 4')
        print('this is shape batch x: ' + str(batch_x.shape))
        print('this is shape batch y: ' + str(batch_y.shape))
        print('this is shape prediction: ' + str(prediction.shape))
        #img = util.combine_img_prediction(batch_x, batch_y, prediction)
        print('track 5')
        #util.save_image(img, "%s/%s.jpg"%(self.prediction_path, name))

        return pred_shape

    def output_epoch_stats(self, epoch, total_loss, training_iters, lr):
        logging.info("Epoch {:}, Average loss: {:.4f}, learning rate: {:.4f}".format(epoch, (total_loss / training_iters), lr))

    def output_minibatch_stats(self, sess, summary_writer, step, batch_x, batch_y):
        print('this is shape cost : ' + str(self.net.cost.shape))
        print('this is cost : ' + str(self.net.cost))
        print('this is  acc : ' + str(self.net.accuracy.shape))
        print('this is cost : ' + str(self.net.accuracy))
        print('this is shape prediction: ' + str(self.net.predicter.shape))
        print('this is shape batch x: ' + str(batch_x.shape))
        print('this is shape batch y: ' + str(batch_y.shape))


        # Calculate batch loss and accuracy
        summary_str, loss, acc, predictions = sess.run([self.summary_op,
                                                            self.net.cost,
                                                            self.net.accuracy,
                                                            self.net.predicter],
                                                           feed_dict={self.net.x: batch_x,
                                                                      self.net.y: batch_y,
                                                                      self.net.keep_prob: 1.})
        print('track 6')
        summary_writer.add_summary(summary_str, step)
        print('track 7')
        summary_writer.flush()
        logging.info("Iter {:}, Minibatch Loss= {:.4f}, Training Accuracy= {:.4f}, Minibatch error= {:.1f}%".format(step,
                                                                                                            loss,
                                                                                                            acc,
                                                                                                            error_rate(predictions, batch_y)))
        print('track 8')


推荐答案

您在训练期间在张量流管道中将批量大小设置为1,但是批量喂入500只在您的测试数据中。这就是为什么网络仅请求形状为57600的张量的原因。
您可以将训练批大小设置为500或将测试批大小设置为1。

You set your batch size as 1 in your tensorflow pipeline during training but feeding in 500 batch size in your testing data. Thats why the network requests only a tensor of shape 57600.You can either set your training batch size 500 or testing batch size as 1.

这篇关于张量流,图像分割卷积InvalidArgumentError:重塑的输入是具有28800000值的张量,但请求的形状为57600的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 15:20