Notebook
import numpy as np import pandas as pd from subprocess import check_output print(check_output(["ls", "train/"]).decode("utf8")) import matplotlib.pyplot as plt from skimage.io import imread import os from glob import glob %matplotlib inline import tifffile as tiff import cv2 as cv2 from skimage.segmentation import slic, mark_boundaries
history= model.fit_generator(train_generator, steps_per_epoch=int(len(X_train)/batchsize), epochs=10, validation_data=validation_generator, validation_steps=int(len(X_test)/batchsize))
#Save model/ Don't have prediction from keras.models import load_model #model.save('retinopathy_predict.h5') print(X_train.shape) print(X_test[0].shape) y_pred = [] p = 100 for i in range (200): image = X_train[i] imagematrix = np.asarray(image) #img1=imagematrix.reshape(img_rows,img_cols,3) #plt.imshow(img1) #print(imagematrix.shape) imagepredict = np.expand_dims(imagematrix, axis=0) #print(imagepredict.shape) y_pred1 = model.predict(imagepredict) y_pred2 = [x * p for x in y_pred1] y_pred3 = np.max(y_pred2) y_pred.append(y_pred3) print(y_pred3) y_pred = np.asarray(y_pred)
#Balance the distribution in the training set train_df = raw_train_df.groupby(['level', 'eye']).apply(lambda x: x.sample(75, replace = True) ).reset_index(drop = True) print('New Data Size:', train_df.shape[0], 'Old Size:', raw_train_df.shape[0]) train_df[['level', 'eye']].hist(figsize = (10, 5))
retina_model.fit_generator(train_gen, steps_per_epoch = train_df.shape[0]//batch_size, validation_data = valid_gen, validation_steps = valid_df.shape[0]//batch_size, epochs = 25, callbacks = callbacks_list, workers = 0, # tf-generators are not thread-safe use_multiprocessing=False, max_queue_size = 0 )