예제 #1
0
    def test_split(self):
        options = Options()
        _, _, x_test, _ = get_dataset(options)
        model = train_network(get_model(x_test, options), options)
        part1, part2 = split_network(model, 3)
        model_output = model(x_test[0:5])
        split_output = part2(part1(x_test[0:5]))

        equality = tf.math.reduce_all(tf.equal(model_output, split_output))
        self.assertEqual(equality, True)
예제 #2
0
 def test_compose_rotation(self):
     """Test whether rotation -> convolution == convolution -> rotation
     It isn't. This has implications for our project.
     This is not as much a test as a demonstration of fact"""
     options = Options()
     _, _, x_test, _ = get_dataset(options)
     model = train_network(get_model(x_test, options), options)
     part1, _ = split_network(model, 8)
     image = tf.expand_dims(x_test[0], 0)
     rotated_image = tfa.image.rotate(image, math.pi)
     out = tfa.image.rotate(part1(image), math.pi)
     rotated_out = part1(rotated_image)
     equality = tf.math.reduce_all(
         tf.equal(tfa.image.rotate(out, math.pi), rotated_out))
     self.assertEqual(equality, False)
예제 #3
0
def basic(iterations, profile):
    options = Options()
    options.serial = True
    #options.accperclass = True
    options.convlayers = 0
    options.step = 20
    options.combine = True
    options.post_init()
    x_train, y_train, x_test, y_test = get_dataset(options)  # pylint: disable=unused-variable
    model = train_network(get_model(x_test, options), options)
    only_convolutional, _ = split_network(model, options.convlayers)  # pylint: disable=unused-variable
    cmd_string = """run_experiment(iterations, options, x_train, y_train, x_test, y_test,
                    model, only_convolutional, EXPERIMENT_DIR + '/basic.csv')"""
    if profile:
        cProfile.run(cmd_string, PROFILING_DIR + '/basic')
    else:
        exec(cmd_string)
예제 #4
0
def rot_first(iterations, profile):
    options = Options()
    options.serial = True
    options.convlayers = 5
    options.step = 20
    options.combine = False
    options.representatives = False
    options.rotate_first = True
    options.post_init()
    x_train, y_train, x_test, y_test = get_dataset(options)  # pylint: disable=unused-variable
    model = train_network(get_model(x_test, options), options)
    options.convlayers = get_last_conv_layer(model) + 1
    only_convolutional, _ = split_network(model, options.convlayers)  # pylint: disable=unused-variable
    cmd_string = """run_experiment(iterations, options, x_train, y_train, x_test, y_test,
                    model, only_convolutional, EXPERIMENT_DIR + '/rotate_first.csv')"""
    if profile:
        cProfile.run(cmd_string, PROFILING_DIR + '/rotate_first')
    else:
        exec(cmd_string)
예제 #5
0
import sys
import os
from src.runner import check_some
from src.options import Options
from src.training_sample_finder import get_training_samples
from src.network import train_network, get_dataset, get_model, split_network

sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))

if __name__ == "__main__":
    # Initialize the options class.
    options = Options()
    # Parse arguments
    options.parse_args(10000)
    # Get the MNIST dataset
    x_train, y_train, x_test, y_test = get_dataset(options)
    # Gets the model and the conv part of model, the function also trains the
    # network, if there doesn't exist a saved network
    model = train_network(get_model(x_test, options), options)
    only_convolutional, _ = split_network(model, options.convlayers)
    model.summary()
    if only_convolutional is not None:
        only_convolutional.summary()
    training_samples = get_training_samples(only_convolutional, x_train,
                                            y_train, options)

    # Run the checksome function, which tests a chosen algorithm to find if it
    # can properly rotate pictures back
    check_some(only_convolutional, x_test, y_test, model, training_samples,
               options)