Ejemplo n.º 1
0
preds = []
gt = []
for id in ids:
    test_ids = {id}
    train_ids = set([x.split("/")[-1][:5] for x in files]) - test_ids

    train_val, test = [x for x in files if x.split("/")[-1][:5] in train_ids],\
                      [x for x in files if x.split("/")[-1][:5] in test_ids]

    train, val = train_test_split(train_val, test_size=0.1, random_state=1337)

    train_dict = {k: np.load(k) for k in train}
    test_dict = {k: np.load(k) for k in test}
    val_dict = {k: np.load(k) for k in val}

    model = get_model_cnn_crf(lr=0.0001)

    file_path = "cnn_crf_model_20_folds.h5"
    # model.load_weights(file_path)

    checkpoint = ModelCheckpoint(file_path,
                                 monitor='val_acc',
                                 verbose=1,
                                 save_best_only=True,
                                 mode='max')
    early = EarlyStopping(monitor="val_acc",
                          mode="max",
                          patience=20,
                          verbose=1)
    redonplat = ReduceLROnPlateau(monitor="val_acc",
                                  mode="max",
Ejemplo n.º 2
0
files = sorted(glob(os.path.join(base_path, "*.npz")))

ids = sorted(list(set([x.split("/")[-1][:5] for x in files])))
#split by test subject
train_ids, test_ids = train_test_split(ids, test_size=0.15, random_state=1338)

train_val, test = [x for x in files if x.split("/")[-1][:5] in train_ids],\
                  [x for x in files if x.split("/")[-1][:5] in test_ids]

train, val = train_test_split(train_val, test_size=0.1, random_state=1337)

train_dict = {k: np.load(k) for k in train}
test_dict = {k: np.load(k) for k in test}
val_dict = {k: np.load(k) for k in val}

model = get_model_cnn_crf()

file_path = "cnn_crf_model.h5"
# model.load_weights(file_path)

checkpoint = ModelCheckpoint(file_path,
                             monitor='val_acc',
                             verbose=1,
                             save_best_only=True,
                             mode='max')
early = EarlyStopping(monitor="val_acc", mode="max", patience=20, verbose=1)
redonplat = ReduceLROnPlateau(monitor="val_acc",
                              mode="max",
                              patience=5,
                              verbose=2)
callbacks_list = [checkpoint, early, redonplat]  # early