mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-26 01:51:40 +00:00
Add support for different RKNN YOLO models in the backend (#1205)
This commit is contained in:
@@ -25,12 +25,14 @@ import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import org.photonvision.common.logging.LogGroup;
|
||||
import org.photonvision.common.logging.Logger;
|
||||
import org.photonvision.rknn.RknnJNI;
|
||||
|
||||
public class NeuralNetworkModelManager {
|
||||
private static NeuralNetworkModelManager INSTANCE;
|
||||
private static final Logger logger = new Logger(NeuralNetworkModelManager.class, LogGroup.Config);
|
||||
|
||||
private final String MODEL_NAME = "note-640-640-yolov5s.rknn";
|
||||
private final RknnJNI.ModelVersion modelVersion = RknnJNI.ModelVersion.YOLO_V5;
|
||||
private File defaultModelFile;
|
||||
private List<String> labels;
|
||||
|
||||
@@ -51,7 +53,7 @@ public class NeuralNetworkModelManager {
|
||||
this.defaultModelFile = new File(modelsFolder, MODEL_NAME);
|
||||
extractResource(modelResourcePath, defaultModelFile);
|
||||
|
||||
File labelsFile = new File(modelsFolder, "labels.txt");
|
||||
File labelsFile = new File(modelsFolder, "labels_v5.txt");
|
||||
var labelResourcePath = "/models/" + labelsFile.getName();
|
||||
extractResource(labelResourcePath, labelsFile);
|
||||
|
||||
@@ -95,4 +97,8 @@ public class NeuralNetworkModelManager {
|
||||
public List<String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
|
||||
public RknnJNI.ModelVersion getModelVersion() {
|
||||
return modelVersion;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,12 +65,11 @@ public class RknnDetectorJNI extends PhotonJNICommon {
|
||||
long objPointer = -1;
|
||||
private List<String> labels;
|
||||
private final Object lock = new Object();
|
||||
|
||||
private static final CopyOnWriteArrayList<Long> detectors = new CopyOnWriteArrayList<>();
|
||||
|
||||
public RknnObjectDetector(String modelPath, List<String> labels) {
|
||||
public RknnObjectDetector(String modelPath, List<String> labels, RknnJNI.ModelVersion version) {
|
||||
synchronized (lock) {
|
||||
objPointer = RknnJNI.create(modelPath, labels.size());
|
||||
objPointer = RknnJNI.create(modelPath, labels.size(), version.ordinal(), -1);
|
||||
detectors.add(objPointer);
|
||||
System.out.println(
|
||||
"Created " + objPointer + "! Detectors: " + Arrays.toString(detectors.toArray()));
|
||||
|
||||
@@ -35,7 +35,8 @@ public class RknnDetectionPipe
|
||||
this.detector =
|
||||
new RknnObjectDetector(
|
||||
NeuralNetworkModelManager.getInstance().getDefaultRknnModel().getAbsolutePath(),
|
||||
NeuralNetworkModelManager.getInstance().getLabels());
|
||||
NeuralNetworkModelManager.getInstance().getLabels(),
|
||||
NeuralNetworkModelManager.getInstance().getModelVersion());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user