Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ ext {
openCVversion = "4.10.0-3"
javalinVersion = "5.6.2"
libcameraDriverVersion = "v2025.0.3"
rknnVersion = "dev-v2025.0.0-1-g33b6263"
rubikVersion = "v2025.1.0"
rknnVersion = "dev-v2025.0.0-5-g666c0c6"
rubikVersion = "dev-v2025.1.0-8-g067a316"
frcYear = "2025"
mrcalVersion = "v2025.0.0";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public RknnObjectDetector(RknnModel model, Size inputSize) {
if (objPointer <= 0) {
throw new RuntimeException(
"Failed to create detector from path " + model.modelFile.getPath());
} else if (!RknnJNI.isQuantized(objPointer)) {
throw new UnsupportedOperationException("Model must be quantized.");
}

logger.debug("Created detector for model " + model.modelFile.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public RubikObjectDetector(RubikModel model, Size inputSize) {
+ ". Please ensure the model is valid and compatible with the Rubik backend.");
throw new RuntimeException(
"Failed to create detector from path " + model.modelFile.getPath());
} else if (!RubikJNI.isQuantized(ptr)) {
throw new UnsupportedOperationException("Model must be quantized.");
}

logger.debug("Created detector for model " + model.modelFile.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
import org.photonvision.vision.camera.CameraQuirk;
import org.photonvision.vision.camera.PVCameraInfo;
import org.photonvision.vision.objects.ObjectDetector;
import org.photonvision.vision.objects.RknnModel;
import org.photonvision.vision.objects.RubikModel;
import org.photonvision.vision.processes.VisionSourceManager;
import org.zeroturnaround.zip.ZipUtil;

Expand Down Expand Up @@ -656,18 +659,49 @@ public static void onImportObjectDetectionModelRequest(Context ctx) {
modelFile.content().transferTo(out);
}

ModelProperties modelProperties =
new ModelProperties(
modelPath,
modelFile.filename().replaceAll("." + family.extension(), ""),
labels,
width,
ObjectDetector objDetector = null;

try {
height,
family,
version);

objDetector =
switch (family) {
case RUBIK -> new RubikModel(modelProperties).load();
case RKNN -> new RknnModel(modelProperties).load();
};
} catch (RuntimeException e) {
ctx.status(400);
ctx.result("Failed to load object detection model: " + e.getMessage());

try {
Files.deleteIfExists(modelPath);
} catch (IOException ex) {
e.addSuppressed(ex);
}

logger.error("Failed to load object detection model", e);
return;
} finally {
// this finally block will run regardless of what happens in try/catch
// please see https://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html
// for a summary on how finally works
if (objDetector != null) {
objDetector.release();
}
}

ConfigManager.getInstance()
.getConfig()
.neuralNetworkPropertyManager()
.addModelProperties(
new ModelProperties(
modelPath,
modelFile.filename().replaceAll("." + family.extension(), ""),
labels,
width,
height,
family,
version));
.addModelProperties(modelProperties);

logger.debug(
ConfigManager.getInstance().getConfig().neuralNetworkPropertyManager().toString());
Expand Down
Loading