Merge branch 'fe/fix/json-init' into 'fe/develop'
Fix: json 없을 때 에러 해결 See merge request s11-s-project/S11P21S002!190
This commit is contained in:
commit
6cd0ee68c9
@ -8,5 +8,6 @@ export async function getLabelJson(jsonPath: string) {
|
|||||||
'Cache-Control': 'no-cache',
|
'Cache-Control': 'no-cache',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(({ data }) => data);
|
.then(({ data }) => data)
|
||||||
|
.catch(() => ({}) as LabelJson);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import useProjectStore from '@/stores/useProjectStore';
|
|||||||
export default function ImageCanvas() {
|
export default function ImageCanvas() {
|
||||||
const project = useProjectStore((state) => state.project)!;
|
const project = useProjectStore((state) => state.project)!;
|
||||||
const { id: imageId, imagePath, dataPath } = useCanvasStore((state) => state.image)!;
|
const { id: imageId, imagePath, dataPath } = useCanvasStore((state) => state.image)!;
|
||||||
const { data: labelData, refetch } = useLabelJson(dataPath, project);
|
const { data: labelData } = useLabelJson(dataPath, project);
|
||||||
const { shapes } = labelData || [];
|
const { shapes } = labelData || [];
|
||||||
const selectedLabelId = useCanvasStore((state) => state.selectedLabelId);
|
const selectedLabelId = useCanvasStore((state) => state.selectedLabelId);
|
||||||
const setSelectedLabelId = useCanvasStore((state) => state.setSelectedLabelId);
|
const setSelectedLabelId = useCanvasStore((state) => state.setSelectedLabelId);
|
||||||
@ -64,6 +64,8 @@ export default function ImageCanvas() {
|
|||||||
shape_type: type === 'polygon' ? 'polygon' : 'rectangle',
|
shape_type: type === 'polygon' ? 'polygon' : 'rectangle',
|
||||||
points: coordinates,
|
points: coordinates,
|
||||||
})),
|
})),
|
||||||
|
imageWidth: image!.width,
|
||||||
|
imageHeight: image!.height,
|
||||||
});
|
});
|
||||||
|
|
||||||
saveImageLabels(project.id, imageId, { data: json })
|
saveImageLabels(project.id, imageId, { data: json })
|
||||||
@ -71,7 +73,7 @@ export default function ImageCanvas() {
|
|||||||
alert('레이블 데이터 저장 실패');
|
alert('레이블 데이터 저장 실패');
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
refetch();
|
alert('레이블링 성공!');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const startDrawRect = () => {
|
const startDrawRect = () => {
|
||||||
|
@ -4,16 +4,12 @@ import createLabelJson from '@/utils/json/createLabelJson';
|
|||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
|
|
||||||
export default function useLabelJson(dataPath: string, project: Project) {
|
export default function useLabelJson(dataPath: string, project: Project) {
|
||||||
const response = useLabelJsonQuery(dataPath);
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
const { data: labelJsonData } = response;
|
const createdJson = useMemo(() => createLabelJson(project.type), [dataPath]);
|
||||||
const createdJson = useMemo(
|
|
||||||
() => createLabelJson(project.type, labelJsonData.imageHeight, labelJsonData.imageWidth),
|
|
||||||
[project, labelJsonData]
|
|
||||||
);
|
|
||||||
|
|
||||||
if (Object.keys(labelJsonData).includes('version')) {
|
const response = useLabelJsonQuery(dataPath);
|
||||||
|
if (Object.keys(response.data).includes('version')) {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...response, data: createdJson };
|
return { ...response, data: createdJson };
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,13 @@
|
|||||||
import { LabelJson } from '@/types';
|
import { LabelJson } from '@/types';
|
||||||
|
|
||||||
export default function createLabelJson(
|
export default function createLabelJson(type: 'classification' | 'detection' | 'segmentation'): LabelJson {
|
||||||
type: 'classification' | 'detection' | 'segmentation',
|
|
||||||
imageHeight: number,
|
|
||||||
imageWidth: number
|
|
||||||
): LabelJson {
|
|
||||||
return {
|
return {
|
||||||
version: '0.1.0',
|
version: '0.1.0',
|
||||||
task_type: type === 'classification' ? 'cls' : type === 'detection' ? 'det' : 'seg',
|
task_type: type === 'classification' ? 'cls' : type === 'detection' ? 'det' : 'seg',
|
||||||
shapes: [],
|
shapes: [],
|
||||||
split: 'none',
|
split: 'none',
|
||||||
imageHeight,
|
imageHeight: 0,
|
||||||
imageWidth,
|
imageWidth: 0,
|
||||||
imageDepth: 3,
|
imageDepth: 3,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user