From b08c0a5ee92fc6e638faea4718f2a5725d96537c Mon Sep 17 00:00:00 2001 From: gravityspy Date: Wed, 14 Nov 2018 17:50:58 -0600 Subject: [PATCH] Updating the unit tests with the ciritcal change to the feature space code --- bin/wscan | 2 +- gravityspy/ml/labelling_test_glitches.py | 33 ++++++++++-------------- gravityspy/ml/read_image.py | 4 +-- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/bin/wscan b/bin/wscan index 489a214..7520c31 100755 --- a/bin/wscan +++ b/bin/wscan @@ -148,7 +148,7 @@ def main(channel_name, frametype, event_time, gid, plot_directory, elif hdf5: results.convert_unicode_to_bytestring() results.write(os.path.join(final_path, 'classification.hdf5'), - path='/{0}'.format(idstring), format='hdf5', append=True)) + path='/{0}'.format(idstring), format='hdf5', append=True) if path_to_similarity_search is not None: features.convert_unicode_to_bytestring() features.write(os.path.join(final_path, 'features.hdf5'), diff --git a/gravityspy/ml/labelling_test_glitches.py b/gravityspy/ml/labelling_test_glitches.py index fddc73c..502e83b 100755 --- a/gravityspy/ml/labelling_test_glitches.py +++ b/gravityspy/ml/labelling_test_glitches.py @@ -3,6 +3,7 @@ K.set_image_dim_ordering('th') from keras.models import load_model from scipy.misc import imresize +from keras.applications.vgg16 import preprocess_input import numpy import os @@ -182,30 +183,22 @@ def get_multiview_feature_space(image_data, semantic_model_name, a 200 dimensional feature space vector """ img_rows, img_cols = image_size[0], image_size[1] - test_set_unlabelled_x_1 = image_data.filter(regex=("1.0.png")).iloc[0].iloc[0] - test_set_unlabelled_x_2 = image_data.filter(regex=("2.0.png")).iloc[0].iloc[0] - test_set_unlabelled_x_3 = image_data.filter(regex=("4.0.png")).iloc[0].iloc[0] - test_set_unlabelled_x_4 = image_data.filter(regex=("0.5.png")).iloc[0].iloc[0] - test_set_unlabelled_x_1 = numpy.concatenate((test_set_unlabelled_x_1[0].reshape(-1, 1, img_rows, img_cols), - test_set_unlabelled_x_1[1].reshape(-1, 1, img_rows, img_cols), - test_set_unlabelled_x_1[2].reshape(-1, 1, img_rows, img_cols)), - axis=1) - test_set_unlabelled_x_2 = numpy.concatenate((test_set_unlabelled_x_2[0].reshape(-1, 1, img_rows, img_cols), - test_set_unlabelled_x_2[1].reshape(-1, 1, img_rows, img_cols), - test_set_unlabelled_x_2[2].reshape(-1, 1, img_rows, img_cols)), - axis=1) - test_set_unlabelled_x_3 = numpy.concatenate((test_set_unlabelled_x_3[0].reshape(-1, 1, img_rows, img_cols), - test_set_unlabelled_x_3[1].reshape(-1, 1, img_rows, img_cols), - test_set_unlabelled_x_3[2].reshape(-1, 1, img_rows, img_cols)), - axis=1) - test_set_unlabelled_x_4 = numpy.concatenate((test_set_unlabelled_x_4[0].reshape(-1, 1, img_rows, img_cols), - test_set_unlabelled_x_4[1].reshape(-1, 1, img_rows, img_cols), - test_set_unlabelled_x_4[2].reshape(-1, 1, img_rows, img_cols)), - axis=1) + half_second_images = sorted(image_data.filter(regex=("0.5.png")).keys()) + one_second_images = sorted(image_data.filter(regex=("1.0.png")).keys()) + two_second_images = sorted(image_data.filter(regex=("2.0.png")).keys()) + four_second_images = sorted(image_data.filter(regex=("4.0.png")).keys()) + + test_set_unlabelled_x_1 = numpy.vstack(image_data[one_second_images].iloc[0]).reshape(-1, 3, img_rows, img_cols) + test_set_unlabelled_x_2 = numpy.vstack(image_data[two_second_images].iloc[0]).reshape(-1, 3, img_rows, img_cols) + test_set_unlabelled_x_3 = numpy.vstack(image_data[four_second_images].iloc[0]).reshape(-1, 3, img_rows, img_cols) + test_set_unlabelled_x_4 = numpy.vstack(image_data[half_second_images].iloc[0]).reshape(-1, 3, img_rows, img_cols) + semantic_idx_model = load_model(semantic_model_name) concat_test_unlabelled = concatenate_views(test_set_unlabelled_x_1, test_set_unlabelled_x_2, test_set_unlabelled_x_3, test_set_unlabelled_x_4, [img_rows, img_cols], True) + concat_test_unlabelled = preprocess_input(concat_test_unlabelled) + half_second_images = sorted(image_data.filter(regex=("0.5.png")).keys()) ids = [] diff --git a/gravityspy/ml/read_image.py b/gravityspy/ml/read_image.py index 14f507f..ac44651 100755 --- a/gravityspy/ml/read_image.py +++ b/gravityspy/ml/read_image.py @@ -58,7 +58,7 @@ def read_grayscale(filename, resolution=0.3, x=[66, 532], y=[105, 671], image_data = rgb2gray(image_data) image_data = rescale(image_data, resolution, mode='constant', - preserve_range='True') + preserve_range='True',multichannel=False) dim = np.int(reduce(lambda x, y: x * y, image_data.shape)) image_data = np.reshape(image_data, (dim)) @@ -90,7 +90,7 @@ def read_rgb(filename, resolution=0.3, x=[66, 532], y=[105, 671], image_data = read_and_crop_image(filename, x=x, y=y) image_data = rescale(image_data, resolution, mode='constant', - preserve_range='True') + preserve_range='True', multichannel=True) dim = np.int(reduce(lambda x, y: x * y, image_data[:,:,0].shape)) image_data_r = np.reshape(image_data[:,:,0], (dim)) image_data_g = np.reshape(image_data[:,:,1], (dim))