diff --git a/cnn.py b/cnn.py index 68b0402..c189043 100644 --- a/cnn.py +++ b/cnn.py @@ -27,16 +27,18 @@ classifier = Sequential() classifier.add(Conv2D(64, (5, 5), input_shape = (256, 256, 1), activation = 'relu')) -classifier.add(Dropout(0.25)) +classifier.add(Dropout(0.2)) classifier.add(MaxPooling2D(pool_size = (4, 4))) classifier.add(Conv2D(32, (3, 3), activation = 'relu')) -classifier.add(Dropout(0.25)) +classifier.add(Dropout(0.2)) classifier.add(MaxPooling2D(pool_size = (4, 4))) + + classifier.add(Flatten()) classifier.add(Dense(units = 128, activation = 'relu')) -classifier.add(Dropout(0.5)) +classifier.add(Dropout(0.3)) classifier.add(Dense(units = 32, activation = 'relu')) classifier.add(Dense(units = 1, activation = 'sigmoid')) @@ -47,17 +49,21 @@ dir = "Data/Processed0" for filename in os.listdir(dir): - img = np.load(os.path.join(dir, filename)) - im_rez = skimage.transform.resize(img, (256, 256, 1)) - X.append(im_rez) - y.append(0) + img = np.load(os.path.join(dir, filename))[:,:,0] + smooth_img = skimage.filters.gaussian(img, 8) + sobel_img = skimage.filters.sobel(img) + im_rez = skimage.transform.resize(sobel_img, (256, 256, 1)) + X.append(im_rez) + y.append(0) dir = "Data/Processed1" for filename in os.listdir(dir): - img = np.load(os.path.join(dir, filename)) - im_rez = skimage.transform.resize(img, (256, 256, 1)) - X.append(im_rez) - y.append(1) + img = np.load(os.path.join(dir, filename))[:,:,0] + smooth_img = skimage.filters.gaussian(img, 8) + sobel_img = skimage.filters.sobel(img) + im_rez = skimage.transform.resize(sobel_img, (256, 256, 1)) + X.append(im_rez) + y.append(1) X = np.array(X) y = np.array(y) @@ -66,14 +72,14 @@ print(type(Xtr)) classifier.summary() -es = EarlyStopping(patience=10, restore_best_weights = True) +es = EarlyStopping(patience=20, restore_best_weights = True) history = classifier.fit(Xtr, ytr, callbacks = [es], - epochs = 100, + epochs = 40, batch_size = 8, validation_data = (Xts, yts)) classifier.evaluate(Xts, yts) -classifier.save("model_even_better.h5") +classifier.save("Models/Keras/Test2/model2.h5") import pickle as pickle -pickle.dump(history, open("history_even_better.pkl", "rb")) +pickle.dump(history, open("Models/Keras/Test2/history2.pkl", "wb")) diff --git a/finish_CNN.py b/finish_CNN.py index 9bfb2f7..054b3c4 100644 --- a/finish_CNN.py +++ b/finish_CNN.py @@ -8,7 +8,7 @@ import pydicom as pd import skimage os.environ["CUDA_VISIBLE_DEVICES"] = "4" -model = load_model("Models/Keras/model_even_better.h5") +model = load_model("Models/Keras/model_better.h5") for fn in glob.iglob(os.path.join("/data3/wv2019/data/processed/", "*", "*", "*"), recursive=True): if(os.path.isdir(fn)):