import tensorflow as tf
import keras
from keras.backend.tensorflow_backend import set_session
from keras.optimizers import Adam, Adagrad
from keras.callbacks import ModelCheckpoint, Callback, History
from dl_utils.dl_networks.resnet import ResnetBuilder
from dl_utils.tb_callback import TensorBoard
K.set_image_dim_ordering('th')

##############################
#
# Config data
#
##############################

cases = dataset_loaders.get_casenames(test=True)

image_size_nn = 45
N_valid_cases = 50

wind = 100
big_patch_size = 100

experiment_folder_name = 'final_classificator'
experiment_name = 'final_classificator'  # This one will only be used for the logs
INPUT_MODEL = '%s/%s/models/final_classificator_model_2.hdf5' % (
    settings.DATAMODEL_PATH, experiment_folder_name)

existing_labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'FP']

##############################
                           scan_step,
                           batch_size,
                           square_to_scan=None)
    preds = []
    for x in patches:
        preds.append(model.predict(x))
    preds = np.vstack(preds)
    preds = preds.reshape([
        int(np.sqrt(preds.shape[0])),
        int(np.sqrt(preds.shape[0])), preds.shape[1]
    ])
    return preds, time.time() - t1


for test in [False, True]:
    for casename in dataset_loaders.get_casenames(test=test):
        if casename == 'emtpy':
            continue
        try:
            filename_to_save = annotations_name.format(path=ANNOTATIONS_PATH,
                                                       scan_window=scan_step,
                                                       casename=casename)
            if not os.path.isfile(filename_to_save):
                preds, takentime = predict_case(casename)
                print(
                    "- Calculated case %s with window step %d in %0.0f seconds"
                    % (casename, scan_step, takentime))
                np.savez_compressed(filename_to_save, preds=preds)
            else:
                print("- [ALREADY DONE] %s" % filename_to_save)
        except:
Beispiel #3
0
def predict_case(case):
    t1 = time.time()
    patches = scan_patches(case,
                           image_size_nn,
                           patch_size,
                           scan_step,
                           batch_size,
                           square_to_scan=None)
    preds = []
    for x in patches:
        preds.append(model.predict(x))
    preds = np.vstack(preds)
    preds = preds.reshape([
        int(np.sqrt(preds.shape[0])),
        int(np.sqrt(preds.shape[0])), preds.shape[1]
    ])
    return preds, time.time() - t1


for casename in dataset_loaders.get_casenames():
    filename_to_save = annotations_name.format(path=ANNOTATIONS_PATH,
                                               scan_window=scan_step,
                                               casename=casename)
    if not os.path.isfile(filename_to_save):
        preds, takentime = predict_case(casename)
        print("- Calculated case %s with window step %d in %0.0f seconds" %
              (casename, scan_step, takentime))
        np.savez_compressed(filename_to_save, preds=preds)
    else:
        print("- [ALREADY DONE] %s" % filename_to_save)