-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
48 lines (40 loc) · 1.09 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"log"
"math/rand"
"os"
"time"
"github.com/sno6/mnist"
"image/png"
)
const (
// Change these to point your image / label files.
imagesLoc = "../data/train-images-idx3-ubyte"
labelsLoc = "../data/train-labels-idx1-ubyte"
testingImagesLoc = "../data/t10k-images-idx3-ubyte"
testingLabelsLoc = "../data/t10k-labels-idx1-ubyte"
)
func main() {
// Files can be a partial list and this will still work.
m, err := mnist.New(&mnist.Files{
TrainingImagesLoc: imagesLoc,
TrainingLabelsLoc: labelsLoc,
TestingImagesLoc: testingImagesLoc,
TestingLabelsLoc: testingLabelsLoc,
})
if err != nil {
log.Fatalf("mnist: Error processing MNIST data: %v\n", err)
}
rand.Seed(time.Now().UnixNano())
i := rand.Intn(m.TestingImages.Count)
img := mnist.ToGrayScale(m.TestingImages.GetImage(i))
f, err := os.Create(fmt.Sprintf("mnist-image-%v.png", m.TestingLabels.GetLabel(i)))
if err != nil {
log.Fatalf("mnist: Error creating file\n", err)
}
defer f.Close()
if err := png.Encode(f, img); err != nil {
log.Fatalf("mnist: Error writing image\n", err)
}
}