Exemplo n.º 1
0
def generate_images(path,
                    new_foldername="images",
                    post_processing=False,
                    results_fname="test_results.hdf5"):
    """ Vygeneruje obrazky pro porovnani """

    images_path = path + "/" + new_foldername
    fm.make_folder(images_path)

    file = h5py.File(path + "/" + results_fname, 'r')

    test_data = file["test_data"]
    test_labels = file["test_labels"]
    test_predictions = file["test_predictions"]

    #    dataname = fm.load_json(path+"/notebook_config.json")["experiment_name"]
    #    file2 = h5py.File("datasets/processed/"+dataname+".hdf5", 'r')
    #    test_data = file2["test_data"]

    for index in range(test_data.shape[0]):
        if index % 100 == 0:
            print("Generuji se obrazky:", index, "/", test_data.shape[0])

        orig = test_data[index][:, :, 0].astype("uint8")
        label = test_labels[index].astype("uint8") * 255
        result = test_predictions[index].astype("float")
        lesion = np.argmax(result, axis=2) * 127

        if post_processing:
            post, _ = CNN_evaluator.apply_morphology_operations(lesion, label)

            post[lesion != 0] += 1
            blank = np.zeros(label.shape, dtype="uint8")
            blank[post[:] == 0] = [255, 0, 0]
            blank[post[:] == 1] = [0, 0, 255]
            blank[post[:] == 2] = [0, 255, 0]

            show_results(
                label,
                orig,
                blank,
                result,
                lesion_label=u"Výstup CNN",
                result_label=u"Výstup CNN po morfologických operacích",
                path=images_path,
                index=index)

        else:
            show_results(label,
                         orig,
                         result,
                         lesion,
                         path=images_path,
                         index=index)
        #break

    file.close()
Exemplo n.º 2
0
loss = args.loss
LR_change = args.LR_change
batch_size = args.batch_size

special_label = optimizer_label + "_SegNetSkip_Morph"
special_label = special_label + "_LR" + str(abs(int(np.log10(LR)))) + LR_change
special_label = special_label + "_" + str(epochs) + "epochs"
special_label = special_label + "_" + str(batch_size) + "bs"
""" Nacteni dat """

#experiment_name = "no_aug_structured_data-liver_only"
experiment_name = "aug_structured_data-liver_only"
#experiment_name = "aug-ge+int_structured_data-liver_only"

experiment_foldername = "experiments/" + experiment_name
fm.make_folder(experiment_foldername)

hdf_filename = "datasets/processed/" + experiment_name + ".hdf5"
hdf_file = h5py.File(hdf_filename, 'r')
train_data = hdf_file['train_data'][:]
train_labels = hdf_file["train_labels"][:]
val_data = hdf_file['val_data'][:]
val_labels = hdf_file["val_labels"][:]
""" Architektura """
h, w, d = train_data.shape[1:]

inputs = Input(shape=(h, w, d))

# downsampling
xc1 = Conv2D(64, (3, 3), padding='same', activation='relu',
             strides=(1, 1))(inputs)
Exemplo n.º 3
0
            if addr.startswith(name):
                if name in train_names:
                    train_addrs.append(addr)
                elif name in val_names:
                    val_addrs.append(addr)
                elif name in test_names:
                    test_addrs.append(addr)
                    
    print(len(train_addrs), len(val_addrs), len(test_addrs))
        
    return train_addrs, val_addrs, test_addrs
    

""" Definice cest """

fm.make_folder("datasets/processed/")

hdf_path = "datasets/processed/aug_structured_data-liver_only.hdf5"
data_path = 'CTs/kerasdata/Slices/*.png'
masks_path = 'CTs/kerasdata/Masks/*.png'

data_addrs = glob.glob(data_path)
masks_addrs = glob.glob(masks_path)

# jde to vzit i bez augmentace
data_addrs = [a for a in data_addrs]# if "rot=0_shear=0" in a]
masks_addrs = [a for a in masks_addrs]# if "rot=0_shear=0" in a]

print(len(data_addrs), len(masks_addrs))

@author: Mirab
"""

import glob
import os
import re
from shutil import copyfile

import file_manager_metacentrum as fm

foldername = "experiments/aug_structured_data-liver_only/*"
folders = glob.glob(foldername)

for folder in folders:

    name = re.sub(r".+\\+", "", folder)
    if "." in name:
        continue
    new_name = "experiments_results_copy/"
    fm.make_folder(new_name + name + "/logs")

    files = os.listdir(folder)
    for f in files:
        if f.endswith(".json"):
            copyfile(folder + "/" + f, new_name + name + "/" + f)
        if f.endswith("logs"):
            logfiles = os.listdir(folder + "/" + f)
            for lf in logfiles:
                if not (lf.endswith(".hdf5") or lf.endswith(".h5")):
                    copyfile(folder + "/" + f + "/" + lf,
                             new_name + name + "/" + f + "/" + lf)