From ba9e54d1fba210a2fb24524b979dfe1dfb70e26a Mon Sep 17 00:00:00 2001 From: Cyrille Nofficial Date: Fri, 31 Dec 2021 19:36:35 +0100 Subject: [PATCH] refactor: convert input/output to uint8 --- pkg/steering/steering.go | 12 ++++++------ pkg/tools/tools.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/steering/steering.go b/pkg/steering/steering.go index b107e13..13474a8 100644 --- a/pkg/steering/steering.go +++ b/pkg/steering/steering.go @@ -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) diff --git a/pkg/tools/tools.go b/pkg/tools/tools.go index 9f139c6..43e9693 100644 --- a/pkg/tools/tools.go +++ b/pkg/tools/tools.go @@ -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 }