diff --git a/README.md b/README.md index 9c893af..70b8370 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ the paper) at 10/16 fps (i.e., looking at one in every 16 frames), we would: go run prepare_rnn.go shibuya 16 cd models/gnn python train.py shibuya - cd ../rnn + cd github.com/favyen/mirisrnn python train.py ../../logs/shibuya/16/filter_rnn_ds.json ../../logs/shibuya/16/filter-rnn/model python train.py ../../logs/shibuya/16/refine_rnn_ds.json ../../logs/shibuya/16/refine-rnn/model diff --git a/eval.go b/bin/eval/eval.go similarity index 93% rename from eval.go rename to bin/eval/eval.go index 9ce3f1c..d014bfd 100644 --- a/eval.go +++ b/bin/eval/eval.go @@ -1,8 +1,8 @@ package main import ( - "./miris" - "./predicate" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/predicate" "fmt" "io/ioutil" @@ -107,9 +107,9 @@ func main() { var precision, recall, f1 float64 if tp > 0 { - precision = float64(tp)/float64(tp+fp) - recall = float64(tp)/float64(tp+fn) - f1 = 2/(1/precision+1/recall) + precision = float64(tp) / float64(tp+fp) + recall = float64(tp) / float64(tp+fn) + f1 = 2 / (1/precision + 1/recall) } fmt.Printf("p=%v, r=%v, f=%v\n", precision, recall, f1) } diff --git a/bin/exec/exec.go b/bin/exec/exec.go new file mode 100644 index 0000000..0d460ce --- /dev/null +++ b/bin/exec/exec.go @@ -0,0 +1,30 @@ +package main + +import ( + "github.com/favyen/miris/data" + "github.com/favyen/miris/exec" + "github.com/favyen/miris/miris" + + "fmt" + "os" +) + +func main() { + predName := os.Args[1] + planFname := os.Args[2] + + ppCfg, modelCfg := data.Get(predName) + detectionPath, framePath := data.GetExec(predName) + var plan miris.PlannerConfig + miris.ReadJSON(planFname, &plan) + execCfg := miris.ExecConfig{ + DetectionPath: detectionPath, + FramePath: framePath, + TrackOutput: fmt.Sprintf("logs/%s/%d/%v/track.json", predName, plan.Freq, plan.Bound), + FilterOutput: fmt.Sprintf("logs/%s/%d/%v/filter.json", predName, plan.Freq, plan.Bound), + UncertaintyOutput: fmt.Sprintf("logs/%s/%d/%v/uncertainty.json", predName, plan.Freq, plan.Bound), + RefineOutput: fmt.Sprintf("logs/%s/%d/%v/refine.json", predName, plan.Freq, plan.Bound), + OutPath: fmt.Sprintf("logs/%s/%d/%v/final.json", predName, plan.Freq, plan.Bound), + } + exec.Exec(ppCfg, modelCfg, plan, execCfg) +} diff --git a/get-count.go b/bin/get-count/get-count.go similarity index 85% rename from get-count.go rename to bin/get-count/get-count.go index cb71bc4..cb35318 100644 --- a/get-count.go +++ b/bin/get-count/get-count.go @@ -1,8 +1,8 @@ package main import ( - "./miris" - "./predicate" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/predicate" "fmt" "os" diff --git a/plan.go b/bin/plan/plan.go similarity index 86% rename from plan.go rename to bin/plan/plan.go index 99090fb..37a94c5 100644 --- a/plan.go +++ b/bin/plan/plan.go @@ -1,9 +1,9 @@ package main import ( - "./data" - "./miris" - "./planner" + "github.com/favyen/miris/data" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/planner" "fmt" "log" @@ -31,10 +31,10 @@ func main() { q := planner.PlanQ(qSamples, bound) log.Println("finished planning q", q) plan := miris.PlannerConfig{ - Freq: freq, - Bound: bound, + Freq: freq, + Bound: bound, QSamples: qSamples, - Q: q, + Q: q, } miris.WriteJSON(fmt.Sprintf("logs/%s/%d/%v/plan.json", predName, freq, bound), plan) filterPlan, refinePlan := planner.PlanFilterRefine(ppCfg, modelCfg, freq, bound, nil) @@ -43,4 +43,3 @@ func main() { log.Println(plan) miris.WriteJSON(fmt.Sprintf("logs/%s/%d/%v/plan.json", predName, freq, bound), plan) } - diff --git a/prepare_rnn.go b/bin/prepare_rnn/prepare_rnn.go similarity index 86% rename from prepare_rnn.go rename to bin/prepare_rnn/prepare_rnn.go index e1b947d..fae93fb 100644 --- a/prepare_rnn.go +++ b/bin/prepare_rnn/prepare_rnn.go @@ -1,10 +1,10 @@ package main import ( - "./data" - "./miris" - "./predicate" - rnnlib "./models/rnn" + "github.com/favyen/miris/data" + "github.com/favyen/miris/miris" + rnnlib "github.com/favyen/miris/models/rnn" + "github.com/favyen/miris/predicate" "fmt" "log" diff --git a/data/cfgs.go b/data/cfgs.go index 017633a..3a9aa0e 100644 --- a/data/cfgs.go +++ b/data/cfgs.go @@ -1,7 +1,7 @@ package data import ( - "../miris" + "github.com/favyen/miris/miris" "fmt" ) @@ -49,14 +49,14 @@ func Shibuya(predName string) (miris.PreprocessConfig, miris.ModelConfig) { ppCfg := miris.PreprocessConfig{ TrainSegments: segments[0:2], - ValSegments: segments[2:], - Predicate: predName, - FrameScale: 2, + ValSegments: segments[2:], + Predicate: predName, + FrameScale: 2, } var modelCfg miris.ModelConfig for freq := 32; freq >= 1; freq /= 2 { modelCfg.GNN = append(modelCfg.GNN, miris.GNNModel{ - Freq: freq, + Freq: freq, ModelPath: "logs/shibuya/gnn/model", }) modelCfg.Filters = append(modelCfg.Filters, miris.FilterModel{ @@ -88,14 +88,14 @@ func Warsaw(predName string) (miris.PreprocessConfig, miris.ModelConfig) { ppCfg := miris.PreprocessConfig{ TrainSegments: segments[0:2], - ValSegments: segments[2:], - Predicate: predName, - FrameScale: 2, + ValSegments: segments[2:], + Predicate: predName, + FrameScale: 2, } var modelCfg miris.ModelConfig for freq := 32; freq >= 1; freq /= 2 { modelCfg.GNN = append(modelCfg.GNN, miris.GNNModel{ - Freq: freq, + Freq: freq, ModelPath: "logs/warsaw/gnn/model", }) modelCfg.Filters = append(modelCfg.Filters, miris.FilterModel{ @@ -127,14 +127,14 @@ func Beach(predName string) (miris.PreprocessConfig, miris.ModelConfig) { ppCfg := miris.PreprocessConfig{ TrainSegments: segments[0:2], - ValSegments: segments[2:], - Predicate: predName, - FrameScale: 2, + ValSegments: segments[2:], + Predicate: predName, + FrameScale: 2, } var modelCfg miris.ModelConfig for freq := 32; freq >= 1; freq /= 2 { modelCfg.GNN = append(modelCfg.GNN, miris.GNNModel{ - Freq: freq, + Freq: freq, ModelPath: "logs/beach/gnn/model", }) modelCfg.Filters = append(modelCfg.Filters, miris.FilterModel{ @@ -166,14 +166,14 @@ func UAV(predName string) (miris.PreprocessConfig, miris.ModelConfig) { ppCfg := miris.PreprocessConfig{ TrainSegments: segments[0:2], - ValSegments: segments[2:], - Predicate: predName, - FrameScale: 2, + ValSegments: segments[2:], + Predicate: predName, + FrameScale: 2, } var modelCfg miris.ModelConfig for freq := 32; freq >= 1; freq /= 2 { modelCfg.GNN = append(modelCfg.GNN, miris.GNNModel{ - Freq: freq, + Freq: freq, ModelPath: "logs/uav/gnn/model", }) modelCfg.Filters = append(modelCfg.Filters, miris.FilterModel{ diff --git a/exec.go b/exec.go deleted file mode 100644 index 44fd9b8..0000000 --- a/exec.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "./data" - "./exec" - "./miris" - - "fmt" - "os" -) - -func main() { - predName := os.Args[1] - planFname := os.Args[2] - - ppCfg, modelCfg := data.Get(predName) - detectionPath, framePath := data.GetExec(predName) - var plan miris.PlannerConfig - miris.ReadJSON(planFname, &plan) - execCfg := miris.ExecConfig{ - DetectionPath: detectionPath, - FramePath: framePath, - TrackOutput: fmt.Sprintf("logs/%s/%d/%v/track.json", predName, plan.Freq, plan.Bound), - FilterOutput: fmt.Sprintf("logs/%s/%d/%v/filter.json", predName, plan.Freq, plan.Bound), - UncertaintyOutput: fmt.Sprintf("logs/%s/%d/%v/uncertainty.json", predName, plan.Freq, plan.Bound), - RefineOutput: fmt.Sprintf("logs/%s/%d/%v/refine.json", predName, plan.Freq, plan.Bound), - OutPath: fmt.Sprintf("logs/%s/%d/%v/final.json", predName, plan.Freq, plan.Bound), - } - exec.Exec(ppCfg, modelCfg, plan, execCfg) -} - diff --git a/exec/exec.go b/exec/exec.go index 2175e3d..008068a 100644 --- a/exec/exec.go +++ b/exec/exec.go @@ -1,11 +1,11 @@ package exec import ( - filterlib "../filter" - gnnlib "../gnn" - "../miris" - "../predicate" - "../refine" + filterlib "github.com/favyen/miris/filter" + gnnlib "github.com/favyen/miris/gnn" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/predicate" + "github.com/favyen/miris/refine" "log" "os" @@ -28,8 +28,8 @@ func getNeededSpecs(needed []int, seenFrames map[int]bool, maxFrame int) [][2]in idx2 = seenIdx } } - freq1 := frameIdx-idx1 - freq2 := idx2-frameIdx + freq1 := frameIdx - idx1 + freq2 := idx2 - frameIdx frames = append(frames, [2]int{idx1, freq1}) frames = append(frames, [2]int{frameIdx, freq2}) } @@ -42,7 +42,7 @@ func getNeededSpecs(needed []int, seenFrames map[int]bool, maxFrame int) [][2]in type GraphWithSeen struct { Graph []gnnlib.Edge - Seen map[int]bool + Seen map[int]bool } func ReadGraphAndSeen(fname string) ([]gnnlib.Edge, map[int]bool) { @@ -90,7 +90,7 @@ func Exec(ppCfg miris.PreprocessConfig, modelCfg miris.ModelConfig, plan miris.P if _, err := os.Stat(execCfg.TrackOutput); err != nil { log.Printf("[exec] run initial tracking") - for _, freq := range []int{2*plan.Freq, plan.Freq} { + for _, freq := range []int{2 * plan.Freq, plan.Freq} { var frames [][2]int for frameIdx := 0; frameIdx < gnn.NumFrames()-freq; frameIdx += freq { frames = append(frames, [2]int{frameIdx, freq}) @@ -105,7 +105,7 @@ func Exec(ppCfg miris.PreprocessConfig, modelCfg miris.ModelConfig, plan miris.P graph, seenFrames = ReadGraphAndSeen(execCfg.TrackOutput) } log.Printf("[exec] ... tracking yields graph with %d edges (seen %d frames)", len(graph), len(seenFrames)) - maxFrame := ((gnn.NumFrames()-1)/plan.Freq)*plan.Freq + maxFrame := ((gnn.NumFrames() - 1) / plan.Freq) * plan.Freq // now filter the components var components [][]gnnlib.Edge @@ -240,7 +240,7 @@ func Exec(ppCfg miris.PreprocessConfig, modelCfg miris.ModelConfig, plan miris.P for _, comp := range components { for _, track := range gnn.SampleComponent(comp) { for i := range track { - track[i].TrackID = len(tracks)+1 + track[i].TrackID = len(tracks) + 1 } tracks = append(tracks, track) } diff --git a/filter/filter.go b/filter/filter.go index 1bc12e1..ee2072c 100644 --- a/filter/filter.go +++ b/filter/filter.go @@ -1,7 +1,7 @@ package filter import ( - "../miris" + "github.com/favyen/miris/miris" ) const Threads int = 12 diff --git a/filter/nnd.go b/filter/nnd.go index 6bc6178..fe67a8d 100644 --- a/filter/nnd.go +++ b/filter/nnd.go @@ -1,7 +1,7 @@ package filter import ( - "../miris" + "github.com/favyen/miris/miris" "log" ) @@ -49,7 +49,7 @@ func (nnd NNDFilter) Predict(tracks [][]miris.Detection) []float64 { }() } for i := range tracks { - if i % 1000 == 0 { + if i%1000 == 0 { log.Printf("[filter-nnd] ... %d/%d", i, len(tracks)) } ch <- i @@ -57,7 +57,7 @@ func (nnd NNDFilter) Predict(tracks [][]miris.Detection) []float64 { close(ch) scores := make([]float64, len(tracks)) for i := 0; i < Threads; i++ { - m := <- donech + m := <-donech for idx, score := range m { scores[idx] = score } diff --git a/filter/noop.go b/filter/noop.go index 2245466..4f62371 100644 --- a/filter/noop.go +++ b/filter/noop.go @@ -1,7 +1,7 @@ package filter import ( - "../miris" + "github.com/favyen/miris/miris" ) func init() { diff --git a/filter/rnn.go b/filter/rnn.go index c6fb19b..7ed371e 100644 --- a/filter/rnn.go +++ b/filter/rnn.go @@ -1,8 +1,8 @@ package filter import ( - "../miris" - rnnlib "../models/rnn" + "github.com/favyen/miris/miris" + rnnlib "github.com/favyen/miris/models/rnn" ) func init() { diff --git a/gnn/exec.go b/gnn/exec.go index 4afa891..23aae3e 100644 --- a/gnn/exec.go +++ b/gnn/exec.go @@ -1,18 +1,18 @@ package gnn import ( - "../miris" + "github.com/favyen/miris/miris" "fmt" "sort" ) type Edge struct { - LeftFrame int - LeftIdx int + LeftFrame int + LeftIdx int RightFrame int - RightIdx int - Score float64 + RightIdx int + Score float64 } func GetEdgeMaps(edges []Edge) (map[[2]int][]Edge, map[[2]int][]Edge) { @@ -46,14 +46,14 @@ func (gnn *GNN) Update(edges []Edge, frames [][2]int, q map[int]float64) []Edge for i, frameSpec := range frames { idx1 := frameSpec[0] freq := frameSpec[1] - frameInferList[i] = [2]int{idx1, idx1+freq} + frameInferList[i] = [2]int{idx1, idx1 + freq} } mats := gnn.InferMany(frameInferList, "[gnn-update]") for i, frameSpec := range frames { idx1 := frameSpec[0] freq := frameSpec[1] - idx2 := idx1+freq + idx2 := idx1 + freq mat := mats[i] if q[freq] == 0 { panic(fmt.Errorf("gnn update got freq %d without q on frames (%d,%d)", freq, idx1, idx2)) @@ -308,7 +308,7 @@ func (gnn *GNN) GetUncertainFrames(components [][]Edge, seen []int) []int { if next == -1 || next-lk[0] <= 1 { panic(fmt.Errorf("issue finding frame for uncertain edge")) } - mid := (lk[0]+next)/2 + mid := (lk[0] + next) / 2 frameSet[mid] = true } for rk, group := range rightMap { @@ -319,7 +319,7 @@ func (gnn *GNN) GetUncertainFrames(components [][]Edge, seen []int) []int { if prev == -1 || rk[0]-prev <= 1 { panic(fmt.Errorf("issue finding frame for uncertain edge")) } - mid := (prev+rk[0])/2 + mid := (prev + rk[0]) / 2 frameSet[mid] = true } } diff --git a/gnn/gnn.go b/gnn/gnn.go index a628f6b..33a96dd 100644 --- a/gnn/gnn.go +++ b/gnn/gnn.go @@ -1,7 +1,7 @@ package gnn import ( - "../miris" + "github.com/favyen/miris/miris" "bufio" "encoding/json" @@ -12,9 +12,9 @@ import ( ) type GNN struct { - cmd *exec.Cmd - stdin io.WriteCloser - rd *bufio.Reader + cmd *exec.Cmd + stdin io.WriteCloser + rd *bufio.Reader detections [][]miris.Detection } @@ -56,10 +56,10 @@ func (gnn *GNN) Infer(idx1 int, idx2 int) [][]float64 { func (gnn *GNN) InferMany(frames [][2]int, logPrefix string) [][][]float64 { var mats [][][]float64 for i := 0; i < len(frames); i += 16 { - if logPrefix != "" && i % 128 == 0 { - log.Printf(logPrefix + " %d/%d (%d/%d)", frames[i][0], len(gnn.detections), i, len(frames)) + if logPrefix != "" && i%128 == 0 { + log.Printf(logPrefix+" %d/%d (%d/%d)", frames[i][0], len(gnn.detections), i, len(frames)) } - end := i+16 + end := i + 16 if end > len(frames) { end = len(frames) } @@ -68,7 +68,7 @@ func (gnn *GNN) InferMany(frames [][2]int, logPrefix string) [][][]float64 { if err != nil { panic(err) } - if _, err := gnn.stdin.Write([]byte(string(bytes)+"\n")); err != nil { + if _, err := gnn.stdin.Write([]byte(string(bytes) + "\n")); err != nil { panic(err) } line, err := gnn.rd.ReadString('\n') diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c2a9cff --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module github.com/favyen/miris + +go 1.14 + +require ( + github.com/ajstarks/svgo v0.0.0-20200725142600-7a3c8b57fecb // indirect + github.com/dhconnelly/rtreego v1.0.0 // indirect + github.com/golang/protobuf v1.4.3 // indirect + github.com/mitroadmaps/gomapinfer v0.0.0-20200618184748-ce5d64b5a0d4 + github.com/qedus/osmpbf v1.1.0 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..2063187 --- /dev/null +++ b/go.sum @@ -0,0 +1,28 @@ +github.com/ajstarks/svgo v0.0.0-20200725142600-7a3c8b57fecb h1:EVl3FJLQCzSbgBezKo/1A4ADnJ4mtJZ0RvnNzDJ44nY= +github.com/ajstarks/svgo v0.0.0-20200725142600-7a3c8b57fecb/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw= +github.com/dhconnelly/rtreego v1.0.0 h1:1+V1STGw+zwx7jpvH/fwbeC5w5gZfn+XinARU45oRek= +github.com/dhconnelly/rtreego v1.0.0/go.mod h1:SDozu0Fjy17XH1svEXJgdYq8Tah6Zjfa/4Q33Z80+KM= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= +github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/mitroadmaps/gomapinfer v0.0.0-20200618184748-ce5d64b5a0d4 h1:w2ngyqzQlZG2jyroTlur23vUvIrXkuBBv3Tl99Y/S3k= +github.com/mitroadmaps/gomapinfer v0.0.0-20200618184748-ce5d64b5a0d4/go.mod h1:60dnxKwUjhRjPfhvtjJQccZOo741GN+5WymEEc+Aa0c= +github.com/qedus/osmpbf v1.1.0 h1:1ewnhb7cX0VAp24M+ViDvLI9RKKgZOXFBLM5xGlB5TA= +github.com/qedus/osmpbf v1.1.0/go.mod h1:37EgzlwZC2inPP5/rY1MZIxE6kgDof7MIljJuELs0c0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= diff --git a/miris/config.go b/miris/config.go index 3052203..4237425 100644 --- a/miris/config.go +++ b/miris/config.go @@ -11,32 +11,32 @@ type Segment struct { type PreprocessConfig struct { TrainSegments []Segment - ValSegments []Segment - Predicate string - FrameScale int + ValSegments []Segment + Predicate string + FrameScale int } type FilterModel struct { Name string Freq int - Cfg map[string]string + Cfg map[string]string } type RefineModel struct { Name string Freq int - Cfg map[string]string + Cfg map[string]string } type GNNModel struct { - Freq int + Freq int ModelPath string } type ModelConfig struct { - Filters []FilterModel + Filters []FilterModel Refiners []RefineModel - GNN []GNNModel + GNN []GNNModel } func (cfg ModelConfig) GetFilterCfg(name string, freq int) map[string]string { @@ -69,32 +69,32 @@ func (cfg ModelConfig) GetGNN(freq int) GNNModel { } type FilterPlan struct { - Name string + Name string Threshold float64 } type RefinePlan struct { - PSMethod string - PSCfg map[string]string + PSMethod string + PSCfg map[string]string InterpMethod string - InterpCfg map[string]string + InterpCfg map[string]string } type PlannerConfig struct { - Freq int - Bound float64 - Filter FilterPlan + Freq int + Bound float64 + Filter FilterPlan QSamples map[int][]float64 - Q map[int]float64 - Refine RefinePlan + Q map[int]float64 + Refine RefinePlan } type ExecConfig struct { - DetectionPath string - FramePath string - TrackOutput string - FilterOutput string + DetectionPath string + FramePath string + TrackOutput string + FilterOutput string UncertaintyOutput string - RefineOutput string - OutPath string + RefineOutput string + OutPath string } diff --git a/miris/detection.go b/miris/detection.go index 7e55b3f..3f22bea 100644 --- a/miris/detection.go +++ b/miris/detection.go @@ -9,13 +9,13 @@ import ( ) type Detection struct { - FrameIdx int `json:"frame_idx"` - TrackID int `json:"track_id"` - Left int `json:"left"` - Top int `json:"top"` - Right int `json:"right"` - Bottom int `json:"bottom"` - Score float64 `json:"score,omitempty"` + FrameIdx int `json:"frame_idx"` + TrackID int `json:"track_id"` + Left int `json:"left"` + Top int `json:"top"` + Right int `json:"right"` + Bottom int `json:"bottom"` + Score float64 `json:"score,omitempty"` } func (d Detection) Bounds() common.Rectangle { @@ -30,15 +30,15 @@ func (d Detection) Equals(other Detection) bool { } func Interpolate(a Detection, b Detection, frameIdx int) Detection { - factor := float64(frameIdx - a.FrameIdx) / float64(b.FrameIdx - a.FrameIdx) + factor := float64(frameIdx-a.FrameIdx) / float64(b.FrameIdx-a.FrameIdx) d := Detection{ FrameIdx: frameIdx, - TrackID: a.TrackID, + TrackID: a.TrackID, } - d.Left = int(factor * float64(b.Left - a.Left)) + a.Left - d.Top = int(factor * float64(b.Top - a.Top)) + a.Top - d.Right = int(factor * float64(b.Right - a.Right)) + a.Right - d.Bottom = int(factor * float64(b.Bottom - a.Bottom)) + a.Bottom + d.Left = int(factor*float64(b.Left-a.Left)) + a.Left + d.Top = int(factor*float64(b.Top-a.Top)) + a.Top + d.Right = int(factor*float64(b.Right-a.Right)) + a.Right + d.Bottom = int(factor*float64(b.Bottom-a.Bottom)) + a.Bottom return d } @@ -46,7 +46,7 @@ func Densify(track []Detection) []Detection { var denseTrack []Detection for _, detection := range track { if len(denseTrack) > 0 { - prev := denseTrack[len(denseTrack) - 1] + prev := denseTrack[len(denseTrack)-1] for frameIdx := prev.FrameIdx + 1; frameIdx < detection.FrameIdx; frameIdx++ { denseTrack = append(denseTrack, Interpolate(prev, detection, frameIdx)) } @@ -70,7 +70,7 @@ func DensifyAt(track []Detection, indexes []int) []Detection { var denseTrack []Detection for _, detection := range track { if len(denseTrack) > 0 { - prev := denseTrack[len(denseTrack) - 1] + prev := denseTrack[len(denseTrack)-1] for frameIdx := prev.FrameIdx + 1; frameIdx < detection.FrameIdx; frameIdx++ { if !relevant[frameIdx] { continue @@ -84,6 +84,7 @@ func DensifyAt(track []Detection, indexes []int) []Detection { } type FeatureVector [64]float64 + func (v1 FeatureVector) Distance(v2 FeatureVector) float64 { var d float64 = 0 for i := 0; i < len(v1); i++ { @@ -97,10 +98,11 @@ type ActionVectorJSON struct { Y float64 `json:"y"` P float64 `json:"p"` } + func (v ActionVectorJSON) ActionVector() ActionVector { return ActionVector{ Displacement: common.Point{v.X, v.Y}, - Probability: v.P, + Probability: v.P, } } @@ -180,7 +182,7 @@ func CountDetections(detections [][]Detection) int { func GetCoarse(track []Detection, freq int, k int) []Detection { var coarse []Detection for _, detection := range track { - if detection.FrameIdx % freq != k { + if detection.FrameIdx%freq != k { continue } coarse = append(coarse, detection) diff --git a/miris/distance.go b/miris/distance.go index fe52236..0ced022 100644 --- a/miris/distance.go +++ b/miris/distance.go @@ -6,7 +6,7 @@ import ( func SamplePoints(track []Detection) []common.Point { var points []common.Point - for i := 0; i < len(track) - 1; i++ { + for i := 0; i < len(track)-1; i++ { segment := common.Segment{track[i].Bounds().Center(), track[i+1].Bounds().Center()} points = append(points, segment.Sample(10)...) } @@ -16,14 +16,14 @@ func SamplePoints(track []Detection) []common.Point { func SampleNormalizedPoints(track []Detection) []common.Point { // sample twenty points along the track var trackLength float64 = 0 - for i := 0; i < len(track) - 1; i++ { + for i := 0; i < len(track)-1; i++ { trackLength += track[i].Bounds().Center().Distance(track[i+1].Bounds().Center()) } pointFreq := trackLength / 20 points := []common.Point{track[0].Bounds().Center()} remaining := pointFreq - for i := 0; i < len(track) - 1; i++ { + for i := 0; i < len(track)-1; i++ { segment := common.Segment{track[i].Bounds().Center(), track[i+1].Bounds().Center()} for segment.Length() > remaining { vector := segment.Vector() diff --git a/models/rnn/lib.go b/models/rnn/lib.go index 11480da..78b54f0 100644 --- a/models/rnn/lib.go +++ b/models/rnn/lib.go @@ -1,8 +1,8 @@ package rnn import ( - "../../miris" - "../../predicate" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/predicate" "bufio" "encoding/json" @@ -16,12 +16,12 @@ import ( type Item struct { Track []miris.Detection `json:"track"` - Label []int `json:"label"` + Label []int `json:"label"` } type DS struct { Train []Item `json:"train"` - Val []Item `json:"val"` + Val []Item `json:"val"` } func boolToInt(b []bool) []int { @@ -35,9 +35,9 @@ func boolToInt(b []bool) []int { } type Model struct { - cmd *exec.Cmd + cmd *exec.Cmd stdin io.WriteCloser - rd *bufio.Reader + rd *bufio.Reader } func MakeModel(numOutputs int, modelPath string) Model { @@ -51,7 +51,7 @@ func (m Model) Infer(tracks [][]miris.Detection) [][]float64 { if err != nil { panic(err) } - if _, err := m.stdin.Write([]byte(string(bytes)+"\n")); err != nil { + if _, err := m.stdin.Write([]byte(string(bytes) + "\n")); err != nil { panic(err) } line, err := m.rd.ReadString('\n') @@ -88,7 +88,7 @@ func GetCoarsePSRefine(track []miris.Detection, freq int, pFreq int, sFreq int, frameToDetection := make(map[int]miris.Detection) for i, detection := range track { frameToDetection[detection.FrameIdx] = detection - if detection.FrameIdx % freq != k { + if detection.FrameIdx%freq != k { continue } coarse = append(coarse, detection) @@ -105,7 +105,7 @@ func GetCoarsePSRefine(track []miris.Detection, freq int, pFreq int, sFreq int, coarse = append([]miris.Detection{}, track[start:end+1]...) } var fakes []miris.Detection - for x := freq/2; x >= pFreq; x /= 2 { + for x := freq / 2; x >= pFreq; x /= 2 { frameIdx := coarse[0].FrameIdx - x detection, ok := frameToDetection[frameIdx] if ok { @@ -113,15 +113,15 @@ func GetCoarsePSRefine(track []miris.Detection, freq int, pFreq int, sFreq int, } else { fake := miris.Detection{ FrameIdx: frameIdx, - Left: 0, - Top: 0, - Right: 0, - Bottom: 0, + Left: 0, + Top: 0, + Right: 0, + Bottom: 0, } fakes = append(fakes, fake) } } - for x := freq/2; x >= sFreq; x /= 2 { + for x := freq / 2; x >= sFreq; x /= 2 { frameIdx := coarse[len(coarse)-1].FrameIdx + x detection, ok := frameToDetection[frameIdx] if ok { @@ -129,10 +129,10 @@ func GetCoarsePSRefine(track []miris.Detection, freq int, pFreq int, sFreq int, } else { fake := miris.Detection{ FrameIdx: frameIdx, - Left: 0, - Top: 0, - Right: 0, - Bottom: 0, + Left: 0, + Top: 0, + Right: 0, + Bottom: 0, } fakes = append(fakes, fake) } @@ -172,8 +172,8 @@ func ItemsFromSegments(segments []miris.Segment, freq int, predFunc predicate.Pr freqList = append(freqList, x) } - coarsePerTrueTrack := 1+(50000/numTrue) - coarsePerFalseTrack := 1+(50000/numFalse) + coarsePerTrueTrack := 1 + (50000 / numTrue) + coarsePerFalseTrack := 1 + (50000 / numFalse) log.Printf("[prepare] compute coarse tracks (max true=%d false=%d per track with %d tracks)", coarsePerTrueTrack, coarsePerFalseTrack, len(tracks)) var filterItems, refineItems []Item for i, track := range tracks { diff --git a/planner/filter.go b/planner/filter.go index 023ebc5..e6ca00d 100644 --- a/planner/filter.go +++ b/planner/filter.go @@ -1,8 +1,8 @@ package planner import ( - "../filter" - "../miris" + "github.com/favyen/miris/filter" + "github.com/favyen/miris/miris" "log" "sort" @@ -26,8 +26,8 @@ func PlanFilter(context plannerContext) miris.FilterPlan { // get coarse validation tracks // don't create much more than 25K true and 25K false tracks - coarsePerTrueTrack := 1+(50000/valTrue) - coarsePerFalseTrack := 1+(50000/valFalse) + coarsePerTrueTrack := 1 + (50000 / valTrue) + coarsePerFalseTrack := 1 + (50000 / valFalse) log.Printf("[plan-filter] compute coarse tracks (max true=%d false=%d per track with %d val tracks)", coarsePerTrueTrack, coarsePerFalseTrack, len(context.valTracks)) var coarseTracks [][]miris.Detection var coarseLabels []bool @@ -64,7 +64,7 @@ func PlanFilter(context plannerContext) miris.FilterPlan { } log.Printf("[plan-filter] best filter is %s with precision=%v, threshold=%v", bestName, bestPrecision, bestThreshold) return miris.FilterPlan{ - Name: bestName, + Name: bestName, Threshold: bestThreshold, } } diff --git a/planner/planner.go b/planner/planner.go index add16e0..4e4b369 100644 --- a/planner/planner.go +++ b/planner/planner.go @@ -1,30 +1,30 @@ package planner import ( - "../miris" - "../predicate" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/predicate" "log" ) type plannerContext struct { - ppCfg miris.PreprocessConfig - modelCfg miris.ModelConfig - freq int - bound float64 + ppCfg miris.PreprocessConfig + modelCfg miris.ModelConfig + freq int + bound float64 trainDetections [][]miris.Detection - trainTracks [][]miris.Detection - valDetections [][]miris.Detection - valTracks [][]miris.Detection - predFunc predicate.Predicate + trainTracks [][]miris.Detection + valDetections [][]miris.Detection + valTracks [][]miris.Detection + predFunc predicate.Predicate } func PlanFilterRefine(ppCfg miris.PreprocessConfig, modelCfg miris.ModelConfig, freq int, bound float64, existingFilterPlan *miris.FilterPlan) (miris.FilterPlan, miris.RefinePlan) { context := plannerContext{ - ppCfg: ppCfg, + ppCfg: ppCfg, modelCfg: modelCfg, - freq: freq, - bound: bound, + freq: freq, + bound: bound, } increment := func(detections [][]miris.Detection, frames int, trackID int) { diff --git a/planner/refine.go b/planner/refine.go index b5bda81..68ac043 100644 --- a/planner/refine.go +++ b/planner/refine.go @@ -1,9 +1,9 @@ package planner import ( - "../filter" - "../miris" - "../refine" + "github.com/favyen/miris/filter" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/refine" "log" ) @@ -77,9 +77,9 @@ func PlanRefine(context plannerContext, filterPlan miris.FilterPlan) miris.Refin } log.Printf("[plan-refine] decided to use (%s, %s)", bestNames[0], bestNames[1]) return miris.RefinePlan{ - PSMethod: bestNames[0], - PSCfg: refinerConfigs[bestNames[0]], + PSMethod: bestNames[0], + PSCfg: refinerConfigs[bestNames[0]], InterpMethod: bestNames[1], - InterpCfg: refinerConfigs[bestNames[1]], + InterpCfg: refinerConfigs[bestNames[1]], } } diff --git a/planner/uncertainty.go b/planner/uncertainty.go index a595594..7f72587 100644 --- a/planner/uncertainty.go +++ b/planner/uncertainty.go @@ -1,9 +1,9 @@ package planner import ( - "../gnn" - "../miris" - "../predicate" + "github.com/favyen/miris/gnn" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/predicate" "fmt" "log" @@ -45,7 +45,7 @@ func GetQSamplesSegment(ppCfg miris.PreprocessConfig, segment miris.Segment, fre var frames [][2]int for frameIdx := 0; frameIdx < len(detections)-freq; frameIdx += freq { - frames = append(frames, [2]int{frameIdx, frameIdx+freq}) + frames = append(frames, [2]int{frameIdx, frameIdx + freq}) } mats := model.InferMany(frames, fmt.Sprintf("[plan-q] [%s @ %d]", segment.FramePath, freq)) for counter, mat := range mats { @@ -88,14 +88,14 @@ func GetQSamplesSegment(ppCfg miris.PreprocessConfig, segment miris.Segment, fre // disconnects is set of disconnected indices in track // if i is disconnected, it means getLongestSegment := func(track []miris.Detection, disconnects map[int]bool) []miris.Detection { - discList := []int{-1, len(track)-1} + discList := []int{-1, len(track) - 1} for idx := range disconnects { discList = append(discList, idx) } sort.Ints(discList) var longestSegment []miris.Detection for i := 0; i < len(discList)-1; i++ { - segment := track[discList[i]+1:discList[i+1]+1] + segment := track[discList[i]+1 : discList[i+1]+1] if len(segment) > len(longestSegment) { longestSegment = segment } @@ -151,7 +151,7 @@ func GetQSamplesSegment(ppCfg miris.PreprocessConfig, segment miris.Segment, fre } type qjob struct { - freq int + freq int segment miris.Segment } @@ -181,7 +181,7 @@ func GetQSamples(maxFreq int, ppCfg miris.PreprocessConfig, modelCfg miris.Model close(jobch) allSamples := make(map[int][]float64) for i := 0; i < QThreads; i++ { - m := <- donech + m := <-donech for freq, samples := range m { allSamples[freq] = append(allSamples[freq], samples...) } diff --git a/predicate/misc.go b/predicate/misc.go index 9ef03a8..3ad1851 100644 --- a/predicate/misc.go +++ b/predicate/misc.go @@ -3,7 +3,7 @@ package predicate // miscellaneous queries import ( - "../miris" + "github.com/favyen/miris/miris" "github.com/mitroadmaps/gomapinfer/common" ) @@ -31,7 +31,6 @@ func WarsawBrake(tracks [][]miris.Detection) bool { return false } - // need to have hard braking: high speed in 5 frames, then 5 frames, then zero in 5 frames // high speed = 300 px / 5 frames, zero = 30 px / 5 frames for i := range track { @@ -72,7 +71,7 @@ func BeachRunner(tracks [][]miris.Detection) bool { if !poly.Contains(p2) { continue } - if track[i].FrameIdx - track[j].FrameIdx <= 20 { + if track[i].FrameIdx-track[j].FrameIdx <= 20 { return true } } diff --git a/predicate/predicate.go b/predicate/predicate.go index 8a55e56..883ff69 100644 --- a/predicate/predicate.go +++ b/predicate/predicate.go @@ -1,8 +1,8 @@ package predicate import ( + "github.com/favyen/miris/miris" "github.com/mitroadmaps/gomapinfer/common" - "../miris" ) var predicates = make(map[string]Predicate) @@ -76,7 +76,7 @@ func Or(predicates ...Predicate) Predicate { // returns index of latest detection that precedes idx by at least (nframes) func GetPredTime(track []miris.Detection, idx int, nframes int) int { for i := idx - 1; i >= 0; i-- { - if track[i].FrameIdx < track[idx].FrameIdx - nframes { + if track[i].FrameIdx < track[idx].FrameIdx-nframes { return i } } @@ -85,7 +85,7 @@ func GetPredTime(track []miris.Detection, idx int, nframes int) int { // returns index of closest predecessor to idx that is at least distance away func GetPredDistance(track []miris.Detection, idx int, distance float64) int { - for i := idx - 1 ; i >= 0; i-- { + for i := idx - 1; i >= 0; i-- { if track[i].Bounds().Center().Distance(track[idx].Bounds().Center()) >= distance { return i } diff --git a/refine/accel.go b/refine/accel.go index 495a000..66e9d1f 100644 --- a/refine/accel.go +++ b/refine/accel.go @@ -1,13 +1,13 @@ package refine import ( - "../miris" - "../predicate" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/predicate" "fmt" "math" - "strconv" "sort" + "strconv" ) func GetCoarseIntermediate(freq int, k int, track []miris.Detection) []miris.Detection { @@ -15,7 +15,7 @@ func GetCoarseIntermediate(freq int, k int, track []miris.Detection) []miris.Det end := -1 var coarse []miris.Detection for i, detection := range track { - if detection.FrameIdx % freq != k { + if detection.FrameIdx%freq != k { continue } coarse = append(coarse, detection) @@ -33,7 +33,7 @@ func GetCoarseIntermediate(freq int, k int, track []miris.Detection) []miris.Det out = append(out, coarse[0]) for _, detection := range coarse[1:] { last := out[len(out)-1] - for frameIdx := last.FrameIdx+freq; frameIdx < detection.FrameIdx; frameIdx += freq { + for frameIdx := last.FrameIdx + freq; frameIdx < detection.FrameIdx; frameIdx += freq { out = append(out, miris.Interpolate(last, detection, frameIdx)) } out = append(out, detection) @@ -43,14 +43,14 @@ func GetCoarseIntermediate(freq int, k int, track []miris.Detection) []miris.Det } type AccelRefiner struct { - freq int - predFunc predicate.Predicate + freq int + predFunc predicate.Predicate accelThreshold float64 } func MakeAccelRefiner(freq int, trainTracks [][]miris.Detection, predFunc predicate.Predicate, modelCfg map[string]string, cfg map[string]string) Refiner { r := &AccelRefiner{ - freq: freq, + freq: freq, predFunc: predFunc, } if cfg["threshold"] != "" { @@ -72,7 +72,7 @@ func (r *AccelRefiner) insertDetection(coarse []miris.Detection, original []miri var insertIdx int = 0 for i := 0; i < len(coarse); i++ { if coarse[i].FrameIdx < frameIdx { - insertIdx = i+1 + insertIdx = i + 1 } } if insertIdx == 0 || insertIdx == len(coarse) { @@ -97,7 +97,7 @@ func (r *AccelRefiner) refineOnce(track []miris.Detection) (int, int, float64) { var bestAccel float64 var bestIdx int = -1 for i := 1; i < len(track)-1; i++ { - if track[i].FrameIdx - track[i-1].FrameIdx <= 1 && track[i+1].FrameIdx - track[i].FrameIdx <= 1 { + if track[i].FrameIdx-track[i-1].FrameIdx <= 1 && track[i+1].FrameIdx-track[i].FrameIdx <= 1 { continue } vector1 := track[i].Bounds().Center().Sub(track[i-1].Bounds().Center()) @@ -113,10 +113,10 @@ func (r *AccelRefiner) refineOnce(track []miris.Detection) (int, int, float64) { } f1 := -1 f2 := -1 - if track[bestIdx].FrameIdx - track[bestIdx-1].FrameIdx > 1 { + if track[bestIdx].FrameIdx-track[bestIdx-1].FrameIdx > 1 { f1 = (track[bestIdx-1].FrameIdx + track[bestIdx].FrameIdx) / 2 } - if track[bestIdx+1].FrameIdx - track[bestIdx].FrameIdx > 1 { + if track[bestIdx+1].FrameIdx-track[bestIdx].FrameIdx > 1 { f2 = (track[bestIdx].FrameIdx + track[bestIdx+1].FrameIdx) / 2 } return f1, f2, bestAccel diff --git a/refine/refine.go b/refine/refine.go index 584a781..832c62b 100644 --- a/refine/refine.go +++ b/refine/refine.go @@ -1,8 +1,8 @@ package refine import ( - "../miris" - "../predicate" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/predicate" "log" ) @@ -29,7 +29,7 @@ func incorporate(tracks map[int][]miris.Detection, detections []miris.Detection) insertIdx := 0 for i, d := range track { if d.FrameIdx < detection.FrameIdx { - insertIdx = i+1 + insertIdx = i + 1 } } var newTrack []miris.Detection diff --git a/refine/rnn_ps.go b/refine/rnn_ps.go index 5130de2..3b72d6b 100644 --- a/refine/rnn_ps.go +++ b/refine/rnn_ps.go @@ -1,28 +1,28 @@ package refine import ( - "../miris" - "../predicate" - rnnlib "../models/rnn" + "github.com/favyen/miris/miris" + rnnlib "github.com/favyen/miris/models/rnn" + "github.com/favyen/miris/predicate" "fmt" - "strconv" "sort" + "strconv" ) type RNNPSRefiner struct { - freq int - predFunc predicate.Predicate - model rnnlib.Model + freq int + predFunc predicate.Predicate + model rnnlib.Model threshold float64 } func MakeRNNPSRefiner(freq int, trainTracks [][]miris.Detection, predFunc predicate.Predicate, modelCfg map[string]string, cfg map[string]string) Refiner { model := rnnlib.MakeModel(2, modelCfg["model_path"]) r := &RNNPSRefiner{ - freq: freq, + freq: freq, predFunc: predFunc, - model: model, + model: model, } if cfg["threshold"] != "" { var err error @@ -40,12 +40,12 @@ func init() { func (r *RNNPSRefiner) Plan(valTracks [][]miris.Detection, bound float64) map[string]string { type Example struct { - Coarse []miris.Detection + Coarse []miris.Detection Original map[int]miris.Detection - Debug []miris.Detection - MaxT float64 - PFreq int - SFreq int + Debug []miris.Detection + MaxT float64 + PFreq int + SFreq int } removeFakes := func(coarse []miris.Detection) []miris.Detection { @@ -81,12 +81,12 @@ func (r *RNNPSRefiner) Plan(valTracks [][]miris.Detection, bound float64) map[st continue } remaining = append(remaining, Example{ - Coarse: coarse, + Coarse: coarse, Original: frameToDetection, - MaxT: 1, - PFreq: r.freq/2, - SFreq: r.freq/2, - Debug: track, + MaxT: 1, + PFreq: r.freq / 2, + SFreq: r.freq / 2, + Debug: track, }) } } @@ -171,7 +171,7 @@ func (r *RNNPSRefiner) Step(tracks [][]miris.Detection, seen []int) ([]int, []in getFreq := func(frameIdx int) int { for freq := r.freq; freq >= 2; freq /= 2 { - if frameIdx % freq == 0 { + if frameIdx%freq == 0 { return freq } } @@ -188,7 +188,7 @@ func (r *RNNPSRefiner) Step(tracks [][]miris.Detection, seen []int) ([]int, []in // add fake detections to prefix/suffix if the track is missing in those frames curFrames := [2]int{-1, -1} pFreq := getFreq(track[0].FrameIdx) - for freq := pFreq/2; freq >= 1; freq /= 2 { + for freq := pFreq / 2; freq >= 1; freq /= 2 { frameIdx := track[0].FrameIdx - freq if !seenSet[frameIdx] { curFrames[0] = frameIdx @@ -198,7 +198,7 @@ func (r *RNNPSRefiner) Step(tracks [][]miris.Detection, seen []int) ([]int, []in track = append([]miris.Detection{fake}, track...) } sFreq := getFreq(track[len(track)-1].FrameIdx) - for freq := sFreq/2; freq >= 1; freq /= 2 { + for freq := sFreq / 2; freq >= 1; freq /= 2 { frameIdx := track[len(track)-1].FrameIdx + freq if !seenSet[frameIdx] { curFrames[1] = frameIdx diff --git a/refine/simple_ps.go b/refine/simple_ps.go index 4cefa67..c277623 100644 --- a/refine/simple_ps.go +++ b/refine/simple_ps.go @@ -1,12 +1,12 @@ package refine import ( - "../miris" - "../predicate" + "github.com/favyen/miris/miris" + "github.com/favyen/miris/predicate" "fmt" - "strconv" "sort" + "strconv" ) // Get coarse with all intermediate detections, just missing prefix and suffix. @@ -14,7 +14,7 @@ func GetCoarsePS(track []miris.Detection, freq int, k int) []miris.Detection { start := -1 end := -1 for i, detection := range track { - if detection.FrameIdx % freq != k { + if detection.FrameIdx%freq != k { continue } if start == -1 { @@ -25,18 +25,18 @@ func GetCoarsePS(track []miris.Detection, freq int, k int) []miris.Detection { if start == -1 || end == -1 { return nil } - return track[start:end+1] + return track[start : end+1] } type SimplePSRefiner struct { - freq int - predFunc predicate.Predicate + freq int + predFunc predicate.Predicate freqThreshold int } func MakeSimplePSRefiner(freq int, trainTracks [][]miris.Detection, predFunc predicate.Predicate, modelCfg map[string]string, cfg map[string]string) Refiner { r := &SimplePSRefiner{ - freq: freq, + freq: freq, predFunc: predFunc, } if cfg["threshold"] != "" { @@ -94,7 +94,7 @@ func (r *SimplePSRefiner) Step(tracks [][]miris.Detection, seen []int) ([]int, [ getFreq := func(frameIdx int) int { for freq := r.freq; freq >= 2; freq /= 2 { - if frameIdx % freq == 0 { + if frameIdx%freq == 0 { return freq } }