fix(label): label result
This commit is contained in:
@@ -82,6 +82,7 @@ import {
|
||||
useKeyEventStore,
|
||||
useLabelStore,
|
||||
useObjectStore,
|
||||
useVideoFrameStore,
|
||||
} from "../store"
|
||||
import { useBackUrlStore, usePermissionStore } from "../store/auth"
|
||||
import { useBottomToolsStore } from "../useBottomToolsStore"
|
||||
@@ -450,7 +451,7 @@ const TopTools = (
|
||||
}
|
||||
|
||||
const { label_status, data_name } = taskDetail!
|
||||
let results = data_name.map((item, imageId) => {
|
||||
const frameResults = data_name.map((item, imageId) => {
|
||||
const name = item.name?.[0]
|
||||
let finalData: LabelResult = {
|
||||
data_name: name,
|
||||
@@ -637,6 +638,90 @@ const TopTools = (
|
||||
finalData.image_objects = image_objects
|
||||
return finalData
|
||||
})
|
||||
|
||||
let saveResults: LabelResult[] = frameResults
|
||||
if (projectDetail?.label_type === 7) {
|
||||
const frameNamesFromTask = data_name
|
||||
.map((item) => item.name?.[0] || "")
|
||||
.filter((name) => !!name)
|
||||
const frameNameSet = new Set(frameNamesFromTask)
|
||||
const frameStore = useVideoFrameStore.getState().videoFrames
|
||||
const taskVideoPrefix = `${taskDetail!.project_id}:${taskDetail!.id}:`
|
||||
const videoFrameEntries = Array.from(frameStore.entries()).filter(
|
||||
([key]) => key.startsWith(taskVideoPrefix)
|
||||
)
|
||||
if (!videoFrameEntries.length) {
|
||||
throw new Error("视频帧映射缺失,无法保存,请刷新任务后重试")
|
||||
}
|
||||
|
||||
const videoFrameMap = new Map<string, string[]>()
|
||||
videoFrameEntries.forEach(([key, frameNames]) => {
|
||||
const videoName = key.slice(taskVideoPrefix.length)
|
||||
if (!videoName) return
|
||||
videoFrameMap.set(
|
||||
videoName,
|
||||
(frameNames || []).filter((frameName) =>
|
||||
frameNameSet.has(frameName)
|
||||
)
|
||||
)
|
||||
})
|
||||
if (!videoFrameMap.size) {
|
||||
throw new Error("视频帧映射无效,无法保存,请刷新任务后重试")
|
||||
}
|
||||
|
||||
const videoNames = Array.from(videoFrameMap.keys())
|
||||
const frameToVideoMap = new Map<string, string>()
|
||||
videoFrameMap.forEach((frameNames, videoName) => {
|
||||
frameNames.forEach((frameName) => {
|
||||
frameToVideoMap.set(frameName, videoName)
|
||||
})
|
||||
})
|
||||
|
||||
const unresolvedFrames = frameNamesFromTask.filter(
|
||||
(frameName) => !frameToVideoMap.has(frameName)
|
||||
)
|
||||
if (unresolvedFrames.length) {
|
||||
throw new Error(
|
||||
`视频帧映射缺失,无法保存,请刷新任务后重试: ${unresolvedFrames.slice(0, 5).join(", ")}`
|
||||
)
|
||||
}
|
||||
|
||||
const frameResultMap = new Map<string, ImageObjects>()
|
||||
frameResults.forEach((item) => {
|
||||
if (item.image_objects) {
|
||||
frameResultMap.set(item.data_name, item.image_objects)
|
||||
}
|
||||
})
|
||||
|
||||
const groupedVideoObjects = new Map<
|
||||
string,
|
||||
{ [key: string]: ImageObjects }
|
||||
>()
|
||||
frameResultMap.forEach((imageObjects, frameName) => {
|
||||
const videoName = frameToVideoMap.get(frameName)
|
||||
if (!videoName) return
|
||||
if (!groupedVideoObjects.has(videoName)) {
|
||||
groupedVideoObjects.set(videoName, {})
|
||||
}
|
||||
groupedVideoObjects.get(videoName)![frameName] = imageObjects
|
||||
})
|
||||
|
||||
saveResults = videoNames
|
||||
.map((videoName) => {
|
||||
const videoObjects = groupedVideoObjects.get(videoName)
|
||||
if (!videoObjects || !Object.keys(videoObjects).length) return null
|
||||
return {
|
||||
data_name: videoName,
|
||||
video_objects: videoObjects,
|
||||
} as LabelResult
|
||||
})
|
||||
.filter((item): item is LabelResult => !!item)
|
||||
|
||||
if (!saveResults.length) {
|
||||
throw new Error("视频任务保存结果为空")
|
||||
}
|
||||
}
|
||||
|
||||
const workTime = {
|
||||
label_work_time: labelTime.label,
|
||||
first_review_work_time: labelTime.review1,
|
||||
@@ -653,7 +738,7 @@ const TopTools = (
|
||||
}
|
||||
const workLoad: WorkLoad = JSON.parse(JSON.stringify(initialWorkLoad))
|
||||
workLoad.work_time = time ? time - oldWorkLoad.work_time : 0
|
||||
results.forEach((item) => {
|
||||
frameResults.forEach((item) => {
|
||||
const { image_objects } = item
|
||||
if (image_objects) {
|
||||
const { annotations, key_frame, desc } = image_objects
|
||||
@@ -744,12 +829,9 @@ const TopTools = (
|
||||
let params: RequestLabelResult = {
|
||||
uid: user_id,
|
||||
task_id: taskDetail?.id || 0,
|
||||
results: results,
|
||||
results: saveResults,
|
||||
...defaultObj,
|
||||
}
|
||||
results.forEach((item) => {
|
||||
console.log(item.image_objects)
|
||||
})
|
||||
console.log(params, workLoad)
|
||||
await saveLabelResult(params)
|
||||
notifications.show({
|
||||
@@ -760,6 +842,11 @@ const TopTools = (
|
||||
updateOldWorkLoad(workLoad)
|
||||
} catch (error: any) {
|
||||
console.log(error)
|
||||
notifications.hide("save")
|
||||
notifications.show({
|
||||
color: "red",
|
||||
message: error?.message || "保存失败",
|
||||
})
|
||||
}
|
||||
}, [
|
||||
labelCategories,
|
||||
|
||||
Reference in New Issue
Block a user