示例#1
0
文件: main.go 项目: unixpickle/weakai
func main() {
	training := mnist.LoadTrainingDataSet()
	samples := make([][]bool, len(training.Samples))
	for i, sample := range training.Samples {
		samples[i] = make([]bool, len(sample.Intensities))
		for j, x := range sample.Intensities {
			if x > 0.5 {
				samples[i][j] = true
			}
		}
	}

	layers := buildLayers()
	trainer := rbm.Trainer{
		GibbsSteps: GibbsSteps,
		StepSize:   BigStepSize,
		Epochs:     BigEpochs,
		BatchSize:  runtime.GOMAXPROCS(0),
	}
	log.Println("Training...")
	trainer.TrainDeep(layers, samples[:1000])
	trainer.StepSize = SmallStepSize
	trainer.Epochs = SmallEpochs
	trainer.TrainDeep(layers, samples[:1000])
	log.Println("Generating outputs...")

	testingSamples := mnist.LoadTestingDataSet()

	mnist.SaveReconstructionGrid("output.png", func(img []float64) []float64 {
		return reconstruct(layers, img)
	}, testingSamples, ReconstructionGridSize, ReconstructionGridSize)
}
示例#2
0
文件: main.go 项目: unixpickle/weakai
func pretrainedClassifier(d [][]bool) neuralnet.Network {
	log.Println("Pre-training with DBN...")

	trainer := rbm.Trainer{
		GibbsSteps: BoltzmannGibbsSteps,
		StepSize:   BoltzmannStepSize,
		Epochs:     BoltzmannEpochs,
		BatchSize:  runtime.GOMAXPROCS(0),
	}
	layers := createDBN()
	trainer.TrainDeep(layers, d[:BoltzmannSamples])

	classifier := layers.BuildANN()
	outputLayer := &neuralnet.DenseLayer{
		InputCount:  LayerSizes[len(LayerSizes)-1],
		OutputCount: DigitCount,
	}
	outputLayer.Randomize()
	classifier = append(classifier, outputLayer, neuralnet.Sigmoid{})

	return classifier
}