refactor: convert input/output to uint8
This commit is contained in:
parent
ce58df8a6d
commit
ba9e54d1fb
@ -192,13 +192,13 @@ func (p *Part) Value(img image.Image) (float32, float32, error) {
|
||||
dx = img.Bounds().Dx()
|
||||
dy = img.Bounds().Dy()
|
||||
|
||||
bb := make([]byte, dx*dy*3)
|
||||
bb := make([]uint8, dx*dy*3)
|
||||
for y := 0; y < dy; y++ {
|
||||
for x := 0; x < dx; x++ {
|
||||
r, g, b, _ := img.At(x, y).RGBA()
|
||||
bb[(y*dx+x)*3+0] = byte(float64(r) / 257.0)
|
||||
bb[(y*dx+x)*3+1] = byte(float64(g) / 257.0)
|
||||
bb[(y*dx+x)*3+2] = byte(float64(b) / 257.0)
|
||||
bb[(y*dx+x)*3+0] = uint8(float64(r) / 257.0)
|
||||
bb[(y*dx+x)*3+1] = uint8(float64(g) / 257.0)
|
||||
bb[(y*dx+x)*3+2] = uint8(float64(b) / 257.0)
|
||||
}
|
||||
}
|
||||
status = input.CopyFromBuffer(bb)
|
||||
@ -211,8 +211,8 @@ func (p *Part) Value(img image.Image) (float32, float32, error) {
|
||||
return 0., 0., fmt.Errorf("invoke failed: %v", status)
|
||||
}
|
||||
|
||||
output := p.interpreter.GetOutputTensor(0).Int8s()
|
||||
zap.L().Debug("raw steering", zap.Int8s("result", output))
|
||||
output := p.interpreter.GetOutputTensor(0).UInt8s()
|
||||
zap.L().Debug("raw steering", zap.Uint8s("result", output))
|
||||
|
||||
//outputSize := output.Dim(output.NumDims() - 1)
|
||||
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
// LinearBin perform inverse linear_bin, taking
|
||||
func LinearBin(arr []int8, n int, offset int, r float64) (float64, float64) {
|
||||
func LinearBin(arr []uint8, n int, offset int, r float64) (float64, float64) {
|
||||
outputSize := len(arr)
|
||||
type result struct {
|
||||
score float64
|
||||
@ -17,7 +17,7 @@ func LinearBin(arr []int8, n int, offset int, r float64) (float64, float64) {
|
||||
var results []result
|
||||
minScore := 0.2
|
||||
for i := 0; i < outputSize; i++ {
|
||||
score := float64(int(arr[i])+128) / 255.0
|
||||
score := float64(int(arr[i])) / 255.0
|
||||
if score < minScore {
|
||||
continue
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user