def test_freeze_weight(self): config.gan.generator.optimizer.type = "RMSprop" self.genome.add(Conv2d(16)) self.genome.add(Linear(32)) self.genome.add(Linear(16)) self.genome.output_genes.append(Linear(out_features=1, activation_type='Sigmoid')) x = Variable(torch.randn(5, 64)).view(5, 1, 8, 8) self.phenotype.create_model(x) self.train_step(self.phenotype, x) weight = self.genome.genes[0].module.weight.clone() self.train_step(self.phenotype, x) self.assertFalse(weight.equal(self.genome.genes[0].module.weight)) config.evolution.freeze_when_change = True for gene in self.genome.genes: weight, bias = gene.module.weight.clone(), gene.module.bias.clone() gene.freeze() self.train_step(self.phenotype, x) self.assertTrue(weight.equal(gene.module.weight)) self.assertTrue(bias.equal(gene.module.bias)) gene.unfreeze() self.train_step(self.phenotype, x) self.assertFalse(weight.equal(gene.module.weight)) self.assertFalse(bias.equal(gene.module.bias))
def test_complex_graph2(self): self.genome.add(Conv2d(1)) self.genome.add(Linear(128)) self.evaluate_model([5, 1, 28, 28])
def test_zero_output(self): self.genome.add(Conv2d(1, kernel_size=3)) self.genome.add(Conv2d(6, kernel_size=3)) self.genome.add(Conv2d(8, kernel_size=3)) self.genome.add(Conv2d(5, kernel_size=3)) self.evaluate_model([5, 1, 5, 5])
def test_first_linear_after_conv2d(self): self.genome.add(Linear(32)) self.genome.add(Conv2d(3)) self.assertEqual([Conv2d, Linear], [gene.__class__ for gene in self.genome.genes]) self.evaluate_model([5, 3, 5, 5])