Skip to content

Commit

Permalink
Updating the unit tests with the ciritcal change to the feature space…
Browse files Browse the repository at this point in the history
… code
  • Loading branch information
gravityspy committed Nov 14, 2018
1 parent 0443e48 commit b08c0a5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bin/wscan
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
33 changes: 13 additions & 20 deletions gravityspy/ml/labelling_test_glitches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down
4 changes: 2 additions & 2 deletions gravityspy/ml/read_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit b08c0a5

Please sign in to comment.