def test_custom_cmd(self): testmodules = [ { "name": "test", "button": "test.left-click", "action": "echo" }, { "name": "test:alias", "button": "alias.right-click", "action": "echo2" }, ] cmd = "-m" for test in testmodules: cmd += " " + test["name"] cmd += " -p" for test in testmodules: cmd += " " + test["button"] + "=" + test["action"] cfg = Config(shlex.split(cmd)) inp = MockInput() engine = Engine(config=cfg, output=MockOutput(), inp=inp) i = 0 for module in engine.modules(): callback = inp.get_callback(module.id) self.assertTrue(callback is not None) self.assertEquals(callback["command"], testmodules[i]["action"]) if "left" in testmodules[i]["button"]: self.assertTrue(callback["button"], bumblebee.input.LEFT_MOUSE) if "right" in testmodules[i]["button"]: self.assertTrue(callback["button"], bumblebee.input.RIGHT_MOUSE) i += 1
def test_fails_with_no_trainer(self): trainer = MockTrainer() bad_config = hg.Configuration.default() bad_config['trainer'] = None gan = GAN(inputs=MockInput(), config=bad_config) with self.assertRaises(ValidationException): gan.step()
def test_create(self): with self.test_session(): gan = BaseGAN(inputs=MockInput()) gan.create() self.assertEqual(gan.created, True) with self.assertRaises(ValidationException): gan.create()
def test_create_component(self): with self.test_session(): gan = BaseGAN(inputs=MockInput()) distribution = gan.create_component(gan.config.distribution) self.assertEqual( type(distribution), hg.distributions.uniform_distribution.UniformDistribution)
def test_train_updates_posterior(self): with self.test_session(): gan = GAN(inputs=MockInput()) prior_g = gan.session.run(gan.generator.weights()[0]) prior_d = gan.session.run(gan.discriminator.weights()[0]) gan.step() posterior_g = gan.session.run(gan.generator.weights()[0]) posterior_d = gan.session.run(gan.discriminator.weights()[0]) self.assertNotEqual(posterior_g.mean(), prior_g.mean()) self.assertNotEqual(posterior_d.mean(), prior_d.mean())
def setUp(self): self.engine = Engine(config=Config(), output=MockOutput(), inp=MockInput()) self.testModule = "test" self.testAlias = "test-alias" self.singleWidgetModule = [{"module": self.testModule, "name": "a"}] self.singleWidgetAlias = [{"module": self.testAlias, "name": "a" }] self.invalidModule = "no-such-module" self.testModuleSpec = "bumblebee.modules.{}".format(self.testModule) self.testModules = [ {"module": "test", "name": "a"}, {"module": "test", "name": "b"}, ]
def test_overridable_components(self): with self.test_session(): gan = GAN(inputs=MockInput()) gan.discriminator = "d_override" gan.generator = "g_override" gan.encoder = "e_override" gan.loss = "l_override" gan.trainer = "t_override" self.assertEqual(gan.discriminator, "d_override") self.assertEqual(gan.generator, "g_override") self.assertEqual(gan.encoder, "e_override") self.assertEqual(gan.loss, "l_override") self.assertEqual(gan.trainer, "t_override")
def test_create(self): with self.test_session(): remove_d_config = hg.Configuration.default() remove_d_config['discriminator'] = None remove_d_config['loss'] = None remove_d_config['trainer'] = None gan = hg.GAN(config=remove_d_config, inputs=MockInput()) discriminator = AutoencoderDiscriminator(gan, config) gan.encoder = gan.create_component(gan.config.encoder) gan.encoder.create() gan.generator = gan.create_component(gan.config.generator) gan.generator.create() net = discriminator.create() gan.create() self.assertEqual(int(net.get_shape()[1]), 32)
def test_default(self): with self.test_session(): gan = GAN(inputs=MockInput()) gan.create() self.assertEqual(type(gan.generator), ResizeConvGenerator) self.assertEqual(type(gan.discriminator), PyramidDiscriminator)
def test_default(self): with self.test_session(): gan = GAN(inputs=MockInput()) self.assertEqual(type(gan.generator), ResizableGenerator)
def test_train(self): with self.test_session(): gan = GAN(inputs=MockInput()) gan.step() self.assertEqual(gan.trainer.current_step, 1)
def test_create_component(self): with self.test_session(): gan = BaseGAN(inputs=MockInput()) encoder = gan.create_component(gan.config.encoder) self.assertEqual(type(encoder), hg.encoders.uniform_encoder.UniformEncoder)
def test_validate(self): with self.assertRaises(ValidationException): gan = GAN(inputs=MockInput(), config={})
def test_constructor(self): with self.test_session(): gan = BaseGAN(inputs=MockInput()) self.assertNotEqual(gan.config.description, None)
def test_constructor(self): with self.test_session(): mock_input = MockInput() gan = GAN(inputs=mock_input, config=default_config) self.assertEqual(gan.inputs.x, mock_input.x)
def test_has_input(self): with self.test_session(): inputs = MockInput() gan = BaseGAN(inputs=inputs) self.assertEqual(gan.inputs.x, inputs.x)
def test_config(self): with self.test_session(): gan = mock_gan(config=remove_d_config, inputs=MockInput()) loss = CramerLoss(gan, loss_config) self.assertTrue(loss.config.test)
def test_get_config_value(self): with self.test_session(): gan = BaseGAN(inputs=MockInput()) self.assertEqual(type(gan.get_config_value('generator')), hc.config.Config) self.assertEqual(gan.get_config_value('missing'), None)
def test_height(self): with self.test_session(): gan = BaseGAN(inputs=MockInput()) self.assertEqual(gan.height(), 32)
def test_batch_size(self): with self.test_session(): gan = BaseGAN(inputs=MockInput(batch_size=1)) self.assertEqual(gan.batch_size(), 1)