Navigation Menu

Skip to content

Commit

Permalink
we have the sketchy conv net we promised see we deliver bet hackernew…
Browse files Browse the repository at this point in the history
…s ppl wish they delivered on something rather then just tried and they'll be tryna claim they could've for the rest of their lives.

REAL DRAKE SHIT but serious listen to two birds one stone DRAKE is a genius with the diss
  • Loading branch information
geohot committed Dec 26, 2016
1 parent 7cc0c53 commit da31f7a
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
.*.swp
imgs
dst.png
105 changes: 103 additions & 2 deletions loader.go
Expand Up @@ -12,16 +12,95 @@ TODO: don't be cheater and use python only golang pull request accepted

import (
"path/filepath"
"image"
"image/png"
"math/rand"
"strings"
_"fmt"
"os"
"log"
_"github.com/disintegration/imaging"
"github.com/disintegration/gift"
"github.com/NOX73/go-neural"
"github.com/NOX73/go-neural/learn"
)

func randomArray(n int) []float32 {
ret := make([]float32, n)
for i := 0; i < n; i++ {
ret[i] = (rand.Float32()-0.5)*5
}
return ret
}

func main() {
log.Print("use log so we don't have to put an underscore before the import")

type Example struct {
features []float64
yes bool
}

paths := make(chan string)
processed := make(chan Example)

// the Seed for the network is 7
rand.Seed(7)

g := gift.New(
// edge detector
gift.Convolution(
[]float32{
-1, -1, -1,
-1, 8, -1,
-1, -1, -1,
},
false, false, false, 0.0),
// is this max pool?
gift.Maximum(2, true),
gift.Resize(50, 0, gift.LinearResampling),

// random 5x5 conv, hmm but like the color channels bro this is a shit neural network
gift.Convolution(
randomArray(25),
false, false, false, 0.0),
// is this max pool?
gift.Maximum(2, true),
gift.Resize(25, 0, gift.LinearResampling),

// random 3x3 conv, hmm but like the color channels bro this is a shit neural network
gift.Convolution(
randomArray(9),
false, false, false, 0.0),
// is this max pool?
gift.Maximum(2, true),
gift.Resize(10, 0, gift.LinearResampling),

// 300 features one for each spartan RIP
)

n := neural.NewNetwork(300, []int{100,20,1})
n.RandomizeSynapses()

// forest builder
go func() {
// is this a proper design pattern?
// probs not it's awkward ROS node shit
for {
sample := <-processed
//fmt.Println(sample)

// ugh no inline if?
prob := []float64{0.01}
if sample.yes {
prob = []float64{0.4}
}

learn.Learn(n, sample.features, prob, 0.05)

println(learn.Evaluation(n, sample.features, prob))
}
}()

// image loader and network runner
go func() {
Expand All @@ -36,13 +115,35 @@ func main() {
if err != nil { log.Fatal(err) }
f.Close()

println(img)
dst := image.NewRGBA(g.Bounds(img.Bounds()))
g.Draw(dst, img)

// extract features
// i can write much better than this wow shit
ret := make([]float64, 300)
cnt := 0
for i:=0;i<400;i++ {
if i%4 == 3 { continue }
ret[cnt] = float64(dst.Pix[i]) / 256.0
cnt += 1
}

//fmt.Println(path)

processed <- Example{features: ret, yes: strings.Contains(path, "street_signs")}

//imaging.Save(dst, "dst.png")
//println(dst)
}
}()

justone := true
filepath.Walk("imgs/", func(path string, finfo os.FileInfo, err error) error {
if finfo.IsDir() { return nil }
paths <- path
if justone {
paths <- path
justone = true
}
return nil
});

Expand Down

0 comments on commit da31f7a

Please sign in to comment.