Skip to content

Commit

Permalink
Support selecting Object Detection models (#1359)
Browse files Browse the repository at this point in the history
This PR is for part 1 of #1354. It focuses on adding a model selection
interface for models that exist in `photonvision_config/models/`. Upon
completion we can ship more than 1 model and users could upload their
own through `ssh` without deleting the shipped model. This PR also adds
the abstractions need to support more DNN backends (say OpenCV, or RPI
AI Kit)

Up next is adding a CRUD interface for managing models through the UI.
  • Loading branch information
Alextopher authored Sep 21, 2024
1 parent 24fb6af commit 27cb69c
Show file tree
Hide file tree
Showing 20 changed files with 895 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const validNewPipelineTypes = computed(() => {
{ name: "AprilTag", value: WebsocketPipelineType.AprilTag },
{ name: "Aruco", value: WebsocketPipelineType.Aruco }
];
if (useSettingsStore().general.rknnSupported) {
if (useSettingsStore().general.supportedBackends.length > 0) {
pipelineTypes.push({ name: "Object Detection", value: WebsocketPipelineType.ObjectDetection });
}
return pipelineTypes;
Expand Down Expand Up @@ -170,7 +170,7 @@ const pipelineTypesWrapper = computed<{ name: string; value: number }[]>(() => {
{ name: "AprilTag", value: WebsocketPipelineType.AprilTag },
{ name: "Aruco", value: WebsocketPipelineType.Aruco }
];
if (useSettingsStore().general.rknnSupported) {
if (useSettingsStore().general.supportedBackends.length > 0) {
pipelineTypes.push({ name: "Object Detection", value: WebsocketPipelineType.ObjectDetection });
}
Expand Down
27 changes: 24 additions & 3 deletions photon-client/src/components/dashboard/tabs/ObjectDetectionTab.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<script setup lang="ts">
import { useCameraSettingsStore } from "@/stores/settings/CameraSettingsStore";
import { type ActivePipelineSettings, PipelineType } from "@/types/PipelineTypes";
import { type ObjectDetectionPipelineSettings, PipelineType } from "@/types/PipelineTypes";
import PvSlider from "@/components/common/pv-slider.vue";
import { computed, getCurrentInstance } from "vue";
import { useStateStore } from "@/stores/StateStore";
import { useSettingsStore } from "@/stores/settings/GeneralSettingsStore";
// TODO fix pipeline typing in order to fix this, the store settings call should be able to infer that only valid pipeline type settings are exposed based on pre-checks for the entire config section
// Defer reference to store access method
const currentPipelineSettings = computed<ActivePipelineSettings>(
() => useCameraSettingsStore().currentPipelineSettings
const currentPipelineSettings = computed<ObjectDetectionPipelineSettings>(
() => useCameraSettingsStore().currentPipelineSettings as ObjectDetectionPipelineSettings
);
// TODO fix pv-range-slider so that store access doesn't need to be deferred
Expand All @@ -27,10 +28,30 @@ const interactiveCols = computed(() =>
? 9
: 8
);
// Filters out models that are not supported by the current backend, and returns a flattened list.
const supportedModels = computed(() => {
const { availableModels, supportedBackends } = useSettingsStore().general;
return supportedBackends.flatMap((backend) => availableModels[backend] || []);
});
const selectedModel = computed({
get: () => supportedModels.value.indexOf(currentPipelineSettings.value.model),
set: (v) => {
useCameraSettingsStore().changeCurrentPipelineSetting({ model: supportedModels.value[v] }, false);
}
});
</script>

<template>
<div v-if="currentPipelineSettings.pipelineType === PipelineType.ObjectDetection">
<pv-select
v-model="selectedModel"
label="Model"
tooltip="The model used to detect objects in the camera feed"
:select-cols="interactiveCols"
:items="supportedModels"
/>
<pv-slider
v-model="currentPipelineSettings.confidence"
class="pt-2"
Expand Down
6 changes: 4 additions & 2 deletions photon-client/src/stores/settings/GeneralSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ export const useSettingsStore = defineStore("settings", {
hardwareModel: undefined,
hardwarePlatform: undefined,
mrCalWorking: true,
rknnSupported: false
availableModels: {},
supportedBackends: []
},
network: {
ntServerAddress: "",
Expand Down Expand Up @@ -105,7 +106,8 @@ export const useSettingsStore = defineStore("settings", {
hardwarePlatform: data.general.hardwarePlatform || undefined,
gpuAcceleration: data.general.gpuAcceleration || undefined,
mrCalWorking: data.general.mrCalWorking,
rknnSupported: data.general.rknnSupported
availableModels: data.general.availableModels || undefined,
supportedBackends: data.general.supportedBackends || []
};
this.lighting = data.lighting;
this.network = data.networkSettings;
Expand Down
4 changes: 3 additions & 1 deletion photon-client/src/types/PipelineTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ export interface ObjectDetectionPipelineSettings extends PipelineSettings {
confidence: number;
nms: number;
box_thresh: number;
model: string;
}
export type ConfigurableObjectDetectionPipelineSettings = Partial<
Omit<ObjectDetectionPipelineSettings, "pipelineType">
Expand All @@ -304,7 +305,8 @@ export const DefaultObjectDetectionPipelineSettings: ObjectDetectionPipelineSett
cameraExposureRaw: 6,
confidence: 0.9,
nms: 0.45,
box_thresh: 0.25
box_thresh: 0.25,
model: ""
};

export type ActivePipelineSettings =
Expand Down
3 changes: 2 additions & 1 deletion photon-client/src/types/SettingTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export interface GeneralSettings {
hardwareModel?: string;
hardwarePlatform?: string;
mrCalWorking: boolean;
rknnSupported: boolean;
availableModels: Record<string, string[]>;
supportedBackends: string[];
}

export interface MetricData {
Expand Down
Loading

0 comments on commit 27cb69c

Please sign in to comment.