Even faster tests
This commit is contained in:
parent
0a108b3fb2
commit
7a56925176
@ -2,13 +2,14 @@ from __future__ import print_function
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from keras.utils.test_utils import get_test_data
|
||||
from keras.utils.test_utils import get_test_data, keras_test
|
||||
from keras.models import Sequential
|
||||
from keras.layers.core import Dense, Flatten, Activation
|
||||
from keras.layers.convolutional import Convolution2D, MaxPooling2D
|
||||
from keras.utils.np_utils import to_categorical
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_image_classification():
|
||||
'''
|
||||
Classify random 16x16 color images into several classes using logistic regression
|
||||
|
@ -3,7 +3,7 @@ import numpy as np
|
||||
import pytest
|
||||
import string
|
||||
|
||||
from keras.utils.test_utils import get_test_data
|
||||
from keras.utils.test_utils import get_test_data, keras_test
|
||||
from keras.utils.np_utils import to_categorical
|
||||
from keras.models import Sequential
|
||||
from keras.layers import TimeDistributedDense
|
||||
@ -14,6 +14,7 @@ from keras.layers import LSTM
|
||||
from keras.layers import Embedding
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_temporal_classification():
|
||||
'''
|
||||
Classify temporal sequences of float numbers
|
||||
@ -43,6 +44,7 @@ def test_temporal_classification():
|
||||
assert(history.history['val_acc'][-1] >= 0.85)
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_temporal_regression():
|
||||
'''
|
||||
Predict float numbers (regression) based on sequences
|
||||
@ -63,6 +65,7 @@ def test_temporal_regression():
|
||||
assert(history.history['val_loss'][-1] < 0.75)
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_sequence_to_sequence():
|
||||
'''
|
||||
Apply a same Dense layer for each element of time dimension of the input
|
||||
@ -86,6 +89,7 @@ def test_sequence_to_sequence():
|
||||
assert(history.history['val_loss'][-1] < 0.8)
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_stacked_lstm_char_prediction():
|
||||
'''
|
||||
Learn alphabetical char sequence with stacked LSTM.
|
||||
@ -135,6 +139,7 @@ def test_stacked_lstm_char_prediction():
|
||||
assert(generated == alphabet)
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_masked_temporal():
|
||||
'''
|
||||
Confirm that even with masking on both inputs and outputs, cross-entropies are
|
||||
@ -182,5 +187,4 @@ def test_masked_temporal():
|
||||
assert(np.abs(history.history['val_loss'][-1] - ground_truth) < 0.06)
|
||||
|
||||
if __name__ == '__main__':
|
||||
# pytest.main([__file__])
|
||||
test_temporal_classification()
|
||||
pytest.main([__file__])
|
||||
|
@ -2,12 +2,13 @@ from __future__ import print_function
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from keras.utils.test_utils import get_test_data
|
||||
from keras.utils.test_utils import get_test_data, keras_test
|
||||
from keras.models import Sequential
|
||||
from keras.layers.core import Dense
|
||||
from keras.utils.np_utils import to_categorical
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_vector_classification():
|
||||
'''
|
||||
Classify random float vectors into 2 classes with logistic regression
|
||||
@ -37,6 +38,7 @@ def test_vector_classification():
|
||||
assert(history.history['val_acc'][-1] > 0.8)
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_vector_regression():
|
||||
'''
|
||||
Perform float data prediction (regression) using 2 layer MLP
|
||||
|
@ -11,9 +11,9 @@ from keras.layers import convolutional
|
||||
def test_convolution_1d():
|
||||
nb_samples = 2
|
||||
nb_steps = 8
|
||||
input_dim = 5
|
||||
input_dim = 2
|
||||
filter_length = 3
|
||||
nb_filter = 4
|
||||
nb_filter = 3
|
||||
|
||||
for border_mode in ['valid', 'same']:
|
||||
for subsample_length in [1]:
|
||||
@ -58,8 +58,8 @@ def test_averagepooling_1d():
|
||||
@keras_test
|
||||
def test_convolution_2d():
|
||||
nb_samples = 2
|
||||
nb_filter = 3
|
||||
stack_size = 4
|
||||
nb_filter = 2
|
||||
stack_size = 3
|
||||
nb_row = 10
|
||||
nb_col = 6
|
||||
|
||||
@ -91,8 +91,8 @@ def test_convolution_2d():
|
||||
@keras_test
|
||||
def test_atrous_conv_2d():
|
||||
nb_samples = 2
|
||||
nb_filter = 3
|
||||
stack_size = 4
|
||||
nb_filter = 2
|
||||
stack_size = 3
|
||||
nb_row = 10
|
||||
nb_col = 6
|
||||
|
||||
@ -130,8 +130,8 @@ def test_atrous_conv_2d():
|
||||
@keras_test
|
||||
def test_separable_conv_2d():
|
||||
nb_samples = 2
|
||||
nb_filter = 8
|
||||
stack_size = 4
|
||||
nb_filter = 6
|
||||
stack_size = 3
|
||||
nb_row = 10
|
||||
nb_col = 6
|
||||
|
||||
@ -195,8 +195,8 @@ def test_averagepooling_2d():
|
||||
@keras_test
|
||||
def test_convolution_3d():
|
||||
nb_samples = 2
|
||||
nb_filter = 5
|
||||
stack_size = 4
|
||||
nb_filter = 2
|
||||
stack_size = 3
|
||||
kernel_dim1 = 2
|
||||
kernel_dim2 = 3
|
||||
kernel_dim3 = 1
|
||||
@ -261,7 +261,7 @@ def test_averagepooling_3d():
|
||||
@keras_test
|
||||
def test_zero_padding_2d():
|
||||
nb_samples = 2
|
||||
stack_size = 7
|
||||
stack_size = 2
|
||||
input_nb_row = 11
|
||||
input_nb_col = 12
|
||||
|
||||
@ -287,7 +287,7 @@ def test_zero_padding_2d():
|
||||
@pytest.mark.skipif(K._BACKEND != 'theano', reason="Requires Theano backend")
|
||||
def test_zero_padding_3d():
|
||||
nb_samples = 2
|
||||
stack_size = 7
|
||||
stack_size = 2
|
||||
input_len_dim1 = 10
|
||||
input_len_dim2 = 11
|
||||
input_len_dim3 = 12
|
||||
@ -322,7 +322,7 @@ def test_upsampling_1d():
|
||||
@keras_test
|
||||
def test_upsampling_2d():
|
||||
nb_samples = 2
|
||||
stack_size = 7
|
||||
stack_size = 2
|
||||
input_nb_row = 11
|
||||
input_nb_col = 12
|
||||
|
||||
@ -363,7 +363,7 @@ def test_upsampling_2d():
|
||||
@pytest.mark.skipif(K._BACKEND != 'theano', reason="Requires Theano backend")
|
||||
def test_upsampling_3d():
|
||||
nb_samples = 2
|
||||
stack_size = 7
|
||||
stack_size = 2
|
||||
input_len_dim1 = 10
|
||||
input_len_dim2 = 11
|
||||
input_len_dim3 = 12
|
||||
|
@ -11,7 +11,7 @@ from keras.utils.test_utils import keras_test
|
||||
|
||||
from keras import backend as K
|
||||
|
||||
nb_samples, timesteps, embedding_dim, output_dim = 3, 5, 10, 5
|
||||
nb_samples, timesteps, embedding_dim, output_dim = 2, 5, 4, 3
|
||||
embedding_num = 12
|
||||
|
||||
|
||||
@ -24,21 +24,21 @@ def _runner(layer_class):
|
||||
layer_test(layer_class,
|
||||
kwargs={'output_dim': output_dim,
|
||||
'return_sequences': True},
|
||||
input_shape=(3, 2, 3))
|
||||
input_shape=(nb_samples, timesteps, embedding_dim))
|
||||
|
||||
# check dropout
|
||||
layer_test(layer_class,
|
||||
kwargs={'output_dim': output_dim,
|
||||
'dropout_U': 0.1,
|
||||
'dropout_W': 0.1},
|
||||
input_shape=(3, 2, 3))
|
||||
input_shape=(nb_samples, timesteps, embedding_dim))
|
||||
|
||||
# check implementation modes
|
||||
for mode in ['cpu', 'mem', 'gpu']:
|
||||
layer_test(layer_class,
|
||||
kwargs={'output_dim': output_dim,
|
||||
'consume_less': mode},
|
||||
input_shape=(3, 2, 3))
|
||||
input_shape=(nb_samples, timesteps, embedding_dim))
|
||||
|
||||
# check statefulness
|
||||
model = Sequential()
|
||||
@ -83,7 +83,6 @@ def _runner(layer_class):
|
||||
left_padded_input = np.ones((nb_samples, timesteps))
|
||||
left_padded_input[0, :1] = 0
|
||||
left_padded_input[1, :2] = 0
|
||||
left_padded_input[2, :3] = 0
|
||||
out6 = model.predict(left_padded_input)
|
||||
|
||||
layer.reset_states()
|
||||
@ -91,7 +90,6 @@ def _runner(layer_class):
|
||||
right_padded_input = np.ones((nb_samples, timesteps))
|
||||
right_padded_input[0, -1:] = 0
|
||||
right_padded_input[1, -2:] = 0
|
||||
right_padded_input[2, -3:] = 0
|
||||
out7 = model.predict(right_padded_input)
|
||||
|
||||
assert_allclose(out7, out6, atol=1e-5)
|
||||
|
@ -2,14 +2,16 @@ from __future__ import print_function
|
||||
import pytest
|
||||
import numpy as np
|
||||
from keras.models import Sequential
|
||||
from keras.layers.core import Dense, Activation
|
||||
from keras.layers.core import Dense
|
||||
from keras.utils.test_utils import keras_test
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_multiprocessing_training():
|
||||
|
||||
reached_end = False
|
||||
|
||||
arr_data = np.random.randint(0,256, (500, 200))
|
||||
arr_data = np.random.randint(0, 256, (500, 2))
|
||||
arr_labels = np.random.randint(0, 2, 500)
|
||||
|
||||
def myGenerator():
|
||||
@ -27,10 +29,7 @@ def test_multiprocessing_training():
|
||||
|
||||
# Build a NN
|
||||
model = Sequential()
|
||||
model.add(Dense(10, input_shape=(200, )))
|
||||
model.add(Activation('relu'))
|
||||
model.add(Dense(1))
|
||||
model.add(Activation('linear'))
|
||||
model.add(Dense(1, input_shape=(2, )))
|
||||
model.compile(loss='mse', optimizer='adadelta')
|
||||
|
||||
model.fit_generator(myGenerator(),
|
||||
@ -53,11 +52,12 @@ def test_multiprocessing_training():
|
||||
assert reached_end
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_multiprocessing_training_fromfile():
|
||||
|
||||
reached_end = False
|
||||
|
||||
arr_data = np.random.randint(0,256, (500, 200))
|
||||
arr_data = np.random.randint(0, 256, (500, 2))
|
||||
arr_labels = np.random.randint(0, 2, 500)
|
||||
np.savez("data.npz", **{"data": arr_data, "labels": arr_labels})
|
||||
|
||||
@ -78,10 +78,7 @@ def test_multiprocessing_training_fromfile():
|
||||
|
||||
# Build a NN
|
||||
model = Sequential()
|
||||
model.add(Dense(10, input_shape=(200, )))
|
||||
model.add(Activation('relu'))
|
||||
model.add(Dense(1))
|
||||
model.add(Activation('linear'))
|
||||
model.add(Dense(1, input_shape=(2, )))
|
||||
model.compile(loss='mse', optimizer='adadelta')
|
||||
|
||||
model.fit_generator(myGenerator(),
|
||||
@ -103,11 +100,12 @@ def test_multiprocessing_training_fromfile():
|
||||
assert reached_end
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_multiprocessing_predicting():
|
||||
|
||||
reached_end = False
|
||||
|
||||
arr_data = np.random.randint(0,256, (500, 200))
|
||||
arr_data = np.random.randint(0, 256, (500, 2))
|
||||
|
||||
def myGenerator():
|
||||
|
||||
@ -123,10 +121,7 @@ def test_multiprocessing_predicting():
|
||||
|
||||
# Build a NN
|
||||
model = Sequential()
|
||||
model.add(Dense(10, input_shape=(200, )))
|
||||
model.add(Activation('relu'))
|
||||
model.add(Dense(1))
|
||||
model.add(Activation('linear'))
|
||||
model.add(Dense(1, input_shape=(2, )))
|
||||
model.compile(loss='mse', optimizer='adadelta')
|
||||
model.predict_generator(myGenerator(),
|
||||
val_samples=320,
|
||||
@ -142,11 +137,12 @@ def test_multiprocessing_predicting():
|
||||
assert reached_end
|
||||
|
||||
|
||||
@keras_test
|
||||
def test_multiprocessing_evaluating():
|
||||
|
||||
reached_end = False
|
||||
|
||||
arr_data = np.random.randint(0,256, (500, 200))
|
||||
arr_data = np.random.randint(0, 256, (500, 2))
|
||||
arr_labels = np.random.randint(0, 2, 500)
|
||||
|
||||
def myGenerator():
|
||||
@ -164,10 +160,7 @@ def test_multiprocessing_evaluating():
|
||||
|
||||
# Build a NN
|
||||
model = Sequential()
|
||||
model.add(Dense(10, input_shape=(200, )))
|
||||
model.add(Activation('relu'))
|
||||
model.add(Dense(1))
|
||||
model.add(Activation('linear'))
|
||||
model.add(Dense(1, input_shape=(2, )))
|
||||
model.compile(loss='mse', optimizer='adadelta')
|
||||
|
||||
model.evaluate_generator(myGenerator(),
|
||||
|
Loading…
Reference in New Issue
Block a user