def test_save_load_save(): """ Test that a monitor can be saved, then loaded, and then the loaded copy can be saved again. This only tests that the serialization and deserialization processes don't raise an exception. It doesn't test for correctness at all. """ model = DummyModel(1) monitor = Monitor.get_monitor(model) num_examples = 2 num_features = 3 num_batches = 1 batch_size = 2 dataset = DummyDataset(num_examples, num_features) monitor.add_dataset(dataset=dataset, num_batches=num_batches, batch_size=batch_size) vis_batch = T.matrix() mean = vis_batch.mean() data_specs = (monitor.model.get_input_space(), monitor.model.get_input_source()) monitor.add_channel(name='mean', ipt=vis_batch, val=mean, dataset=dataset, data_specs=data_specs) saved = to_string(monitor) monitor = from_string(saved) saved_again = to_string(monitor)
def test_deserialize(): # Test that a monitor can be deserialized model = DummyModel(1) monitor = Monitor.get_monitor(model) x = to_string(monitor) monitor = from_string(x) y = to_string(monitor)
def test_serialize_twice(): # Test that a monitor can be serialized twice # with the same result model = DummyModel(1) monitor = Monitor.get_monitor(model) x = to_string(monitor) y = to_string(monitor) assert x == y
def test_prereqs_multidataset(): # Test that prereqs are run on the right datasets NUM_DATASETS = 4 NUM_FEATURES = 3 model = DummyModel(NUM_FEATURES) monitor = Monitor.get_monitor(model) prereq_counters = [] datasets = [] for i in xrange(NUM_DATASETS): batch_size = i + 1 num_examples = batch_size dataset = DummyDataset(num_examples = num_examples, num_features = NUM_FEATURES) dataset.X[:] = i datasets.append(dataset) monitor.add_dataset(dataset, 'sequential', batch_size=batch_size) prereq_counters.append(sharedX(0.)) channels = [] for i in xrange(NUM_DATASETS): monitor.add_channel(name = str(i), ipt = model.input_space.make_theano_batch(), val = prereq_counters[i], dataset = datasets[i], prereqs = [ ReadVerifyPrereq(i, prereq_counters[i]) ], data_specs=(model.get_input_space(), model.get_input_source())) channels.append(monitor.channels[str(i)]) for channel in channels: assert len(channel.val_record) == 0 monitor() for channel in channels: assert channel.val_record == [1] monitor() for channel in channels: assert channel.val_record == [1,2] # check that handling all these datasets did not # result in them getting serialized to_string(monitor)
def test_valid_after_serialize(): # Test that serializing the monitor does not ruin it BATCH_SIZE = 2 num_examples = 2 * BATCH_SIZE NUM_FEATURES = 3 model = DummyModel(NUM_FEATURES) monitor = Monitor.get_monitor(model) monitoring_dataset = DummyDataset(num_examples=num_examples, num_features=NUM_FEATURES) monitoring_dataset.yaml_src = "" monitor.add_dataset(monitoring_dataset, "sequential", batch_size=BATCH_SIZE) to_string(monitor) monitor.redo_theano()
def test_dont_serialize_dataset(): # Test that serializing the monitor does not serialize the dataset BATCH_SIZE = 2 num_examples = 2 * BATCH_SIZE NUM_FEATURES = 3 model = DummyModel(NUM_FEATURES) monitor = Monitor.get_monitor(model) monitoring_dataset = DummyDataset(num_examples = num_examples, num_features = NUM_FEATURES) monitoring_dataset.yaml_src = "" monitor.add_dataset(monitoring_dataset, 'sequential', batch_size=BATCH_SIZE) monitor() to_string(monitor)
def test_valid_after_serialize(): # Test that serializing the monitor does not ruin it BATCH_SIZE = 2 num_examples = 2 * BATCH_SIZE NUM_FEATURES = 3 model = DummyModel(NUM_FEATURES) monitor = Monitor.get_monitor(model) monitoring_dataset = DummyDataset(num_examples = num_examples, num_features = NUM_FEATURES) monitoring_dataset.yaml_src = "" monitor.add_dataset(monitoring_dataset, 'sequential', batch_size=BATCH_SIZE) to_string(monitor) monitor.redo_theano()