|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref, computed } from "vue"; |
| 3 | +import axios from "axios"; |
| 4 | +import { useStateStore } from "@/stores/StateStore"; |
| 5 | +import { useSettingsStore } from "@/stores/settings/GeneralSettingsStore"; |
| 6 | +
|
| 7 | +const showObjectDetectionImportDialog = ref(false); |
| 8 | +const importRKNNFile = ref<File | null>(null); |
| 9 | +const importLabelsFile = ref<File | null>(null); |
| 10 | +
|
| 11 | +const handleObjectDetectionImport = () => { |
| 12 | + if (importRKNNFile.value === null || importLabelsFile.value === null) return; |
| 13 | +
|
| 14 | + const formData = new FormData(); |
| 15 | + formData.append("rknn", importRKNNFile.value); |
| 16 | + formData.append("labels", importLabelsFile.value); |
| 17 | +
|
| 18 | + useStateStore().showSnackbarMessage({ |
| 19 | + message: "Importing Object Detection Model...", |
| 20 | + color: "secondary", |
| 21 | + timeout: -1 |
| 22 | + }); |
| 23 | +
|
| 24 | + axios |
| 25 | + .post("/utils/importObjectDetectionModel", formData, { |
| 26 | + headers: { "Content-Type": "multipart/form-data" } |
| 27 | + }) |
| 28 | + .then((response) => { |
| 29 | + useStateStore().showSnackbarMessage({ |
| 30 | + message: response.data.text || response.data, |
| 31 | + color: "success" |
| 32 | + }); |
| 33 | + }) |
| 34 | + .catch((error) => { |
| 35 | + if (error.response) { |
| 36 | + useStateStore().showSnackbarMessage({ |
| 37 | + color: "error", |
| 38 | + message: error.response.data.text || error.response.data |
| 39 | + }); |
| 40 | + } else if (error.request) { |
| 41 | + useStateStore().showSnackbarMessage({ |
| 42 | + color: "error", |
| 43 | + message: "Error while trying to process the request! The backend didn't respond." |
| 44 | + }); |
| 45 | + } else { |
| 46 | + useStateStore().showSnackbarMessage({ |
| 47 | + color: "error", |
| 48 | + message: "An error occurred while trying to process the request." |
| 49 | + }); |
| 50 | + } |
| 51 | + }); |
| 52 | +
|
| 53 | + showObjectDetectionImportDialog.value = false; |
| 54 | + importRKNNFile.value = null; |
| 55 | + importLabelsFile.value = null; |
| 56 | +}; |
| 57 | +
|
| 58 | +// Filters out models that are not supported by the current backend, and returns a flattened list. |
| 59 | +const supportedModels = computed(() => { |
| 60 | + const { availableModels, supportedBackends } = useSettingsStore().general; |
| 61 | + return supportedBackends.flatMap((backend) => availableModels[backend] || []); |
| 62 | +}); |
| 63 | +</script> |
| 64 | + |
| 65 | +<template> |
| 66 | + <v-card dark class="mb-3" style="background-color: #006492"> |
| 67 | + <v-card-title class="pa-6">Object Detection</v-card-title> |
| 68 | + <div class="pa-6 pt-0"> |
| 69 | + <v-row> |
| 70 | + <v-col cols="12 "> |
| 71 | + <v-btn color="secondary" @click="() => (showObjectDetectionImportDialog = true)" class="justify-center"> |
| 72 | + <v-icon left class="open-icon"> mdi-import </v-icon> |
| 73 | + <span class="open-label">Import New Model</span> |
| 74 | + </v-btn> |
| 75 | + <v-dialog |
| 76 | + v-model="showObjectDetectionImportDialog" |
| 77 | + width="600" |
| 78 | + @input=" |
| 79 | + () => { |
| 80 | + importRKNNFile = null; |
| 81 | + importLabelsFile = null; |
| 82 | + } |
| 83 | + " |
| 84 | + > |
| 85 | + <v-card color="primary" dark> |
| 86 | + <v-card-title>Import New Object Detection Model</v-card-title> |
| 87 | + <v-card-text> |
| 88 | + Upload a new object detection model to this device that can be used in a pipeline. Naming convention |
| 89 | + should be <code>name-verticalResolution-horizontalResolution-modelType</code>. Additionally, the labels |
| 90 | + file ought to have the same name as the RKNN file, with <code>-labels</code> appended to the end. For |
| 91 | + example, if the RKNN file is named <code>note-640-640-yolov5s.rknn</code>, the labels file should be |
| 92 | + named <code>note-640-640-yolov5s-labels.txt</code>. Note that ONLY 640x640 YOLOv5 & YOLOv8 models |
| 93 | + trained and converted to `.rknn` format for RK3588 CPUs are currently supported! |
| 94 | + <v-row class="mt-6 ml-4 mr-8"> |
| 95 | + <v-file-input label="RKNN File" v-model="importRKNNFile" accept=".rknn" /> |
| 96 | + </v-row> |
| 97 | + <v-row class="mt-6 ml-4 mr-8"> |
| 98 | + <v-file-input label="Labels File" v-model="importLabelsFile" accept=".txt" /> |
| 99 | + </v-row> |
| 100 | + <v-row |
| 101 | + class="mt-12 ml-8 mr-8 mb-1" |
| 102 | + style="display: flex; align-items: center; justify-content: center" |
| 103 | + align="center" |
| 104 | + > |
| 105 | + <v-btn |
| 106 | + color="secondary" |
| 107 | + :disabled="importRKNNFile === null || importLabelsFile === null" |
| 108 | + @click="handleObjectDetectionImport" |
| 109 | + > |
| 110 | + <v-icon left class="open-icon"> mdi-import </v-icon> |
| 111 | + <span class="open-label">Import Object Detection Model</span> |
| 112 | + </v-btn> |
| 113 | + </v-row> |
| 114 | + </v-card-text> |
| 115 | + </v-card> |
| 116 | + </v-dialog> |
| 117 | + </v-col> |
| 118 | + </v-row> |
| 119 | + <v-row> |
| 120 | + <v-col cols="12"> |
| 121 | + <v-simple-table fixed-header height="100%" dense dark> |
| 122 | + <thead style="font-size: 1.25rem"> |
| 123 | + <tr> |
| 124 | + <th class="text-left">Available Models</th> |
| 125 | + </tr> |
| 126 | + </thead> |
| 127 | + <tbody> |
| 128 | + <tr v-for="model in supportedModels" :key="model"> |
| 129 | + <td>{{ model }}</td> |
| 130 | + </tr> |
| 131 | + </tbody> |
| 132 | + </v-simple-table> |
| 133 | + </v-col> |
| 134 | + </v-row> |
| 135 | + </div> |
| 136 | + </v-card> |
| 137 | +</template> |
| 138 | + |
| 139 | +<style scoped lang="scss"> |
| 140 | +.v-btn { |
| 141 | + width: 100%; |
| 142 | +} |
| 143 | +@media only screen and (max-width: 351px) { |
| 144 | + .open-icon { |
| 145 | + margin: 0 !important; |
| 146 | + } |
| 147 | + .open-label { |
| 148 | + display: none; |
| 149 | + } |
| 150 | +} |
| 151 | +.v-data-table { |
| 152 | + width: 100%; |
| 153 | + height: 100%; |
| 154 | + text-align: center; |
| 155 | + background-color: #006492 !important; |
| 156 | +
|
| 157 | + th, |
| 158 | + td { |
| 159 | + background-color: #006492 !important; |
| 160 | + font-size: 1rem !important; |
| 161 | + color: white !important; |
| 162 | + } |
| 163 | +
|
| 164 | + td { |
| 165 | + font-family: monospace !important; |
| 166 | + } |
| 167 | +
|
| 168 | + tbody :hover td { |
| 169 | + background-color: #005281 !important; |
| 170 | + } |
| 171 | +
|
| 172 | + ::-webkit-scrollbar { |
| 173 | + width: 0; |
| 174 | + height: 0.55em; |
| 175 | + border-radius: 5px; |
| 176 | + } |
| 177 | +
|
| 178 | + ::-webkit-scrollbar-track { |
| 179 | + -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.3); |
| 180 | + border-radius: 10px; |
| 181 | + } |
| 182 | +
|
| 183 | + ::-webkit-scrollbar-thumb { |
| 184 | + background-color: #ffd843; |
| 185 | + border-radius: 10px; |
| 186 | + } |
| 187 | +} |
| 188 | +</style> |
0 commit comments