Beispiel #1
0
    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.,
                                  self.net.block_size: 1
                              })
        pred_shape = prediction.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.keep_prob: 1.,
                            self.net.block_size: 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
Beispiel #2
0
import numpy as np

data_provider = image_util.ImageDataProvider("DRIVE700/test/*",
                                             data_suffix="_test.tif",
                                             mask_suffix='_manual1.png',
                                             n_class=2)

net = unet.Unet(layers=4, features_root=8, channels=3, n_class=2)
test_x, test_y = data_provider(1)

prediction = net.predict("mode/drive100_0.92_700/model.ckpt", test_x)
prediction = util.crop_to_shape(prediction, (20, 584, 565, 2))

AUC_ROC = metrics.roc_Auc(prediction,
                          util.crop_to_shape(test_y, prediction.shape))
print("auc", AUC_ROC)
acc = metrics.acc(prediction, util.crop_to_shape(test_y, prediction.shape))
print("acc:", acc)
precision = metrics.precision(prediction,
                              util.crop_to_shape(test_y, prediction.shape))
print("ppv:", precision)
sen = metrics.sen(prediction, util.crop_to_shape(test_y, prediction.shape))
print("TPR:", sen)
TNR = metrics.TNR(prediction, util.crop_to_shape(test_y, prediction.shape))
print("tnr:", TNR)
f1 = metrics.f1score2(prediction, util.crop_to_shape(test_y, prediction.shape))
print("f1:", f1)

img = util.combine_img_prediction(test_x, test_y, prediction)
util.save_image(img, "19.jpg")
Beispiel #3
0
import os

data_provider2 = image_util.ImageDataProvider("TNBC/test/*.png",
                                              data_suffix=".png",
                                              mask_suffix='_mask.png',
                                              n_class=2)
data_provider = image_util.ImageDataProvider("Model_zoo/train_aug/train/*.png",
                                             data_suffix=".png",
                                             mask_suffix='_mask.png',
                                             n_class=2)
output_path = "TNBC2_CKPT"
net = unet.Unet(layers=4, features_root=6, channels=3, n_class=2)
trainer = unet.Trainer(net,
                       batch_size=8,
                       verification_batch_size=4,
                       optimizer="adam")
path = trainer.train(data_provider,
                     output_path,
                     keep_prob=0.8,
                     training_iters=32,
                     epochs=100,
                     display_step=2,
                     restore=True)
test_x, test_y = data_provider2(1)
prediction = net.predict(path, test_x)
error = unet.error_rate(prediction, util.crop_to_shape(test_y,
                                                       prediction.shape))
print(error)
img = util.combine_img_prediction(test_x, test_y, prediction)
util.save_image(img, "tnbc2.jpg")
Beispiel #4
0
import  numpy as np

import os
# data_provider2 = image_util.ImageDataProvider("CHASE_NEW/test/*",data_suffix="R.jpg", mask_suffix='R_1stHO.png', n_class=2)
data_provider2 = image_util.ImageDataProvider("DRIVE700/test/*",data_suffix="_test.tif", mask_suffix='_manual1.png', n_class=2)

#data_provider2 = image_util.ImageDataProvider("DriveTest1/*",data_suffix="_test.tif", mask_suffix='_manual1.gif', n_class=2)
data_provider = image_util.ImageDataProvider("DRIVE700/train/*",data_suffix="_training.tif", mask_suffix='_manual1.png', n_class=2)
output_path="mode/drive100_0.92_700"
net = unet.Unet(layers=4, features_root=8, channels=3, n_class=2)
trainer = unet.Trainer(net,batch_size=4,verification_batch_size=4,optimizer="adam")
path = trainer.train(data_provider, output_path,keep_prob=0.92,training_iters=64, epochs=80,display_step=2,restore=False)
test_x, test_y = data_provider2(20)
prediction = net.predict(path, test_x)
prediction=util.crop_to_shape(prediction, (20,584,565,2))
AUC_ROC = metrics.roc_Auc(prediction, util.crop_to_shape(test_y, prediction.shape))
print("auc:",AUC_ROC)
acc=metrics.acc(prediction,util.crop_to_shape(test_y, prediction.shape))
print("acc:",acc)
precision=metrics.precision(prediction,util.crop_to_shape(test_y, prediction.shape))
print("ppv:",precision)
sen=metrics.sen(prediction,util.crop_to_shape(test_y, prediction.shape))
print("TPR:",sen)
TNR=metrics.TNR(prediction,util.crop_to_shape(test_y, prediction.shape))
print("tnr:",TNR)
f1=metrics.f1score2(prediction,util.crop_to_shape(test_y, prediction.shape))
print("f1:",f1)
img = util.combine_img_prediction(test_x, test_y, prediction)

util.save_image(img, "Drive_deep.jpg")
Beispiel #5
0
from tf_SDUnet import unet, util, image_util

#preparing data loading
data_provider = image_util.ImageDataProvider("dataset2/train/*.jpg",
                                             data_suffix=".jpg",
                                             mask_suffix='_mask.png',
                                             n_class=2)
output_path = "out_put2"
#setup & training
net = unet.Unet(layers=6, features_root=16, channels=3, n_class=2)

trainer = unet.Trainer(net)
path = trainer.train(data_provider, output_path, training_iters=12, epochs=1)
test_x, test_y = data_provider(1)
print(test_x.shape)
prediction = net.predict(path, test_x)
print(prediction)
unet.error_rate(prediction, util.crop_to_shape(test_y, prediction.shape))
img = util.combine_img_prediction(test_x, test_y, prediction)
util.save_image(img, "voc_prediction.jpg")
Beispiel #6
0
from tf_SDUnet import unet, util, image_util
data_provider2 = image_util.ImageDataProvider("TNBC/test/*.png",data_suffix=".png", mask_suffix='_mask.png', n_class=2)
#setup & training
net = unet.Unet(layers=4, features_root=6, channels=3, n_class=2)

test_x, test_y = data_provider2(25)

prediction = net.predict("TNBC2_CKPT/model.ckpt", test_x)

print(test_y)
error=unet.error_rate(prediction, util.crop_to_shape(test_y, prediction.shape))
print("test error:",error)
img = util.combine_img_prediction(test_x, test_y, prediction)
util.save_image(img, "TNBC_test13.jpg")
Beispiel #7
0
                                              mask_suffix='_binary.tif',
                                              n_class=2)
#data_provider = image_util.ImageDataProvider("Tissue_images/*.tif",data_suffix=".tif", mask_suffix='_binary.tif', n_class=2)
data_provider = image_util.ImageDataProvider("tissue_aug/train/*.tif",
                                             data_suffix=".tif",
                                             mask_suffix='_binary.tif',
                                             n_class=2)
output_path = "out_put_skip_aug3_160"
#setup & training
net = unet2.Unet(layers=4, features_root=8, channels=3, n_class=2)
trainer = unet2.Trainer(net,
                        batch_size=4,
                        verification_batch_size=4,
                        optimizer="adam")
path = trainer.train(data_provider,
                     output_path,
                     keep_prob=0.8,
                     training_iters=124,
                     epochs=1,
                     display_step=2,
                     restore=True)
test_x, test_y = data_provider2(14)
prediction = net.predict(path, test_x)

print(test_y)
error = unet2.error_rate(prediction,
                         util.crop_to_shape(test_y, prediction.shape))
print("test error:", error)
img = util.combine_img_prediction(test_x, test_y, prediction)
util.save_image(img, "test_aug_5.jpg")
Beispiel #8
0
                       optimizer="adam")
path = trainer.train(data_provider,
                     output_path,
                     keep_prob=0.92,
                     training_iters=48,
                     epochs=100,
                     display_step=2,
                     restore=False)
test_x, test_y = data_provider2(14)
prediction = net.predict(path, test_x)
#[batches, nx, ny, channels].
prediction = util.crop_to_shape(prediction, (14, 960, 999, 2))

AUC_ROC = metrics.roc_Auc(prediction,
                          util.crop_to_shape(test_y, prediction.shape))
print("auc", AUC_ROC)
acc = metrics.acc(prediction, util.crop_to_shape(test_y, prediction.shape))
print("acc:", acc)
precision = metrics.precision(prediction,
                              util.crop_to_shape(test_y, prediction.shape))
print("ppv:", precision)
sen = metrics.sen(prediction, util.crop_to_shape(test_y, prediction.shape))
print("TPR:", sen)
TNR = metrics.TNR(prediction, util.crop_to_shape(test_y, prediction.shape))
print("tnr:", TNR)
f1 = metrics.f1score2(prediction, util.crop_to_shape(test_y, prediction.shape))
print("f1:", f1)
img = util.combine_img_prediction(test_x, test_y, prediction)

util.save_image(img, "Chase.jpg")
Beispiel #9
0
                                              n_class=2)

net = unet.Unet(layers=4, features_root=8, channels=3, n_class=2)
test_x, test_y = data_provider2(1)
prediction = net.predict("mode/CHASE100_0.93_1100/model.ckpt", test_x)
print(prediction.shape)
prediction = util.crop_to_shape(prediction, (14, 960, 999, 2))

AUC_ROC = metrics.roc_Auc(prediction,
                          util.crop_to_shape(test_y, prediction.shape))
print("auc", AUC_ROC)
acc = metrics.acc(prediction, util.crop_to_shape(test_y, prediction.shape))
print("acc:", acc)
precision = metrics.precision(prediction,
                              util.crop_to_shape(test_y, prediction.shape))
print("ppv:", precision)
sen = metrics.sen(prediction, util.crop_to_shape(test_y, prediction.shape))
print("TPR:", sen)
TNR = metrics.TNR(prediction, util.crop_to_shape(test_y, prediction.shape))
print("tnr:", TNR)
f1 = metrics.f1score2(prediction, util.crop_to_shape(test_y, prediction.shape))
print("f1:", f1)

#
#     print(prediction_tensor)
#     print(label_tensor)
#     print("AUC:" + str(value))

img = util.combine_img_prediction(test_x, test_y, prediction)
util.save_image(img, "01R.jpg")
Beispiel #10
0
                        prediction))
print(
    "aji+:",
    stats_utils.get_fast_aji(util.crop_to_shape(test_y, prediction.shape),
                             prediction))
# DQ,SQ=stats_utils.get_fast_panoptic_quality(util.crop_to_shape(test_y, prediction.shape),prediction)
# print("DQ:",DQ)
# print("SQ:",SQ)
# print("PQ:",DQ*SQ)
error = unet.error_rate(prediction, util.crop_to_shape(test_y,
                                                       prediction.shape))
print("DT error:", error)
# f1=unet.f1score2(prediction, util.crop_to_shape(test_y, prediction.shape))
# print("DTf1:",f1)
img = util.combine_img_prediction(test_x, test_y, prediction)
util.save_image(img, "DTtest.jpg")

test_x, test_y = ST(8)
prediction = net.predict(model, test_x)

# #
print(
    "dice:",
    stats_utils.get_dice_2(util.crop_to_shape(test_y, prediction.shape),
                           prediction))
print(
    "aji:",
    stats_utils.get_aji(util.crop_to_shape(test_y, prediction.shape),
                        prediction))
print(
    "aji+:",
Beispiel #11
0
from tf_SDUnet import unet, util, image_util,stats_utils,layers
import tensorflow as tf
import numpy as np
Single = image_util.ImageDataProvider("test2/single/*.tif",data_suffix=".tif", mask_suffix='_binary.tif', n_class=2,shuffle_data=False)
net = unet.Unet(layers=4, features_root=8, channels=3, n_class=2)
test_x, test_y =Single(1)
model="model/model_f8_0.88_flip_160/model.ckpt"
prediction = net.predict(model, test_x)
print("dice2:",stats_utils.get_dice_2(util.crop_to_shape(test_y, prediction.shape),prediction))
print("dice1",stats_utils.get_dice_1(util.crop_to_shape(test_y, prediction.shape),prediction))
print("f1:",unet.f1score2(prediction, util.crop_to_shape(test_y, prediction.shape)))
print("aji:",stats_utils.get_aji(util.crop_to_shape(test_y, prediction.shape),prediction))
print("aji+:",stats_utils.get_fast_aji(util.crop_to_shape(test_y, prediction.shape),prediction))

error=unet.error_rate(prediction, util.crop_to_shape(test_y, prediction.shape))
print("error:",error)
img = util.combine_img_prediction(test_x, test_y, prediction)
util.save_image(img, "result/5698.jpg")
Beispiel #12
0
print(prediction.shape)
prediction=util.crop_to_shape(prediction, (10,605,700,2))
print(prediction.shape)
print(prediction)


AUC_ROC = metrics.roc_Auc(prediction, util.crop_to_shape(test_y, prediction.shape))
print("auc",AUC_ROC)
acc=metrics.acc(prediction,util.crop_to_shape(test_y, prediction.shape))
print("acc:",acc)
precision=metrics.precision(prediction,util.crop_to_shape(test_y, prediction.shape))
print("ppv:",precision)
sen=metrics.sen(prediction,util.crop_to_shape(test_y, prediction.shape))
print("TPR:",sen)
TNR=metrics.TNR(prediction,util.crop_to_shape(test_y, prediction.shape))
print("tnr:",TNR)
f1=metrics.f1score2(prediction,util.crop_to_shape(test_y, prediction.shape))
print("f1:",f1)



#
#     print(prediction_tensor)
#     print(label_tensor)
#     print("AUC:" + str(value))


img = util.combine_img_prediction(test_x, test_y, prediction)
util.save_image(img, "0236.jpg")
Beispiel #13
0
data_provider2 = image_util.ImageDataProvider("test/*.tif",
                                              data_suffix=".tif",
                                              mask_suffix='_binary.tif',
                                              n_class=2)
data_provider = image_util.ImageDataProvider("Tissue_images/*.tif",
                                             data_suffix=".tif",
                                             mask_suffix='_binary.tif',
                                             n_class=2)
output_path = "FCN_put"
#setup & training
net = FCN.fcn(channels=3, n_class=2)
trainer = FCN.Trainer(net,
                      batch_size=4,
                      verification_batch_size=4,
                      optimizer="adam")
path = trainer.train(data_provider,
                     output_path,
                     dropout=0.9,
                     training_iters=32,
                     epochs=20,
                     display_step=2)
test_x, test_y = data_provider2(1)
prediction = net.predict(path, test_x)
print(prediction)
print(test_y)
error = FCN.error_rate(prediction, test_y)
print("test error:", error)
img = util.combine_img_predictionFCN(test_x, test_y, prediction)
util.save_image(img, "FCN.jpg")
Beispiel #14
0
data_provider2 = image_util.ImageDataProvider("test/ST/*.tif",
                                              data_suffix=".tif",
                                              mask_suffix='_binary.tif',
                                              n_class=2,
                                              shuffle_data=False)

#setup & training
net = unet.Unet(layers=4, features_root=8, channels=3, n_class=2)

test_x, test_y = data_provider2(14)

prediction = net.predict("model_aug_f8_0.75_100/model.ckpt", test_x)

print(test_y)
error = unet.error_rate(prediction, util.crop_to_shape(test_y,
                                                       prediction.shape))
print("test error:", error)
f1 = unet.f1score2(prediction, util.crop_to_shape(test_y, prediction.shape))
# print(f1)
# y_pred = np.argmax(prediction, axis=3)[0]
# y_true = np.argmax(util.crop_to_shape(test_y, prediction.shape), axis=3)[0]
# precision=F1test.precision(y_true,y_pred)
#
# f1=F1test.f1score(y_true,y_pred)

print("f1", f1)

img = util.combine_img_prediction(test_x, test_y, prediction)
util.save_image(img, "test.jpg")
Beispiel #15
0
                       verification_batch_size=4,
                       optimizer="adam")
path = trainer.train(data_provider,
                     output_path,
                     keep_prob=0.93,
                     training_iters=40,
                     epochs=100,
                     display_step=2,
                     restore=False)
test_x, test_y = data_provider2(10)

prediction = net.predict(path, test_x)
prediction = util.crop_to_shape(prediction, (10, 605, 700, 2))
AUC_ROC = metrics.roc_Auc(prediction,
                          util.crop_to_shape(test_y, prediction.shape))
print("auc:", AUC_ROC)
acc = metrics.acc(prediction, util.crop_to_shape(test_y, prediction.shape))
print("acc:", acc)
precision = metrics.precision(prediction,
                              util.crop_to_shape(test_y, prediction.shape))
print("ppv:", precision)
sen = metrics.sen(prediction, util.crop_to_shape(test_y, prediction.shape))
print("TPR:", sen)
TNR = metrics.TNR(prediction, util.crop_to_shape(test_y, prediction.shape))
print("tnr:", TNR)
f1 = metrics.f1score2(prediction, util.crop_to_shape(test_y, prediction.shape))
print("f1:", f1)
img = util.combine_img_prediction(test_x, test_y, prediction)

util.save_image(img, "STARE.jpg")