Skip to content

Commit

Permalink
RSDK-9058: remove tflite from rdk (#4476)
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaney authored Oct 28, 2024
1 parent adcac21 commit 7167627
Show file tree
Hide file tree
Showing 205 changed files with 132 additions and 15,011 deletions.
1 change: 0 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
brew install x264
brew install jpeg-turbo
brew install ffmpeg
brew install tensorflowlite # Needs to be last
- name: build
run: go build ./web/cmd/server
- uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ jobs:
--platform linux/arm/v7 \
-v `pwd`:/rdk \
ghcr.io/viamrobotics/rdk-devenv:armhf-cache \
sudo -Hu testbot bash -lc 'sudo apt-get install -y python3-venv && cd /rdk && go test -v -tags=no_tflite ./...'
sudo -Hu testbot bash -lc 'sudo apt-get install -y python3-venv && cd /rdk && go test -v ./...'
motion_tests:
name: Test Longer-running Motion Plans if affected
Expand Down
3 changes: 0 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ TAG_VERSION?=$(shell git tag --points-at | sort -Vr | head -n1)
DATE_COMPILED?=$(shell date +'%Y-%m-%d')
COMMON_LDFLAGS = -s -w -X 'go.viam.com/rdk/config.Version=${TAG_VERSION}' -X 'go.viam.com/rdk/config.GitRevision=${GIT_REVISION}' -X 'go.viam.com/rdk/config.DateCompiled=${DATE_COMPILED}'
LDFLAGS = -ldflags "-extld=$(shell pwd)/etc/ld_wrapper.sh $(COMMON_LDFLAGS)"
ifeq ($(shell command -v dpkg >/dev/null && dpkg --print-architecture),armhf)
GOFLAGS += -tags=no_tflite
endif

default: build lint server

Expand Down
1 change: 0 additions & 1 deletion android.make
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ droid-rdk.%.aar: etc/android/prefix/aarch64 etc/android/prefix/x86_64
mkdir -p droidtmp/jni/$(JNI_ARCH)
cp -d etc/android/prefix/$(CPU_ARCH)/lib/*.so* droidtmp/jni/$(JNI_ARCH)
cd droidtmp && zip --symlinks -r ../$@ jni/$(JNI_ARCH)
cd ./services/mlmodel/tflitecpu/android/ && zip --symlinks -r ../../../../$@ jni/$(JNI_ARCH)

droid-rdk.aar: droid-rdk.amd64.aar droid-rdk.arm64.aar
# multi-platform AAR -- twice the size, but portable
Expand Down
29 changes: 6 additions & 23 deletions components/camera/transformpipeline/classifier_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !no_tflite

package transformpipeline

import (
Expand All @@ -17,7 +15,6 @@ import (
"go.viam.com/rdk/rimage"
"go.viam.com/rdk/robot"
robotimpl "go.viam.com/rdk/robot/impl"
"go.viam.com/rdk/services/mlmodel"
_ "go.viam.com/rdk/services/mlmodel/register"
"go.viam.com/rdk/services/vision"
_ "go.viam.com/rdk/services/vision/register"
Expand All @@ -28,25 +25,11 @@ func buildRobotWithClassifier(logger logging.Logger) (robot.Robot, error) {
cfg := &config.Config{}

// create fake source camera
tfliteSrv1 := resource.Config{
Name: "object_classifier",
API: mlmodel.API,
Model: resource.DefaultModelFamily.WithModel("tflite_cpu"),
Attributes: rutils.AttributeMap{
"model_path": artifact.MustPath("vision/classification/object_classifier.tflite"),
"label_path": artifact.MustPath("vision/classification/object_labels.txt"),
"num_threads": 1,
},
}
cfg.Services = append(cfg.Services, tfliteSrv1)
visionSrv1 := resource.Config{
Name: "vision_classifier",
API: vision.API,
Model: resource.DefaultModelFamily.WithModel("mlmodel"),
Attributes: rutils.AttributeMap{
"mlmodel_name": "object_classifier",
},
DependsOn: []string{"object_classifier"},
Name: "vision_classifier",
API: vision.API,
Model: resource.DefaultModelFamily.WithModel("fake"),
Attributes: rutils.AttributeMap{},
}
cfg.Services = append(cfg.Services, visionSrv1)
cameraComp := resource.Config{
Expand Down Expand Up @@ -122,7 +105,7 @@ func TestClassifierSource(t *testing.T) {

// Max classifications was 5, but this image gets classified with just 2 labels, so we
// test that each label is present.
test.That(t, ovImg.GetXY(149, 48), test.ShouldResemble, rimage.Red)
test.That(t, ovImg.GetXY(100, 75), test.ShouldResemble, rimage.Red)
test.That(t, ovImg.GetXY(42, 50), test.ShouldResemble, rimage.Red)
test.That(t, ovImg.GetXY(268, 48), test.ShouldResemble, rimage.Red)
test.That(t, classifier.Close(context.Background()), test.ShouldBeNil)
}
89 changes: 0 additions & 89 deletions components/camera/transformpipeline/detector_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !no_tflite

package transformpipeline

import (
Expand All @@ -18,7 +16,6 @@ import (
"go.viam.com/rdk/rimage"
"go.viam.com/rdk/robot"
robotimpl "go.viam.com/rdk/robot/impl"
"go.viam.com/rdk/services/mlmodel"
_ "go.viam.com/rdk/services/mlmodel/register"
"go.viam.com/rdk/services/vision"
_ "go.viam.com/rdk/services/vision/register"
Expand Down Expand Up @@ -64,27 +61,6 @@ func buildRobotWithFakeCamera(logger logging.Logger) (robot.Robot, error) {
},
}
cfg.Services = append(cfg.Services, colorSrv1)
tfliteSrv2 := resource.Config{
Name: "detector_tflite",
API: mlmodel.API,
Model: resource.DefaultModelFamily.WithModel("tflite_cpu"),
Attributes: rutils.AttributeMap{
"model_path": artifact.MustPath("vision/tflite/effdet0.tflite"),
"label_path": artifact.MustPath("vision/tflite/effdetlabels.txt"),
"num_threads": 1,
},
}
cfg.Services = append(cfg.Services, tfliteSrv2)
visionSrv2 := resource.Config{
Name: "vision_detector",
API: vision.API,
Model: resource.DefaultModelFamily.WithModel("mlmodel"),
Attributes: rutils.AttributeMap{
"mlmodel_name": "detector_tflite",
},
DependsOn: []string{"detector_tflite"},
}
cfg.Services = append(cfg.Services, visionSrv2)
cameraComp := resource.Config{
Name: "fake_cam",
API: camera.API,
Expand Down Expand Up @@ -115,26 +91,6 @@ func buildRobotWithFakeCamera(logger logging.Logger) (robot.Robot, error) {
DependsOn: []string{"fake_cam"},
}
cfg.Components = append(cfg.Components, detectorComp)
// create 2nd fake detector camera
tfliteComp := resource.Config{
Name: "tflite_detect",
API: camera.API,
Model: resource.DefaultModelFamily.WithModel("transform"),
Attributes: rutils.AttributeMap{
"source": "fake_cam",
"pipeline": []rutils.AttributeMap{
{
"type": "detections",
"attributes": rutils.AttributeMap{
"detector_name": "vision_detector",
"confidence_threshold": 0.35,
},
},
},
},
DependsOn: []string{"fake_cam"},
}
cfg.Components = append(cfg.Components, tfliteComp)
if err := cfg.Ensure(false, logger); err != nil {
return nil, err
}
Expand Down Expand Up @@ -173,29 +129,6 @@ func TestColorDetectionSource(t *testing.T) {
test.That(t, detector.Close(context.Background()), test.ShouldBeNil)
}

func TestTFLiteDetectionSource(t *testing.T) {
logger := logging.NewTestLogger(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

r, err := buildRobotWithFakeCamera(logger)
defer func() {
test.That(t, r.Close(context.Background()), test.ShouldBeNil)
}()
test.That(t, err, test.ShouldBeNil)

detector, err := camera.FromRobot(r, "tflite_detect")
test.That(t, err, test.ShouldBeNil)
defer detector.Close(ctx)

resImg, _, err := camera.ReadImage(ctx, detector)
test.That(t, err, test.ShouldBeNil)
ovImg := rimage.ConvertImage(resImg)
test.That(t, ovImg.GetXY(624, 402), test.ShouldResemble, rimage.Red)
test.That(t, ovImg.GetXY(815, 647), test.ShouldResemble, rimage.Red)
test.That(t, detector.Close(context.Background()), test.ShouldBeNil)
}

func BenchmarkColorDetectionSource(b *testing.B) {
logger := logging.NewTestLogger(b)
ctx, cancel := context.WithCancel(context.Background())
Expand All @@ -217,25 +150,3 @@ func BenchmarkColorDetectionSource(b *testing.B) {
}
test.That(b, detector.Close(context.Background()), test.ShouldBeNil)
}

func BenchmarkTFLiteDetectionSource(b *testing.B) {
logger := logging.NewTestLogger(b)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

r, err := buildRobotWithFakeCamera(logger)
defer func() {
test.That(b, r.Close(context.Background()), test.ShouldBeNil)
}()
test.That(b, err, test.ShouldBeNil)
detector, err := camera.FromRobot(r, "tflite_detect")
test.That(b, err, test.ShouldBeNil)
defer detector.Close(ctx)

b.ResetTimer()
// begin benchmarking
for i := 0; i < b.N; i++ {
_, _, _ = camera.ReadImage(ctx, detector)
}
test.That(b, detector.Close(context.Background()), test.ShouldBeNil)
}
4 changes: 0 additions & 4 deletions etc/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ run:
deadline: 900s
modules-download-mode: readonly
skip-dirs-use-default: false
skip-dirs:
# TFlite uses FlatBuffer generated code that's ugly
- ml/inference/tflite_metadata$
- ml/inference/tflite$
tests: true
linters:
enable-all: true
Expand Down
2 changes: 1 addition & 1 deletion etc/Dockerfile.cache
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM $MAIN_TAG:$BASE_TAG as builder
COPY --chown=1000:1000 ./ /tmp/rdk
WORKDIR /tmp/rdk
RUN --mount=type=secret,id=netrc,uid=1000,dst=/home/testbot/.netrc sudo -Hu testbot bash -lc 'if [ `dpkg --print-architecture` = armhf ]; then \
GOFLAGS=-tags=no_tflite make build-go tool-install; \
make build-go tool-install; \
else \
make build-go lint-go; \
fi'
Expand Down
38 changes: 0 additions & 38 deletions etc/android/build-tflite.sh

This file was deleted.

35 changes: 0 additions & 35 deletions etc/android/tflite.patch

This file was deleted.

2 changes: 1 addition & 1 deletion etc/ld_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fi
STRIPPED_ARGS="-g -O2"

# list of arguments to prefix with -Bstatic
STATIC_ARGS="-lx264 -lnlopt -ltensorflowlite_c -lstdc++"
STATIC_ARGS="-lx264 -lnlopt -lstdc++"

# add explicit static standard library flags
FILTERED=("-static-libgcc" "-static-libstdc++")
Expand Down
3 changes: 1 addition & 2 deletions etc/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ do_piOS(){
echo "deb [signed-by=/usr/share/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x $(grep VERSION_CODENAME /etc/os-release | cut -d= -f2) main" > /etc/apt/sources.list.d/nodesource.list
# Install most things
apt-get update && apt-get install -y build-essential nodejs libnlopt-dev libx264-dev libtensorflowlite-dev ffmpeg libjpeg62-turbo-dev
apt-get update && apt-get install -y build-essential nodejs libnlopt-dev libx264-dev ffmpeg libjpeg62-turbo-dev
# Install Gostream dependencies
sudo apt-get install -y --no-install-recommends libopus-dev libx11-dev libxext-dev libopusfile-dev
Expand Down Expand Up @@ -170,7 +170,6 @@ do_brew(){
brew "licensefinder"
brew "opus"
brew "opusfile"
brew "tensorflowlite" # Needs to be last
EOS

if [ $? -ne 0 ]; then
Expand Down
2 changes: 1 addition & 1 deletion etc/subsystem_manifest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Sample manifest:
},
{
"api": "rdk:service:ml_model",
"model": "rdk:builtin:tflitecpu"
"model": "rdk:builtin:fake"
"attribute_schema": {
"..."
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !no_tflite

// Package main tests out all four custom models in the complexmodule.
package main_test

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !no_tflite

// Package main tests out all the custom models in the multiplemodules.
package main_test

Expand Down
2 changes: 0 additions & 2 deletions examples/customresources/demos/remoteserver/server_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build !no_tflite

package main_test

import (
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ require (
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551
github.com/golang/protobuf v1.5.4
github.com/golangci/golangci-lint v1.61.0
github.com/google/flatbuffers v2.0.6+incompatible
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
Expand All @@ -58,7 +57,6 @@ require (
github.com/lestrrat-go/jwx v1.2.29
github.com/lmittmann/ppm v1.0.2
github.com/lucasb-eyer/go-colorful v1.2.0
github.com/mattn/go-tflite v1.0.4
github.com/matttproud/golang_protobuf_extensions v1.0.4
github.com/mkch/gpio v0.0.0-20190919032813-8327cd97d95e
github.com/montanaflynn/stats v0.7.0
Expand Down Expand Up @@ -246,6 +244,7 @@ require (
github.com/golangci/revgrep v0.5.3 // indirect
github.com/golangci/unconvert v0.0.0-20240309020433-c5143eacb3ed // indirect
github.com/gonuts/binary v0.2.0 // indirect
github.com/google/flatbuffers v2.0.6+incompatible // indirect
github.com/google/go-containerregistry v0.15.2 // indirect
github.com/google/pprof v0.0.0-20240827171923-fa2c70bbbfe5 // indirect
github.com/google/s2a-go v0.1.8 // indirect
Expand Down Expand Up @@ -300,7 +299,6 @@ require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-pointer v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/mgechev/revive v1.3.9 // indirect
github.com/miekg/dns v1.1.53 // indirect
Expand Down
Loading

0 comments on commit 7167627

Please sign in to comment.