Add support for object detection on Rubik Pi 3 (#2005)

This commit is contained in:
Sam Freund
2025-08-09 10:02:55 -05:00
committed by GitHub
parent e23df8c9a4
commit 9277960018
26 changed files with 545 additions and 70 deletions

View File

@@ -40,6 +40,7 @@ import org.photonvision.common.networking.NetworkManager;
import org.photonvision.common.util.TestUtils;
import org.photonvision.jni.PhotonTargetingJniLoader;
import org.photonvision.jni.RknnDetectorJNI;
import org.photonvision.jni.RubikDetectorJNI;
import org.photonvision.mrcal.MrCalJNILoader;
import org.photonvision.raspi.LibCameraJNILoader;
import org.photonvision.server.Server;
@@ -231,12 +232,31 @@ public class Main {
try {
if (Platform.isRK3588()) {
RknnDetectorJNI.forceLoad();
if (RknnDetectorJNI.getInstance().isLoaded()) {
logger.info("RknnDetectorJNI loaded successfully.");
} else {
logger.error("Failed to load RknnDetectorJNI!");
}
} else {
logger.error("Platform does not support RKNN based machine learning!");
}
} catch (IOException e) {
logger.error("Failed to load rknn-JNI!", e);
}
try {
if (Platform.isQCS6490()) {
RubikDetectorJNI.forceLoad();
if (RubikDetectorJNI.getInstance().isLoaded()) {
logger.info("RubikDetectorJNI loaded successfully.");
} else {
logger.error("Failed to load RubikDetectorJNI!");
}
} else {
logger.error("Platform does not support Rubik based machine learning!");
}
} catch (IOException e) {
logger.error("Failed to load rubik-JNI!", e);
}
try {
MrCalJNILoader.forceLoad();
} catch (IOException e) {

View File

@@ -605,13 +605,40 @@ public class RequestHandler {
return;
}
String modelFileExtension = "";
NeuralNetworkModelManager.Family family;
switch (Platform.getCurrentPlatform()) {
case LINUX_QCS6490:
modelFileExtension = "tflite";
family = NeuralNetworkModelManager.Family.RUBIK;
break;
case LINUX_RK3588_64:
modelFileExtension = "rknn";
family = NeuralNetworkModelManager.Family.RKNN;
break;
default:
ctx.status(400);
ctx.result("The current platform does not support object detection models");
logger.error("The current platform does not support object detection models");
return;
}
// If adding additional platforms, check platform matches
if (!modelFile.extension().contains("rknn")) {
if (!modelFile.extension().contains(modelFileExtension)) {
ctx.status(400);
ctx.result(
"The uploaded file was not of type 'rknn'. The uploaded file should be a .rknn file.");
"The uploaded file was not of type '"
+ modelFileExtension
+ "'. The uploaded file should be a ."
+ modelFileExtension
+ " file.");
logger.error(
"The uploaded file was not of type 'rknn'. The uploaded file should be a .rknn file.");
"The uploaded file was not of type '"
+ modelFileExtension
+ "'. The uploaded file should be a ."
+ modelFileExtension
+ " file.");
return;
}
@@ -638,13 +665,11 @@ public class RequestHandler {
.addModelProperties(
new ModelProperties(
modelPath,
modelFile.filename().replaceAll(".rknn", ""),
modelFile.filename().replaceAll("." + modelFileExtension, ""),
labels,
width,
height,
NeuralNetworkModelManager.Family.RKNN, // This can be determined by platform if
// additional platforms are
// supported
family,
version));
logger.debug(