Skip to content

Instantly share code, notes, and snippets.

@unixpickle
Created February 27, 2017 00:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unixpickle/21cdbdbb6d63af645d9ec88f691edba7 to your computer and use it in GitHub Desktop.
Save unixpickle/21cdbdbb6d63af645d9ec88f691edba7 to your computer and use it in GitHub Desktop.
Training image test
// Quickly hand-verify inputs to my ResNet
package main
import (
"image"
"image/color"
"image/png"
"math/rand"
"os"
"time"
"github.com/unixpickle/imagenet"
)
func main() {
rand.Seed(time.Now().UnixNano())
aug, _ := imagenet.TrainingImage("monkey.jpg")
augVec := aug.Data().([]float32)
if len(augVec) != 224*224*3 {
panic("length")
}
res := image.NewRGBA(image.Rect(0, 0, 224, 224))
for y := 0; y < 224; y++ {
for x := 0; x < 224; x++ {
rgb := augVec[:3]
augVec = augVec[3:]
res.SetRGBA(x, y, color.RGBA{
R: uint8(rgb[0]*0xff + 0.5),
G: uint8(rgb[1]*0xff + 0.5),
B: uint8(rgb[2]*0xff + 0.5),
A: 0xff,
})
}
}
f, _ := os.Create("output.png")
png.Encode(f, res)
f.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment