Worked on Custom tensor flow model and had programmed it and had found that it would always be over 75% sure that there was always a steve even if the cone was out of frame and it would occasionally look and find that there was the team banner image from the website. but then i tested it with the pre programmed tensors and it could easily figure out which image was being shown. must train the computer better with different images as well that are even more distinctable. but i succesfully trained it something and implemented it, so partial success

This commit is contained in:
SpencerPiha
2022-10-09 17:08:44 -05:00
parent cf89b53e90
commit 100b06610c
8 changed files with 103 additions and 5 deletions

View File

@@ -21,6 +21,14 @@ android {
targetCompatibility JavaVersion.VERSION_1_7
}
namespace = 'com.qualcomm.ftcrobotcontroller'
buildFeatures {
mlModelBinding true
}
}
dependencies {
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
}
apply from: '../build.dependencies.gradle'

View File

@@ -50,7 +50,7 @@ import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
* is explained below.
*/
@TeleOp(name = "Concept: TensorFlow Object Detection Webcam", group = "Concept")
@Disabled
//@Disabled
public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
/*
@@ -60,8 +60,10 @@ public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
* has been downloaded to the Robot Controller's SD FLASH memory, it must to be loaded using loadModelFromFile()
* Here we assume it's an Asset. Also see method initTfod() below .
*/
// private static final String TFOD_MODEL_ASSET = "model_20221009_154335.tflite";
private static final String TFOD_MODEL_ASSET = "PowerPlay.tflite";
// private static final String TFOD_MODEL_FILE = "/sdcard/FIRST/tflitemodels/CustomTeamModel.tflite";
// private static final String TFOD_MODEL_FILE = "/sdcard/FIRST/tflitemodels/CustomTeamModel.tflite";
private static final String[] LABELS = {
@@ -83,7 +85,7 @@ public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
* and paste it in to your code on the next line, between the double quotes.
*/
private static final String VUFORIA_KEY =
" -- YOUR NEW VUFORIA KEY GOES HERE --- ";
"Abmu1jv/////AAABmYzrcgDEi014nv+wD6PkEPVnOlV2pI3S9sGUMMR/X7hF72x20rP1JcVtsU0nI6VK0yUlYbCSA2k+yMo4hQmPDBvrqeqAgXKa57ilPhW5e1cB3BEevP+9VoJ9QYFhKA3JJTiuFS50WQeuFy3dp0gOPoqHL3XClRFZWbhzihyNnLXgXlKiq+i5GbfONECucQU2DgiuuxYlCaeNdUHl1X5C2pO80zZ6y7PYAp3p0ciXJxqfBoVAklhd69avaAE5Z84ctKscvcbxCS16lq81X7XgIFjshLoD/vpWa300llDG83+Y777q7b5v7gsUCZ6FiuK152Rd272HLuBRhoTXAt0ug9Baq5cz3sn0sAIEzSHX1nah";
/**
* {@link #vuforia} is the variable we will use to store our instance of the Vuforia
@@ -185,6 +187,6 @@ public class ConceptTensorFlowObjectDetectionWebcam extends LinearOpMode {
// Use loadModelFromAsset() if the TF Model is built in as an asset by Android Studio
// Use loadModelFromFile() if you have downloaded a custom team model to the Robot Controller's FLASH.
tfod.loadModelFromAsset(TFOD_MODEL_ASSET, LABELS);
// tfod.loadModelFromFile(TFOD_MODEL_FILE, LABELS);
// tfod.loadModelFromFile(TFOD_MODEL_FILE, LABELS);
}
}

View File

@@ -17,9 +17,14 @@ apply from: '../build.dependencies.gradle'
android {
namespace = 'org.firstinspires.ftc.teamcode'
buildFeatures {
mlModelBinding true
}
}
dependencies {
implementation project(':FtcRobotController')
implementation 'org.tensorflow:tensorflow-lite-metadata:0.1.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.3.0'
annotationProcessor files('lib/OpModeAnnotationProcessor.jar')
}

View File

@@ -0,0 +1,11 @@
package org.timecrafters.testing.engine;
import org.cyberarm.engine.V2.CyberarmEngine;
public class CameraTestEngine extends CyberarmEngine {
@Override
public void setup() {
}
}

View File

@@ -0,0 +1,59 @@
package org.timecrafters.testing.states;
import org.cyberarm.engine.V2.CyberarmEngine;
import org.firstinspires.ftc.robotcore.external.tfod.Recognition;
import org.firstinspires.ftc.robotcore.external.tfod.TFObjectDetector;
import java.util.ArrayList;
import java.util.List;
public class CameraTestCommon {
private static final String TENSORFLOW_MODEL_ASSET = "";
private static final String[] TENSORFLOW_MODEL_LABELS = {
"1 dalek",
"2 steve",
"3 banner"
};
public TFObjectDetector tensorflow;
private List<Recognition> tensorflowRecognitions = new ArrayList<>();
private final CyberarmEngine engine;
public CameraTestCommon(CyberarmEngine engine) {
this.engine = engine;
initTensorflow();
}
private void initTensorflow() {
int tfodMonitorViewId = engine.hardwareMap.appContext.getResources().getIdentifier(
"tfodMonitorViewId", "id", engine.hardwareMap.appContext.getPackageName());
TFObjectDetector.Parameters parameters = new TFObjectDetector.Parameters(tfodMonitorViewId);
parameters.minResultConfidence = 0.8f;
parameters.isModelTensorFlow2 = true;
parameters.inputSize = 320;
tensorflow.loadModelFromAsset(TENSORFLOW_MODEL_ASSET, TENSORFLOW_MODEL_LABELS);
}
public void activateTensorflow() {
tensorflow.activate();
}
public List<Recognition> tensorflowDetections() {
List<Recognition> updateRecognitions = tensorflow.getUpdatedRecognitions();
if (updateRecognitions != null) {
tensorflowRecognitions = updateRecognitions;
}
return tensorflowRecognitions;
}
public void deactivateTensorflow() {
tensorflow.deactivate();
}
}

View File

@@ -0,0 +1,13 @@
package org.timecrafters.testing.states;
import org.cyberarm.engine.V2.CyberarmState;
public class CameraTestState extends CyberarmState {
@Override
public void exec() {
}
}

View File

@@ -10,7 +10,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.0'
classpath 'com.android.tools.build:gradle:7.2.2'
}
}