From d52004ffcc2e0234f6f33648173fb4dbcf74fb9b Mon Sep 17 00:00:00 2001 From: Isacc Barker Date: Sat, 20 Nov 2021 11:51:54 -0700 Subject: [PATCH] basic tensorflow implementation --- .../autonomous/detection/ObjectDetection.java | 34 +++++++++++++++++++ .../sensor/webcam/WebcamPipeline.java | 2 ++ build.dependencies.gradle | 3 ++ 3 files changed, 39 insertions(+) create mode 100644 TeamCode/src/main/java/org/rowlandhall/arc/autonomous/detection/ObjectDetection.java diff --git a/TeamCode/src/main/java/org/rowlandhall/arc/autonomous/detection/ObjectDetection.java b/TeamCode/src/main/java/org/rowlandhall/arc/autonomous/detection/ObjectDetection.java new file mode 100644 index 000000000000..84db9d23f6a7 --- /dev/null +++ b/TeamCode/src/main/java/org/rowlandhall/arc/autonomous/detection/ObjectDetection.java @@ -0,0 +1,34 @@ +package org.rowlandhall.arc.detection; + +import org.tensorflow.lite.Interpreter; + +import java.util.Map; +import java.util.HashMap; +import java.io.File; + +public class ObjectDetection { + Interpreter interpreter; + Map inputs = new HashMap<>(); + Map outputs = new HashMap<>(); + + public ObjectDetection() { + File model = new File("future_model_location.tflite"); + interpreter = new Interpreter(model); + } + + public void run(long[] frame) { + inputs.put("frame", frame); + + // TODO: Figure out what these outputs should be + // TODO: after we train the model. + + interpreter.runSignature(inputs, outputs); + } + + // NOTE: This will be finished after we, again, figure out + // NOTE: what the outputs should be. + /* public UNKNOWN get_detected_boundaries() { + // Query the output map + } */ +} + diff --git a/TeamCode/src/main/java/org/rowlandhall/arc/autonomous/sensor/webcam/WebcamPipeline.java b/TeamCode/src/main/java/org/rowlandhall/arc/autonomous/sensor/webcam/WebcamPipeline.java index 22acca9a6e7a..ff1e1cc29bc9 100644 --- a/TeamCode/src/main/java/org/rowlandhall/arc/autonomous/sensor/webcam/WebcamPipeline.java +++ b/TeamCode/src/main/java/org/rowlandhall/arc/autonomous/sensor/webcam/WebcamPipeline.java @@ -6,6 +6,8 @@ import org.opencv.imgproc.Imgproc; import org.openftc.easyopencv.OpenCvPipeline; +import org.rowlandhall.arc.detection.ObjectDetection; + /** The OpenCV pipeline for the webcam; what all the frames go through * to get processed. */ public class WebcamPipeline extends OpenCvPipeline { diff --git a/build.dependencies.gradle b/build.dependencies.gradle index 57c8c79e3b9e..0bdb41ebb612 100644 --- a/build.dependencies.gradle +++ b/build.dependencies.gradle @@ -24,5 +24,8 @@ dependencies { // Roadrunner dependency implementation 'com.acmerobotics.dashboard:dashboard:0.4.3' + + // Tensorflow lite + implementation 'org.tensorflow:tensorflow-lite:2.7.0' }