Skip to content

Commit

Permalink
finished sam-track
Browse files Browse the repository at this point in the history
  • Loading branch information
hxhxhx88 committed Sep 7, 2023
1 parent 3bd83f3 commit f249f6c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/frontend/src/common/algorithm/rle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
15 changes: 12 additions & 3 deletions app/frontend/src/component/panel/TrackOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -74,17 +78,22 @@ function ActiveTrackOverlay({

setTracking(undefined);
},
onError: () => {
setTracking(undefined);
},
});

return (
<div {...props}>
<Spin spinning={isLoading} />
<div style={{width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center'}}>
<Spin spinning={isLoading} />
</div>
</div>
);
}

function normalizeUrl(str: string): string {
if (str.startsWith('')) {
if (str.startsWith('/')) {
return `${window.location.protocol}//${window.location.host}${str}`;
}
return str;
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/page/annotate/Panel/Loaded.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const PanelLoaded: FC<{
/>
</div>
<TrackOverlay
style={{background: 'black', position: 'absolute', left: 0, top: 0, width: '100%', height: '100%'}}
style={{background: 'rgba(0,0,0,0.8)', position: 'absolute', left: 0, top: 0, width: '100%', height: '100%'}}
/>
<SyncingDisableInteractionMask />
<MonitorAnnotation videoId={video.id} />
Expand Down
4 changes: 4 additions & 0 deletions module/common/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion module/track/server/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f249f6c

Please sign in to comment.