@@ -2,22 +2,25 @@ package main
22
33import (
44 "bytes"
5- "fmt"
65 "io/ioutil"
76 "net/http"
87 "os"
98 "path/filepath"
109 "sync"
1110
11+ "crypto/md5"
12+ "encoding/base64"
13+ "encoding/hex"
14+
1215 "github.com/CorentinB/DeepSort/pkg/logging"
1316 "github.com/labstack/gommon/color"
1417)
1518
16- func googleNetClassification (path string , arguments * Arguments , wg * sync.WaitGroup ) {
19+ func googleNetClassification (path string , content [] byte , arguments * Arguments , wg * sync.WaitGroup ) {
1720 defer wg .Done ()
1821 url := arguments .URL + "/predict"
19- path , _ = filepath . Abs ( path )
20- var jsonStr = []byte (`{"service":"deepsort-resnet","parameters":{"input":{"width":224,"height":224},"output":{"best":1},"mllib":{"gpu":false}},"data":["` + path + `"]}` )
22+ dataStr := base64 . StdEncoding . EncodeToString ( content )
23+ var jsonStr = []byte (`{"service":"deepsort-resnet","parameters":{"input":{"width":224,"height":224},"output":{"best":1},"mllib":{"gpu":false}},"data":["` + dataStr + `"]}` )
2124 // DEBUG
2225 //fmt.Println("Request: " + string(jsonStr))
2326 req , err := http .NewRequest ("POST" , url , bytes .NewBuffer (jsonStr ))
@@ -44,20 +47,18 @@ func googleNetClassification(path string, arguments *Arguments, wg *sync.WaitGro
4447 color .Green (parsedResponse ), "[GoogleNet]" )
4548 }
4649 if arguments .DryRun != true {
47- if isValid (arguments .Output ) == false {
48- renameFile (path , arguments , parsedResponse )
49- } else {
50- fmt .Println ("Output selected" )
51- }
50+ hashBytes := md5 .Sum (content )
51+ hash := hex .EncodeToString (hashBytes [:])
52+ renameFile (path , hash , arguments , parsedResponse )
5253 }
5354 arguments .CountDone ++
5455}
5556
56- func resNet50Classification (path string , arguments * Arguments , wg * sync.WaitGroup ) {
57+ func resNet50Classification (path string , content [] byte , arguments * Arguments , wg * sync.WaitGroup ) {
5758 defer wg .Done ()
5859 url := arguments .URL + "/predict"
59- path , _ = filepath . Abs ( path )
60- var jsonStr = []byte (`{"service":"deepsort-resnet-50","parameters":{"input":{"width":224,"height":224},"output":{"best":1},"mllib":{"gpu":false}},"data":["` + path + `"]}` )
60+ dataStr := base64 . StdEncoding . EncodeToString ( content )
61+ var jsonStr = []byte (`{"service":"deepsort-resnet-50","parameters":{"input":{"width":224,"height":224},"output":{"best":1},"mllib":{"gpu":false}},"data":["` + dataStr + `"]}` )
6162 // DEBUG
6263 //fmt.Println("Request: " + string(jsonStr))
6364 req , err := http .NewRequest ("POST" , url , bytes .NewBuffer (jsonStr ))
@@ -84,14 +85,9 @@ func resNet50Classification(path string, arguments *Arguments, wg *sync.WaitGrou
8485 color .Green (parsedResponse ), "[ResNet-50]" )
8586 }
8687 if arguments .DryRun != true {
87- if isValid (arguments .Output ) == false &&
88- arguments .OutputChoice == false {
89- renameFile (path , arguments , parsedResponse )
90- } else if arguments .OutputChoice == true &&
91- isValid (arguments .Output ) == false {
92- logging .Error ("Wrong output folder." , "" )
93- os .Exit (1 )
94- }
88+ hashBytes := md5 .Sum (content )
89+ hash := hex .EncodeToString (hashBytes [:])
90+ renameFile (path , hash , arguments , parsedResponse )
9591 }
9692 arguments .CountDone ++
9793}
0 commit comments