Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/machinebox/toys
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer committed Mar 30, 2018
2 parents 16eb7ea + 880a048 commit f41d1fb
Show file tree
Hide file tree
Showing 7 changed files with 460,819 additions and 0 deletions.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@

celebmatch/public/images/

*/.DS_Store
celebmatch/.DS_Store
celebmatch/public/.DS_Store
Binary file removed celebmatch/.DS_Store
Binary file not shown.
Binary file removed celebmatch/public/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions imdbteach/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
91 changes: 91 additions & 0 deletions imdbteach/imdbteach.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package main

import (
"bufio"
"context"
"log"
"os"
"strings"
"time"

"github.com/machinebox/sdk-go/boxutil"
"github.com/machinebox/sdk-go/facebox"
pb "gopkg.in/cheggaaa/pb.v1"
)

//Main looks so small and lonely
func main() {
if err := run(); err != nil {
log.Fatalln(err)
}
}

func run() error {
faceboxClient := facebox.New("http://localhost:8080")
log.Println("waiting for box to be ready...")
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
err := boxutil.WaitForReady(ctx, faceboxClient)
if err != nil {
if err == context.Canceled {
log.Fatalln("timed out waiting for box to be ready")
}
log.Fatalln(err)
}
log.Println("box ready")
r, err := os.Open("namesandpaths.txt")
if err != nil {
return err
}
defer r.Close()
type Item struct {
Filename, Celebname string
}
itemsChan := make(chan Item)
defer close(itemsChan)
for i := 0; i < 4; i++ {
go func() {
for item := range itemsChan {
err := teachFromFile(faceboxClient, item.Filename, item.Celebname)
if err != nil {
//log.Println("ERROR: teachFromFile:", err)
}
}
}()
}

bar := pb.StartNew(460723)

s := bufio.NewScanner(r)
for s.Scan() {
//log.Println(s.Text())
subs := strings.Split(s.Text(), ",")
celebname := subs[0]
filename := "imdb_crop/" + subs[1]
itemsChan <- Item{
Filename: filename,
Celebname: celebname,
}
bar.Increment()
}
bar.Finish()
if err := s.Err(); err != nil {
return err
}
return nil
}

func teachFromFile(faceboxClient *facebox.Client, filename, name string) error {
//log.Printf("Now teaching %v (%v)\n", filename, name)
r, err := os.Open(filename)
if err != nil {
return err
}
defer r.Close()
err = faceboxClient.Teach(r, filename, name)
if err != nil {
return err
}
return nil
}
460,723 changes: 460,723 additions & 0 deletions imdbteach/namesandpaths.txt

Large diffs are not rendered by default.

0 comments on commit f41d1fb

Please sign in to comment.