mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-19 00:41:41 +00:00
Preload OD models before import to check quantization (#2056)
Co-authored-by: samfreund <samf.236@proton.me> Co-authored-by: Sam Freund <techguy763@gmail.com>
This commit is contained in:
@@ -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";
|
||||
|
||||
|
||||
@@ -74,6 +74,8 @@ public class RknnObjectDetector implements ObjectDetector {
|
||||
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());
|
||||
|
||||
@@ -80,6 +80,8 @@ public class RubikObjectDetector implements ObjectDetector {
|
||||
+ ". 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());
|
||||
|
||||
@@ -58,6 +58,9 @@ import org.photonvision.common.util.file.ProgramDirectoryUtilities;
|
||||
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;
|
||||
|
||||
@@ -656,18 +659,49 @@ public class RequestHandler {
|
||||
modelFile.content().transferTo(out);
|
||||
}
|
||||
|
||||
ModelProperties modelProperties =
|
||||
new ModelProperties(
|
||||
modelPath,
|
||||
modelFile.filename().replaceAll("." + family.extension(), ""),
|
||||
labels,
|
||||
width,
|
||||
height,
|
||||
family,
|
||||
version);
|
||||
|
||||
ObjectDetector objDetector = null;
|
||||
|
||||
try {
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user