from utilsTrain import generator
from modelLib import dice_coef
import h5py
import numpy as np

batchSize = 1

h5path = "..\\out\\train_true_256.h5"
h5file = h5py.File(h5path, "r")

n = h5file["image"].shape[0]
a = np.arange(n)

train_index, test_index = train_test_split(a, test_size=0.2, random_state=42)

trainGen = generator(h5file, train_index, batchSize)
testGen = generator(h5file, test_index, batchSize)

model = basic_unet()

bestModelPath = '..\\out\\weights\\UNET_01-loss--1.375.hdf5'

model.load_weights(bestModelPath)

v = next(trainGen)

x = v[0]
y_true = v[1]
y_pred = model.predict(x)

y_true = y_true.flatten()
nTotal = db["RNASeq"].shape[0]
nFeat = db["RNASeq"].shape[1]

n_classes = 33

X = np.arange(nTotal)
y = db["label"][...]

skf = StratifiedKFold(n_splits=5)
skf.get_n_splits(X, y)

kdx = 0
for train_index, test_index in skf.split(X, y):
    kdx += 1
    train_generator = generator(db, train_index, batch_size=32)
    test_generator = generator(db, test_index, batch_size=32)

    model = makeModel(modelName)
    model.compile(loss='categorical_crossentropy',
                  optimizer='adam',
                  metrics=['accuracy'])

    print("\nCross Validation Fold : %02d \n" % kdx)

    check1 = ModelCheckpoint(os.path.join(
        weightsFolder, modelName + "_fold_%02d" % kdx +
        "_{epoch:02d}-loss-{val_loss:.3f}.hdf5"),
                             monitor='val_loss',
                             save_best_only=True,
                             mode='auto')
Exemple #3
0
nTotal = db["RNASeq"].shape[0]
nFeat = db["RNASeq"].shape[1]

n_classes = 33

X = np.arange(nTotal)
y = db["label"][...]

X_train, X_test, y_train, y_test = train_test_split(X,
                                                    y,
                                                    stratify=y,
                                                    test_size=0.25,
                                                    random_state=42)

train_generator = generator(db, X_train, batch_size=32)
test_generator = generator(db, X_test, batch_size=32)

model = makeModel(modelName)

model.compile(loss='categorical_crossentropy',
              optimizer='adam',
              metrics=['accuracy'])

check1 = ModelCheckpoint(os.path.join(
    weightsFolder, modelName + "_{epoch:02d}-loss-{val_loss:.3f}.hdf5"),
                         monitor='val_loss',
                         save_best_only=True,
                         mode='auto')
check2 = ModelCheckpoint(bestModelPath,
                         monitor='val_loss',