Skip to content

Commit c7f5edc

Browse files
authored
Exclude license from being loaded as a model (#2063)
1 parent 6fe9631 commit c7f5edc

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,18 @@ public static NeuralNetworkModelManager getInstance() {
226226
private static final Logger logger = new Logger(NeuralNetworkModelManager.class, LogGroup.Config);
227227

228228
public enum Family {
229-
RKNN,
230-
RUBIK
229+
RKNN(".rknn"),
230+
RUBIK(".tflite");
231+
232+
private final String fileExtension;
233+
234+
private Family(String fileExtension) {
235+
this.fileExtension = fileExtension;
236+
}
237+
238+
public String extension() {
239+
return fileExtension;
240+
}
231241
}
232242

233243
public enum Version {
@@ -358,7 +368,11 @@ public void discoverModels() {
358368
try {
359369
Files.walk(modelsDirectory.toPath())
360370
.filter(Files::isRegularFile)
361-
.forEach(path -> loadModel(path));
371+
.filter(
372+
path ->
373+
supportedBackends.stream()
374+
.anyMatch(family -> path.toString().endsWith(family.extension())))
375+
.forEach(this::loadModel);
362376
} catch (IOException e) {
363377
logger.error("Failed to discover models at " + modelsDirectory.getAbsolutePath(), e);
364378
}

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -605,16 +605,13 @@ public static void onImportObjectDetectionModelRequest(Context ctx) {
605605
return;
606606
}
607607

608-
String modelFileExtension = "";
609608
NeuralNetworkModelManager.Family family;
610609

611610
switch (Platform.getCurrentPlatform()) {
612611
case LINUX_QCS6490:
613-
modelFileExtension = "tflite";
614612
family = NeuralNetworkModelManager.Family.RUBIK;
615613
break;
616614
case LINUX_RK3588_64:
617-
modelFileExtension = "rknn";
618615
family = NeuralNetworkModelManager.Family.RKNN;
619616
break;
620617
default:
@@ -625,19 +622,19 @@ public static void onImportObjectDetectionModelRequest(Context ctx) {
625622
}
626623

627624
// If adding additional platforms, check platform matches
628-
if (!modelFile.extension().contains(modelFileExtension)) {
625+
if (!modelFile.extension().contains(family.extension())) {
629626
ctx.status(400);
630627
ctx.result(
631628
"The uploaded file was not of type '"
632-
+ modelFileExtension
629+
+ family.extension()
633630
+ "'. The uploaded file should be a ."
634-
+ modelFileExtension
631+
+ family.extension()
635632
+ " file.");
636633
logger.error(
637634
"The uploaded file was not of type '"
638-
+ modelFileExtension
635+
+ family.extension()
639636
+ "'. The uploaded file should be a ."
640-
+ modelFileExtension
637+
+ family.extension()
641638
+ " file.");
642639
return;
643640
}
@@ -665,7 +662,7 @@ public static void onImportObjectDetectionModelRequest(Context ctx) {
665662
.addModelProperties(
666663
new ModelProperties(
667664
modelPath,
668-
modelFile.filename().replaceAll("." + modelFileExtension, ""),
665+
modelFile.filename().replaceAll("." + family.extension(), ""),
669666
labels,
670667
width,
671668
height,

0 commit comments

Comments
 (0)