Exemple #1
0
    def store_prediction(self, sess, batch_x, batch_y, batch_z, name):
        prediction, blurpredict = sess.run(
            [self.net.predicter, self.net.blurpredict],
            feed_dict={
                self.net.x: batch_x,
                self.net.y: batch_y,
                self.net.z: batch_z,
                self.net.keep_prob: 1.
            })
        pred_shape = prediction.shape
        blurpred_shape = blurpredict.shape

        loss = sess.run(self.net.cost,
                        feed_dict={
                            self.net.x: batch_x,
                            self.net.y:
                            util.crop_to_shape(batch_y, pred_shape),
                            self.net.z: batch_z,
                            self.net.keep_prob: 1.
                        })

        logging.info("Verification error= {:.1f}%, loss= {:.4f}".format(
            error_rate(prediction,
                       util.crop_to_shape(batch_y, prediction.shape)), loss))

        img = util.combine_img_prediction(batch_x, batch_y, prediction)
        util.save_image(img, "%s/%s.jpg" % (self.prediction_path, name))

        return pred_shape, blurpred_shape
Exemple #2
0
    def store_prediction(self, sess, batch_x, batch_y, name):
        y = crop_to_shape_v2(batch_y, self.in_shape)
        #print(y.shape)
        prediction = sess.run(self.predicter,
                              feed_dict={
                                  self.x:
                                  crop_to_shape_v2(batch_x, self.in_shape),
                                  self.y: y,
                                  self.Dropout_Rate: 0.,
                                  self.IsTraining: False
                              })

        loss = sess.run(self.loss,
                        feed_dict={
                            self.x: crop_to_shape_v2(batch_x, self.in_shape),
                            self.y: y,
                            self.IsTraining: False,
                            self.Dropout_Rate: 0
                        })

        logging.info("Verification error= {:.1f}%, loss= {:.4f}".format(
            error_rate(prediction, crop_to_shape_v2(batch_y, self.in_shape)),
            loss))

        img = util.combine_img_prediction(batch_x, batch_y, prediction)
        util.save_image(img, "%s/%s.jpg" % (self.prediction_path, name))
Exemple #3
0
    def validate(self, sess, test_size, x_provider, y_provider, n_epoch):
        self.net.is_training = False
        mean_dice = 0
        mean_iou = 0
        for val_index in range(test_size):
            val_x, val_y = sess.run([x_provider, y_provider])
            prediction, loss = sess.run([self.net.predicter, self.net.loss],
                                        feed_dict={
                                            self.net.x: val_x,
                                            self.net.y: val_y,
                                        })
            img_predict = prediction.reshape((self.nx, self.ny, 4))
            img_predict = self.remove_minor_cc(img_predict, 0.3, 4)
            img_y = val_y.reshape((self.nx * self.ny, 4))
            img_predict = img_predict.reshape((self.nx * self.ny, 4))
            dice, iou = sess.run([self.net.dice, self.net.iou],
                                 feed_dict={
                                     self.net.img_pred: img_predict,
                                     self.net.img_y: img_y
                                 })
            dice1 = dice[0]
            dice2 = dice[1]
            dice3 = dice[2]
            dice = (dice1 + dice2 + dice3) / 3
            iou1 = iou[0]
            iou2 = iou[1]
            iou3 = iou[2]
            iou = (iou1 + iou2 + iou3) / 3
            mean_dice += dice
            mean_iou += iou
            if val_index == 0:
                img = util.combine_img_prediction(val_x, img_y[:, 1],
                                                  img_predict[:, 1],
                                                  img_y[:, 2], img_predict[:,
                                                                           2],
                                                  img_y[:, 3], img_predict[:,
                                                                           3])
                util.save_image(
                    img,
                    "%s/%s.jpg" % (self.prediction_path, "epoch_%s" % n_epoch +
                                   '_%s' % val_index + '_%s' % dice))

        mean_dice = mean_dice / test_size
        mean_iou = mean_iou / test_size
        logging.info(
            "Validation Loss: {:.4f}, Dice: {:.4f}, IoU: {:.4f}".format(
                loss, mean_dice, mean_iou))
        return mean_dice, mean_iou
    def store_prediction(self, sess, batch_x, batch_y, name):                                                       
        prediction = sess.run(self.net.predicter, feed_dict={self.net.x: batch_x,
                                                             self.net.y: batch_y,
                                                             self.net.keep_prob: 1.})
        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.})

        logging.info("Validation loss={:.4f}".format(loss))

        img = util.combine_img_prediction(batch_x, batch_y, prediction)                                               
        util.save_image(img, "%s/%s.jpg" % (self.prediction_path, name))

        return pred_shape
    def store_prediction(self, sess, batch_x, batch_y, name):
        prediction = sess.run(self.net.predicter,
                              feed_dict={
                                  self.net.x: batch_x,
                                  self.net.y: batch_y,
                                  self.net.keep_prob: 1.
                              })
        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.
                        })

        #logging.info("Verification error= {:.2f}%, loss= {:.6f}".format(error_rate(prediction, batch_y), loss))

        img = util.combine_img_prediction(batch_x, batch_y, prediction)
        util.save_image(img, "%s/%s.jpg" % (self.prediction_path, name))

        return pred_shape
Exemple #6
0
    def test(self, model_path, data_provider, test_size):
        mean_dice = 0
        mean_dice1 = 0
        mean_dice2 = 0
        mean_dice3 = 0
        mean_iou = 0
        mean_iou1 = 0
        mean_iou2 = 0
        mean_iou3 = 0
        self.net.is_training = False
        test_init = data_provider.build_get_data()

        saver = tf.train.Saver()
        with tf.Session() as sess:
            sess.run(test_init)
            x_provider = data_provider.images_test
            y_provider = data_provider.gts_test
            saver.restore(sess, tf.train.latest_checkpoint(model_path))
            for test_index in range(test_size):
                test_x, test_y = sess.run([x_provider, y_provider])
                prediction, loss = sess.run(
                    [self.net.predicter, self.net.loss],
                    feed_dict={
                        self.net.x: test_x,
                        self.net.y: test_y,
                        self.net.keep_prob: 1.,
                    })
                img_predict = prediction.reshape((256, 256, 4))
                img_predict = self.remove_minor_cc(img_predict, 0.3, 4)
                img_y = test_y.reshape((65536, 4))
                img_predict = img_predict.reshape((65536, 4))
                dice, iou = sess.run([self.net.dice, self.net.iou],
                                     feed_dict={
                                         self.net.img_pred: img_predict,
                                         self.net.img_y: img_y
                                     })
                dice1 = dice[0]
                dice2 = dice[1]
                dice3 = dice[2]
                dice = (dice1 + dice2 + dice3) / 3
                iou1 = iou[0]
                iou2 = iou[1]
                iou3 = iou[2]
                iou = (iou1 + iou2 + iou3) / 3
                mean_dice += dice
                mean_dice1 += dice1
                mean_dice2 += dice2
                mean_dice3 += dice3
                mean_iou += iou
                mean_iou1 += iou1
                mean_iou2 += iou2
                mean_iou3 += iou3
                img = util.combine_img_prediction(test_x, img_y[:, 1],
                                                  img_predict[:, 1],
                                                  img_y[:, 2], img_predict[:,
                                                                           2],
                                                  img_y[:, 3], img_predict[:,
                                                                           3])
                util.save_image(
                    img, "%s/%s.jpg" % (self.prediction_path,
                                        "test_%s" % test_index + '_%s' % dice))
            mean_dice = mean_dice / test_size
            mean_iou = mean_iou / test_size
            mean_dice1 = mean_dice1 / test_size
            mean_dice2 = mean_dice2 / test_size
            mean_dice3 = mean_dice3 / test_size
            mean_iou1 = mean_iou1 / test_size
            mean_iou2 = mean_iou2 / test_size
            mean_iou3 = mean_iou3 / test_size
            logging.info("Test Loss: {:.4f}, Dice: {:.4f}, IoU: {:.4f}".format(
                loss, mean_dice, mean_iou))
            logging.info(
                "Dice1: {:.4f}, Dice2: {:.4f}, Dice3: {:.4f}, IoU1: {:.4f}, IoU2: {:.4f}, IoU3: {:.4f}"
                .format(mean_dice1, mean_dice2, mean_dice3, mean_iou1,
                        mean_iou2, mean_iou3))
            return mean_dice, mean_iou