Пример #1
0
 def __call__(self):
     """Train the model and visualize progress."""
     print('Start training')
     repeats = repeated(self.problem.dataset.training, self.problem.epochs)
     batches = batched(repeats, self.problem.batch_size)
     if self.visual:
         self.window.start(functools.partial(self._train_visual, batches))
     else:
         self._train(batches)
Пример #2
0
 def __call__(self):
     """Train the model and visualize progress."""
     print('Start training')
     repeats = repeated(self.problem.dataset.training, self.problem.epochs)
     batches = batched(repeats, self.problem.batch_size)
     if self.visual:
         self.window.start(functools.partial(self._train_visual, batches))
     else:
         self._train(batches)
Пример #3
0
 def test_generator(self):
     iterable = MockGenerator([1, 2, 3])
     repeats = repeated(iterable, 3)
     assert iterable.evaluated == 0
     list(repeats)
     assert iterable.evaluated == 3 * 3
Пример #4
0
 def test_result(self):
     iterable = range(14)
     repeats = repeated(iterable, 3)
     assert list(repeats) == list(iterable) * 3
Пример #5
0
 def test_generator(self):
     iterable = MockGenerator([1, 2, 3])
     repeats = repeated(iterable, 3)
     assert iterable.evaluated == 0
     list(repeats)
     assert iterable.evaluated == 3 * 3
Пример #6
0
 def test_result(self):
     iterable = range(14)
     repeats = repeated(iterable, 3)
     assert list(repeats) == list(iterable) * 3
Пример #7
0
    # Define model and initialize weights
    network = Network([
        Layer(len(problem.dataset.training[0].data), Linear),
        Layer(700, Relu),
        Layer(500, Relu),
        Layer(300, Relu),
        Layer(len(problem.dataset.training[0].target), Sigmoid)
    ])
    weights = Matrices(network.shapes)
    weights.flat = np.random.normal(0, problem.weight_scale, len(weights.flat))

    # Classes needed during training
    backprop = ParallelBackprop(network, problem.cost)
    momentum = Momentum()
    decent = GradientDecent()
    decay = WeightDecay()
    plot = Plot()

    # Train the model
    repeats = repeated(problem.dataset.training, problem.training_rounds)
    batches = batched(repeats, problem.batch_size)
    for index, batch in enumerate(batches):
        gradient = backprop(weights, batch)
        gradient = momentum(gradient, problem.momentum)
        weights = decent(weights, gradient, problem.learning_rate)
        weights = decay(weights, problem.weight_decay)
        # Show progress
        plot(compute_costs(network, weights, problem.cost, batch))
        every(problem.evaluate_every // problem.batch_size, index, evaluate,
            index, network, weights, problem.dataset.testing)