Skip to content

Commit 9983e47

Browse files
committed
Send base64 to DeepDetect
1 parent 0c8f26d commit 9983e47

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ Because sometimes, you have folders full of badly named pictures, and you want t
1414
You need DeepDetect installed, the easiest way is using docker:
1515
```
1616
docker pull beniz/deepdetect_cpu
17-
docker run -d -p 8080:8080 -v /path/to/images:/path/to/images beniz/deepdetect_cpu
18-
```
19-
20-
PLEASE NOTE THAT THE PATH IN THE HOST SHOULD BE THE SAME IN THE CONTAINER!
21-
22-
Example:
23-
```
24-
docker run -d -p 8080:8080 -v /home/corentin/Images:/home/corentin/Images beniz/deepdetect_cpu
17+
docker run -d -p 8080:8080 beniz/deepdetect_cpu
2518
```
2619

2720
Right now, the only supported installation of DeepDetect that works with DeepSort is the deepdetect_cpu container.

cmd/deepsort/classify.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
func googleNetClassification(path string, arguments *Arguments, wg *sync.WaitGroup) {
1616
defer wg.Done()
1717
url := arguments.URL + "/predict"
18-
path, _ = filepath.Abs(path)
19-
var jsonStr = []byte(`{"service":"deepsort-resnet","parameters":{"input":{"width":224,"height":224},"output":{"best":1},"mllib":{"gpu":false}},"data":["` + path + `"]}`)
18+
dataStr := readFile(path)
19+
var jsonStr = []byte(`{"service":"deepsort-resnet","parameters":{"input":{"width":224,"height":224},"output":{"best":1},"mllib":{"gpu":false}},"data":["` + dataStr + `"]}`)
2020
// DEBUG
2121
//fmt.Println("Request: " + string(jsonStr))
2222
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
@@ -51,8 +51,8 @@ func googleNetClassification(path string, arguments *Arguments, wg *sync.WaitGro
5151
func resNet50Classification(path string, arguments *Arguments, wg *sync.WaitGroup) {
5252
defer wg.Done()
5353
url := arguments.URL + "/predict"
54-
path, _ = filepath.Abs(path)
55-
var jsonStr = []byte(`{"service":"deepsort-resnet-50","parameters":{"input":{"width":224,"height":224},"output":{"best":1},"mllib":{"gpu":false}},"data":["` + path + `"]}`)
54+
dataStr := readFile(path)
55+
var jsonStr = []byte(`{"service":"deepsort-resnet-50","parameters":{"input":{"width":224,"height":224},"output":{"best":1},"mllib":{"gpu":false}},"data":["` + dataStr + `"]}`)
5656
// DEBUG
5757
//fmt.Println("Request: " + string(jsonStr))
5858
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))

cmd/deepsort/read_file.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"bytes"
5+
"encoding/base64"
6+
"github.com/CorentinB/DeepSort/pkg/logging"
7+
"io"
8+
"os"
9+
"path/filepath"
10+
)
11+
12+
// Reads file and returns data string for DeepDetect
13+
func readFile(filePath string) string {
14+
f, err := os.Open(filePath)
15+
if err != nil {
16+
logging.Error("Can't open the file.", "["+filepath.Base(filePath)+"]")
17+
os.Exit(1)
18+
}
19+
defer f.Close()
20+
21+
var buf bytes.Buffer
22+
enc := base64.NewEncoder(base64.StdEncoding, &buf)
23+
24+
if _, err := io.Copy(enc, f); err != nil {
25+
logging.Error("Can't read the file.", "["+filepath.Base(filePath)+"]")
26+
os.Exit(1)
27+
}
28+
29+
enc.Close()
30+
return buf.String()
31+
}

0 commit comments

Comments
 (0)