From f249f6c7ae7571725542c7c7d14ac17529209a86 Mon Sep 17 00:00:00 2001 From: Xu Han Date: Thu, 7 Sep 2023 17:42:40 +0800 Subject: [PATCH] finished sam-track --- app/frontend/src/common/algorithm/rle.ts | 2 +- app/frontend/src/component/panel/TrackOverlay.tsx | 15 ++++++++++++--- app/frontend/src/page/annotate/Panel/Loaded.tsx | 2 +- module/common/python.go | 4 ++++ module/track/server/track.go | 6 +++++- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/app/frontend/src/common/algorithm/rle.ts b/app/frontend/src/common/algorithm/rle.ts index 9472d5b..0dc91dd 100644 --- a/app/frontend/src/common/algorithm/rle.ts +++ b/app/frontend/src/common/algorithm/rle.ts @@ -149,7 +149,7 @@ export function shrink(rle: RunLengthEncoding): {rle: RunLengthEncoding; offset: yMax = Math.max(y, yMax); }); - if (xMin < 0 || yMin < 0) { + if (xMax < 0 || yMax < 0) { // empty mask return undefined; } diff --git a/app/frontend/src/component/panel/TrackOverlay.tsx b/app/frontend/src/component/panel/TrackOverlay.tsx index e459a95..769d56d 100644 --- a/app/frontend/src/component/panel/TrackOverlay.tsx +++ b/app/frontend/src/component/panel/TrackOverlay.tsx @@ -31,7 +31,11 @@ function ActiveTrackOverlay({ const addComponents = useAnnoStore(s => s.addComponents); const {isLoading} = useQuery({ - queryKey: [], + // prevent cache + queryKey: [uuidv4()], + retry: false, + cacheTime: 0, + queryFn: () => { const {rle, offset} = ctx.mask; const { @@ -74,17 +78,22 @@ function ActiveTrackOverlay({ setTracking(undefined); }, + onError: () => { + setTracking(undefined); + }, }); return (
- +
+ +
); } function normalizeUrl(str: string): string { - if (str.startsWith('')) { + if (str.startsWith('/')) { return `${window.location.protocol}//${window.location.host}${str}`; } return str; diff --git a/app/frontend/src/page/annotate/Panel/Loaded.tsx b/app/frontend/src/page/annotate/Panel/Loaded.tsx index 5198aea..42b4721 100644 --- a/app/frontend/src/page/annotate/Panel/Loaded.tsx +++ b/app/frontend/src/page/annotate/Panel/Loaded.tsx @@ -73,7 +73,7 @@ export const PanelLoaded: FC<{ /> diff --git a/module/common/python.go b/module/common/python.go index c1c4bc3..d0a86c4 100644 --- a/module/common/python.go +++ b/module/common/python.go @@ -19,11 +19,15 @@ func RunPython(ctx context.Context, bin string, args ...string) error { type PythonRuntime struct { Env []string + Dir string } func (r *PythonRuntime) RunPython(ctx context.Context, bin string, args ...string) error { cmd := exec.Command(bin, args...) cmd.Env = r.Env + if r.Dir != "" { + cmd.Dir = r.Dir + } zap.L().Debug("running Python script", zap.String("cmd", cmd.String()), zap.Strings("envs", cmd.Env)) // redirect and monitor stderr of the subprocess diff --git a/module/track/server/track.go b/module/track/server/track.go index 9e05a4f..01dcc63 100644 --- a/module/track/server/track.go +++ b/module/track/server/track.go @@ -46,7 +46,11 @@ func (s *mServer) Track(ctx context.Context, req *servicev1.TrackRequest) (*serv // call Python resultPath := taskPath + ".result.json" - err = common.RunPython(ctx, s.options.pythonBin, s.options.scriptMain, + r := common.PythonRuntime{ + Dir: filepath.Dir(s.options.scriptMain), + } + main := filepath.Base(s.options.scriptMain) + err = r.RunPython(ctx, s.options.pythonBin, main, "--gpu", fmt.Sprintf("%d", opt.gpuId), "--input", taskPath, "--output", resultPath,