Skip to content

Commit 1639334

Browse files
committed
move quantization check to constructor
1 parent 071db4c commit 1639334

4 files changed

Lines changed: 5 additions & 25 deletions

File tree

photon-core/src/main/java/org/photonvision/vision/objects/ObjectDetector.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,4 @@ public interface ObjectDetector extends Releasable {
5757
* empty list if the detector is not initialized or if no objects are detected.
5858
*/
5959
public List<NeuralNetworkPipeResult> detect(Mat in, double nmsThresh, double boxThresh);
60-
61-
/**
62-
* Checks if the model is quantized
63-
*
64-
* @return true if the model is quantized, false if not
65-
*/
66-
public boolean isQuantized();
6760
}

photon-core/src/main/java/org/photonvision/vision/objects/RknnObjectDetector.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public RknnObjectDetector(RknnModel model, Size inputSize) {
7474
if (objPointer <= 0) {
7575
throw new RuntimeException(
7676
"Failed to create detector from path " + model.modelFile.getPath());
77+
} else if (!RknnJNI.isQuantized(objPointer)) {
78+
throw new UnsupportedOperationException("Model must be quantized.");
7779
}
7880

7981
logger.debug("Created detector for model " + model.modelFile.getName());
@@ -133,11 +135,6 @@ public List<NeuralNetworkPipeResult> detect(Mat in, double nmsThresh, double box
133135
.toList());
134136
}
135137

136-
@Override
137-
public boolean isQuantized() {
138-
return RknnJNI.isQuantized(objPointer);
139-
}
140-
141138
/** Thread-safe method to release the detector. */
142139
@Override
143140
public void release() {

photon-core/src/main/java/org/photonvision/vision/objects/RubikObjectDetector.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public RubikObjectDetector(RubikModel model, Size inputSize) {
8080
+ ". Please ensure the model is valid and compatible with the Rubik backend.");
8181
throw new RuntimeException(
8282
"Failed to create detector from path " + model.modelFile.getPath());
83+
} else if (!RubikJNI.isQuantized(ptr)) {
84+
throw new UnsupportedOperationException("Model must be quantized.");
8385
}
8486

8587
logger.debug("Created detector for model " + model.modelFile.getName());
@@ -140,12 +142,6 @@ public List<NeuralNetworkPipeResult> detect(Mat in, double nmsThresh, double box
140142
.toList());
141143
}
142144

143-
// TODO: replace with actual quantization check
144-
@Override
145-
public boolean isQuantized() {
146-
return true;
147-
}
148-
149145
/** Thread-safe method to release the detector. */
150146
@Override
151147
public void release() {

photon-server/src/main/java/org/photonvision/server/RequestHandler.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -680,13 +680,7 @@ public static void onImportObjectDetectionModelRequest(Context ctx) {
680680
case RUBIK -> new RubikModel(modelProperties).load();
681681
case RKNN -> new RknnModel(modelProperties).load();
682682
};
683-
684-
if (!objDetector.isQuantized()) {
685-
ctx.status(400);
686-
ctx.result("Failed to load object detection model: model must be quantized!");
687-
return;
688-
}
689-
} catch (Exception e) {
683+
} catch (RuntimeException e) {
690684
ctx.status(400);
691685
ctx.result("Failed to load object detection model: " + e.getMessage());
692686
logger.error("Failed to load object detection model", e);

0 commit comments

Comments
 (0)