Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
neeyanthkvk committed Jun 27, 2019
1 parent 31299b1 commit 89a69ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
36 changes: 21 additions & 15 deletions cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand All @@ -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)
Expand All @@ -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"))
2 changes: 1 addition & 1 deletion finish_CNN.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)):
Expand Down

0 comments on commit 89a69ac

Please sign in to comment.