-
Notifications
You must be signed in to change notification settings - Fork 2
[refactor] 객체 추론 모드 스위치 정리 #433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 8 commits
240891a
e7fe9a4
2cb1c87
58b8484
085a45f
fb32434
b65fe73
501213e
ce5fb2e
2e7b5cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,21 @@ | ||||||||||||||
| export type CurationDetectionMode = 'server' | 'client'; | ||||||||||||||
|
|
||||||||||||||
| export const CURATION_DETECTION_MODE = | ||||||||||||||
| (import.meta.env.VITE_CURATION_DETECTION_MODE === 'client' | ||||||||||||||
| ? 'client' | ||||||||||||||
| : 'server') satisfies CurationDetectionMode; | ||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||
|
|
||||||||||||||
| export const IS_CLIENT_DETECTION_ENABLED = CURATION_DETECTION_MODE === 'client'; | ||||||||||||||
|
|
||||||||||||||
| export const getCategoryQueryDetectedObjects = <T>(detectedObjects: T[]) => | ||||||||||||||
| IS_CLIENT_DETECTION_ENABLED ? detectedObjects : undefined; | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial
현재 추론된 타입은 💡 타입 명시 제안-export const getCategoryQueryDetectedObjects = <T>(detectedObjects: T[]) =>
- IS_CLIENT_DETECTION_ENABLED ? detectedObjects : undefined;
+export const getCategoryQueryDetectedObjects = <T>(
+ detectedObjects: T[]
+): T[] | undefined =>
+ IS_CLIENT_DETECTION_ENABLED ? detectedObjects : undefined;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||
|
|
||||||||||||||
| export const isCategoryQueryEnabled = ( | ||||||||||||||
| imageId: number | null, | ||||||||||||||
| detectedObjectsCount: number | ||||||||||||||
| ) => | ||||||||||||||
| imageId !== null && | ||||||||||||||
| (!IS_CLIENT_DETECTION_ENABLED || detectedObjectsCount > 0); | ||||||||||||||
|
|
||||||||||||||
| export const shouldShowDetectionPending = (detectedObjectsCount: number) => | ||||||||||||||
| IS_CLIENT_DETECTION_ENABLED && detectedObjectsCount === 0; | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { useEffect } from 'react'; | ||
|
|
||
| import { useLocation } from 'react-router-dom'; | ||
|
|
||
| import { ROUTES } from '@/routes/paths'; | ||
|
|
||
| import { IS_CLIENT_DETECTION_ENABLED } from '@pages/generate/constants/curationDetectionMode'; | ||
| import { OBJ365_MODEL_PATH } from '@pages/generate/constants/detection'; | ||
|
|
||
| import { preloadONNXModel } from './useOnnxModel'; | ||
|
|
||
| const GENERATE_WARMUP_PATHS = [ | ||
| ROUTES.GENERATE, | ||
| ROUTES.IMAGE_SETUP, | ||
| ]; | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const useGenerateWarmupClient = () => { | ||
| const location = useLocation(); | ||
|
|
||
| useEffect(() => { | ||
| const pathname = location.pathname; | ||
| const shouldWarmup = GENERATE_WARMUP_PATHS.some( | ||
| (prefix) => pathname === prefix || pathname.startsWith(`${prefix}/`) | ||
| ); | ||
|
|
||
| if (!shouldWarmup) return; | ||
|
|
||
| preloadONNXModel(OBJ365_MODEL_PATH).catch(() => undefined); | ||
| }, [location.pathname]); | ||
| }; | ||
|
Comment on lines
+14
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial
경로 매칭 로직( 한 가지 제안: Line 25에서 🔧 제안- preloadONNXModel(OBJ365_MODEL_PATH).catch(() => undefined);
+ preloadONNXModel(OBJ365_MODEL_PATH).catch((e) => {
+ console.warn('[useGenerateWarmup] model preload failed:', e);
+ });🤖 Prompt for AI Agents |
||
|
|
||
| const useGenerateWarmupServer = () => { | ||
| // 서버 모드 no-op 훅 | ||
| }; | ||
|
Comment on lines
+29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial No-op 훅의 의도를 명확히 해두면 좋겠어요. 현재 주석이 한 줄이지만, 향후 서버 모드에서 다른 warmup 로직(예: 서버 캐시 프리히트)을 추가할 가능성이 있다면, JSDoc으로 확장 포인트를 남겨두는 것도 고려해 보세요. 🤖 Prompt for AI Agents |
||
|
|
||
| export const useGenerateWarmup = IS_CLIENT_DETECTION_ENABLED | ||
| ? useGenerateWarmupClient | ||
| : useGenerateWarmupServer; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -218,14 +218,28 @@ export const preloadONNXModel = async ( | |
| * - 640×640 렌더링 텐서를 입력으로 받아 감지 결과를 반환 | ||
| * - 추론 결과는 후속 파이프라인(`useFurnitureHotspots`)에서 원본 좌표로 보정 | ||
| */ | ||
| export function useONNXModel(modelPath: string) { | ||
| interface UseONNXModelOptions { | ||
| enabled?: boolean; | ||
| } | ||
|
|
||
| export function useONNXModel(modelPath: string, options?: UseONNXModelOptions) { | ||
| const enabled = options?.enabled ?? true; | ||
| const [session, setSession] = useState<InferenceSession | null>(null); | ||
| const [isLoading, setIsLoading] = useState(true); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const [progress, setProgress] = useState(0); | ||
| const ortRef = useRef<OnnxModule | null>(null); // onnxruntime-web 모듈 보관 | ||
|
|
||
| useEffect(() => { | ||
| if (!enabled) { | ||
| setSession(null); | ||
| ortRef.current = null; | ||
| setIsLoading(false); | ||
| setError(null); | ||
| setProgress(0); | ||
| return; | ||
| } | ||
|
Comment on lines
+234
to
+241
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial
현재 구조에서 🤖 Prompt for AI Agents |
||
|
|
||
| if (typeof window === 'undefined') { | ||
| setIsLoading(false); | ||
| setError('브라우저 환경이 아닙니다'); | ||
|
|
@@ -260,7 +274,7 @@ export function useONNXModel(modelPath: string) { | |
| return () => { | ||
| isMounted = false; | ||
| }; | ||
| }, [modelPath]); | ||
| }, [enabled, modelPath]); | ||
|
|
||
| const runInference = useCallback( | ||
| async (imageElement: HTMLImageElement): Promise<ProcessedDetections> => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { useEffect } from 'react'; | ||
|
|
||
| import { IS_CLIENT_DETECTION_ENABLED } from '@pages/generate/constants/curationDetectionMode'; | ||
| import { OBJ365_MODEL_PATH } from '@pages/generate/constants/detection'; | ||
|
|
||
| import { preloadONNXModel } from './useOnnxModel'; | ||
|
|
||
| const useStartPageModelPreloadClient = () => { | ||
| useEffect(() => { | ||
| preloadONNXModel(OBJ365_MODEL_PATH).catch(() => undefined); | ||
| }, []); | ||
| }; | ||
|
|
||
| const useStartPageModelPreloadServer = () => { | ||
| // 서버 모드 no-op 훅 | ||
| }; | ||
|
|
||
| export const useStartPageModelPreload = IS_CLIENT_DETECTION_ENABLED | ||
| ? useStartPageModelPreloadClient | ||
| : useStartPageModelPreloadServer; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.