Example #1
0
from sklearn.cross_validation import train_test_split
from keras.models import model_from_json
import cPickle as pickle

batch_size = 32
nb_classes = 3 
nb_epoch = 10
data_augmentation = True

# input image dimensions
img_rows, img_cols = 100,100
# the mitosis images are RGB
img_channels = 1

# the data, shuffled and split between train and test sets
image_list = create_image_list('/data/50_50_100_40', sample_size=[-1,-1,-1,-1,-1], use_mr=True)
with open('image_list.pkl', 'w+') as f:
    pickle.dump(image_list, f)

# Create testset data for cross-val
num_images = len(image_list)
test_size = int(0.1 * num_images)
print("Train size: ", num_images-test_size)
print("Test size: ", test_size)


model = Sequential()

model.add(Convolution2D(256, 3, 3, border_mode='same',
                        input_shape=(img_channels, img_rows, img_cols)))
model.add(Activation('relu'))
Example #2
0
from sklearn.cross_validation import train_test_split
from keras.models import model_from_json
import cPickle as pickle

batch_size = 32
nb_classes = 2 
nb_epoch = 10
data_augmentation = True

# input image dimensions
img_rows, img_cols = 100,100
# the mitosis images are RGB
img_channels = 3

# the data, shuffled and split between train and test sets
image_list = create_image_list('/data/50_50_100_40', sample_size=[-1,-1,0,-1,-1], use_mr=True)

with open('image_list.pkl', 'w+') as f:
    pickle.dump(image_list, f)

# Create testset data for cross-val
num_images = len(image_list)
test_size = int(0.1 * num_images)
print("Train size: ", num_images-test_size)
print("Test size: ", test_size)
print("Training Distribution: ", get_counts(image_list[0:-test_size], nb_classes))

model = Sequential()

model.add(Convolution2D(256, 6, 6, border_mode='same',
                        input_shape=(img_channels, img_rows, img_cols)))
Example #3
0
    precision = precision_score(y_true, y_predicted, labels=labels, average=method)
    recall = recall_score(y_true, y_predicted, labels=labels, average=method)
    accuracy = accuracy_score(y_true, y_predicted)
    print "Precision Score {}".format(precision)
    print "Recall Score {}".format(recall)
    y_0 = y_predicted[y_true==0]
    y_1 = y_predicted[y_true==1]
    y_2 = y_predicted[y_true==2]
    print "Non-mitosis: True = {}, Predicted = {}".format((y_true==0).sum(), (y_0==0).sum())
    print "Mitosis: True = {}, Predicted = {}".format((y_true==1).sum(), (y_1==1).sum())
    print "Background: True = {}, Predicted = {}".format((y_true==2).sum(), (y_2==2).sum())
    print confusion_matrix(y_true, y_predicted)

if __name__ == '__main__':
    print "Unpacking the model"
    model = unpack_model('../runs/gpu0/cnn1_model_architecture.json', '../runs/gpu0/cnn1_model_weights.h5')
    print "Unpickling the image list"
    with open ('../runs/gpu1/image_list.pkl') as f:
        image_list_train = pickle.load(f)
    print "Creating test image list"
    image_list_test = create_image_list(path='/data/Test/ScannerA', sample_size=[-1,-1,0,0,0], use_mr=False)
    print "Calculating distribution of train"
    image_names, count_0, count_1, count_2 = get_names_count(image_list_train)
    print "Creating X, y for test {}".format(len(image_list_test))
    X, y = get_input(image_list_test)
    print "Predicting on test"
    y_prob = predict_prob(model, X, y)
    y_predicted = np.argmax(y_prob, axis=1)
    #y_predicted = thresholding(y_prob, count_0*1./y.size, count_1*1./y.size, count_2*1./y.size)
    get_metrics(y, y_predicted, [0,1], "binary")
Example #4
0
def get_test(path):
    image_list = create_image_list(path=path, use_mr=False)
    X, y = get_input(image_list)
    return X, y
def get_test(path):
    image_list = create_image_list(path=path, use_mr=False)
    X, y = get_input(image_list)
    return X, y
    return model, model.get_weights()


batch_size = 32
nb_classes = 3
nb_epoch = 10
data_augmentation = True

# input image dimensions
img_rows, img_cols = 100, 100
# the mitosis images are RGB
img_channels = 3

# the data, shuffled and split between train and test sets
image_list = create_image_list('/data/50_50_100_40',
                               sample_size=[-1, -1, -1, -1, -1],
                               use_mr=True)
image_names, clusters = get_image_clusters(
    '/home/ubuntu/capstone/code/clustering/image_names.pkl',
    '/home/ubuntu/capstone/code/clustering/clusters.pkl')

with open('image_list.pkl', 'w+') as f:
    pickle.dump(image_list, f)

# define two groups of layers: feature (convolutions) and classification (dense)
feature_layers = [
    Convolution2D(32,
                  3,
                  3,
                  border_mode='same',
                  input_shape=(img_channels, img_rows, img_cols)),
    y_1 = y_predicted[y_true == 1]
    y_2 = y_predicted[y_true == 2]
    print "Background: True = {}, Predicted = {}".format((y_true == 0).sum(),
                                                         (y_0 == 0).sum())
    print "Non_Mitosis: True = {}, Predicted = {}".format((y_true == 1).sum(),
                                                          (y_1 == 1).sum())
    print "Mitosis: True = {}, Predicted = {}".format((y_true == 2).sum(),
                                                      (y_2 == 2).sum())
    print confusion_matrix(y_true, y_predicted)


if __name__ == '__main__':
    print "Unpacking the model"
    model = unpack_model('../runs/gpu1/ccn1_model_architecture.json',
                         '../runs/gpu1/ccn1_model_weights.h5')
    print "Unpickling the image list"
    with open('../runs/gpu1/image_list.pkl') as f:
        image_list_train = pickle.load(f)
    print "Creating test image list"
    image_list_test = create_image_list(path='/data/Test/ScannerA',
                                        use_mr=False)
    print "Calculating distribution of train"
    image_names, count_0, count_1, count_2 = get_names_count(image_list_train)
    print "Creating X, y for test {}".format(len(image_list_test))
    X, y = get_input(image_list_test)
    print "Predicting on test"
    y_prob = predict_prob(model, X, y)
    y_predicted = thresholding(y_prob, count_0 * 1. / y.size,
                               count_1 * 1. / y.size, count_2 * 1. / y.size)
    get_metrics(y, y_predicted)
def get_metrics(y_true, y_predicted):
    precision = precision_score(y_true, y_predicted, labels=[0,1,2], average="weighted")
    recall = recall_score(y_true, y_predicted, labels=[0,1,2], average="weighted")
    print "Precision Score {}".format(precision)
    print "Recall Score {}".format(recall)
    y_0 = y_predicted[y_true==0]
    y_1 = y_predicted[y_true==1]
    y_2 = y_predicted[y_true==2]
    print "Background: True = {}, Predicted = {}".format((y_true==0).sum(), (y_0==0).sum())
    print "Non_Mitosis: True = {}, Predicted = {}".format((y_true==1).sum(), (y_1==1).sum())
    print "Mitosis: True = {}, Predicted = {}".format((y_true==2).sum(), (y_2==2).sum())
    print confusion_matrix(y_true, y_predicted)

if __name__ == '__main__':
    print "Unpacking the model"
    model = unpack_model('../runs/gpu1/ccn1_model_architecture.json', '../runs/gpu1/ccn1_model_weights.h5')
    print "Unpickling the image list"
    with open ('../runs/gpu1/image_list.pkl') as f:
        image_list_train = pickle.load(f)
    print "Creating test image list"
    image_list_test = create_image_list(path='/data/Test/ScannerA', use_mr=False)
    print "Calculating distribution of train"
    image_names, count_0, count_1, count_2 = get_names_count(image_list_train)
    print "Creating X, y for test {}".format(len(image_list_test))
    X, y = get_input(image_list_test)
    print "Predicting on test"
    y_prob = predict_prob(model, X, y)
    y_predicted = thresholding(y_prob, count_0*1./y.size, count_1*1./y.size, count_2*1./y.size)
    get_metrics(y, y_predicted)
Example #9
0
from sklearn.cross_validation import train_test_split
from keras.models import model_from_json
import cPickle as pickle

batch_size = 32
nb_classes = 3 
nb_epoch = 10
data_augmentation = True

# input image dimensions
img_rows, img_cols = 100,100
# the mitosis images are RGB
img_channels = 3

# the data, shuffled and split between train and test sets
image_list = create_image_list('/data/ScannerA', sample_size=[-1,-1,-1,-1,-1], use_mr=True)
with open('image_list.pkl', 'w+') as f:
    pickle.dump(image_list, f)

# Create testset data for cross-val
num_images = len(image_list)
test_size = int(0.2 * num_images)
print("Train size: ", num_images-test_size)
print("Test size: ", test_size)


model = Sequential()

model.add(Convolution2D(32, 3, 3, border_mode='same',
                        input_shape=(img_channels, img_rows, img_cols)))
model.add(Activation('relu'))
Example #10
0
    y_2 = y_predicted[y_true == 2]
    print "Non-mitosis: True = {}, Predicted = {}".format((y_true == 0).sum(),
                                                          (y_0 == 0).sum())
    print "Mitosis: True = {}, Predicted = {}".format((y_true == 1).sum(),
                                                      (y_1 == 1).sum())
    print "Background: True = {}, Predicted = {}".format((y_true == 2).sum(),
                                                         (y_2 == 2).sum())
    print confusion_matrix(y_true, y_predicted)


if __name__ == '__main__':
    print "Unpacking the model"
    model = unpack_model('../runs/gpu0/cnn1_model_architecture.json',
                         '../runs/gpu0/cnn1_model_weights.h5')
    print "Unpickling the image list"
    with open('../runs/gpu1/image_list.pkl') as f:
        image_list_train = pickle.load(f)
    print "Creating test image list"
    image_list_test = create_image_list(path='/data/Test/ScannerA',
                                        sample_size=[-1, -1, 0, 0, 0],
                                        use_mr=False)
    print "Calculating distribution of train"
    image_names, count_0, count_1, count_2 = get_names_count(image_list_train)
    print "Creating X, y for test {}".format(len(image_list_test))
    X, y = get_input(image_list_test)
    print "Predicting on test"
    y_prob = predict_prob(model, X, y)
    y_predicted = np.argmax(y_prob, axis=1)
    #y_predicted = thresholding(y_prob, count_0*1./y.size, count_1*1./y.size, count_2*1./y.size)
    get_metrics(y, y_predicted, [0, 1], "binary")


batch_size = 32
nb_classes = 3 
nb_epoch = 10
data_augmentation = True

# input image dimensions
img_rows, img_cols = 100,100
# the mitosis images are RGB
img_channels = 3


# the data, shuffled and split between train and test sets
image_list = create_image_list('/data/50_50_100_40', sample_size=[-1,-1,-1,-1,-1], use_mr=True)
image_names, clusters = get_image_clusters('/home/ubuntu/capstone/code/clustering/image_names.pkl','/home/ubuntu/capstone/code/clustering/clusters.pkl')

with open('image_list.pkl', 'w+') as f:
    pickle.dump(image_list, f)

# define two groups of layers: feature (convolutions) and classification (dense) 
feature_layers = [
    Convolution2D(32, 3, 3, border_mode='same',
                    input_shape=(img_channels, img_rows, img_cols)),
    Activation('relu'),
    Convolution2D(32, 3, 3),
    Activation('relu'),
    MaxPooling2D(pool_size=(2, 2)),
    Dropout(0.1),
    Convolution2D(64, 3, 3, border_mode='same'),