from tf_SDUnet import unet, util, image_util, metrics 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")
import matplotlib.pyplot as plt import numpy as np plt.rcParams['image.cmap'] = 'gist_earth' np.random.seed(98765) from tf_SDUnet import image_gen from tf_SDUnet import unet nx = 572 ny = 572 generator = image_gen.GrayScaleDataProvider(nx, ny, cnt=20) x_test, y_test = generator(1) fig, ax = plt.subplots(1, 2, sharey=True, figsize=(8, 4)) ax[0].imshow(x_test[0, ..., 0], aspect="auto") ax[1].imshow(y_test[0, ..., 1], aspect="auto") net = unet.Unet(channels=generator.channels, n_class=generator.n_class, layers=3, features_root=16) trainer = unet.Trainer(net, optimizer="momentum", opt_kwargs=dict(momentum=0.2)) path = trainer.train(generator, "./unet_trained", training_iters=32, epochs=10, display_step=2) x_test, y_test = generator(1) prediction = net.predict("./unet_trained/model.ckpt", x_test) fig, ax = plt.subplots(1, 3, sharex=True, sharey=True, figsize=(12, 5)) ax[0].imshow(x_test[0, ..., 0], aspect="auto") ax[1].imshow(y_test[0, ..., 1], aspect="auto")
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")
n_class=2) ST = image_util.ImageDataProvider("test2/ST/*.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) #data_provider = image_util.ImageDataProvider("Kumar_aug/aug/*.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 = "model_f8_0.88_dice_100" #setup & training net = unet.Unet(layers=4, features_root=8, channels=3, n_class=2, cost="dice_coefficient") trainer = unet.Trainer(net, batch_size=4, verification_batch_size=4, optimizer="adam") path = trainer.train(data_provider, output_path, keep_prob=0.88, block_size=7, training_iters=64, epochs=100, display_step=2, restore=False) test_x, test_y = DT(6)