From 586aca906c1f64fced120c95f201cce72772c448 Mon Sep 17 00:00:00 2001 From: dehann Date: Sat, 17 Feb 2024 17:09:26 -0800 Subject: [PATCH] switch feature mountain tracker to FolderDict --- NEWS.md | 1 + ext/CaesarImagesExt.jl | 2 ++ ext/Images/FeatureMountain.jl | 51 ++++++++++++----------------------- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/NEWS.md b/NEWS.md index 6e85c16c6..a7746c407 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,7 @@ Major changes and news in Caesar.jl. - Several compat updates for dependencies. - Restore Docs build, and update links for NavAbility at WhereWhen.ai Technologies Inc. - Introduce `FolderDict` as data structure for lower memory consumption, also as potential BlobStore. +- Refactor FeatureMountain tracker to use `FolderDict`. ## Changes in v0.13 diff --git a/ext/CaesarImagesExt.jl b/ext/CaesarImagesExt.jl index 839830e78..d226fe09b 100644 --- a/ext/CaesarImagesExt.jl +++ b/ext/CaesarImagesExt.jl @@ -40,6 +40,8 @@ import Caesar: addFeatureTracks_Frame1_Q!, addFeatureTracks_Frame2_PfwdQ!, addFe import Caesar: addFeatureTracks, consolidateFeatureTracks!, summarizeFeatureTracks!, buildFeatureMountain, buildFeatureMountainDistributed import Caesar: unionFeatureMountain, sortKeysMinSighting +import Caesar: FolderDict + # NOTE usage requires ImageFeatures.jl import Caesar: curateFeatureTracks diff --git a/ext/Images/FeatureMountain.jl b/ext/Images/FeatureMountain.jl index 6c1f126ec..c6c5efe7a 100644 --- a/ext/Images/FeatureMountain.jl +++ b/ext/Images/FeatureMountain.jl @@ -1,19 +1,21 @@ +FEATUREMOUNTAIN_DICT = Dict{Tuple{Symbol,Int},MANYTRACKS} +FEATUREMOUNTAIN_DIRDICT = FolderDict{Tuple{Symbol,Int},MANYTRACKS} +FEATUREMOUNTAINTYPES = Union{ + <:FEATUREMOUNTAIN_DICT, + <:FEATUREMOUNTAIN_DIRDICT +} function addFeatureTracks_Frame1_Q!( - # mountain::FeatureMountain, featToMany, dfg::AbstractDFG, vlb_q::Symbol; trackBlobKey = r"IMG_FEATURE_TRACKS_FWDBCK", ) # - # if !haskey(mountain, 1) - # mountain[1] = FeatureTracks() - # end eb = getData(dfg,vlb_q,trackBlobKey) if isnothing(eb) return featToMany @@ -26,9 +28,6 @@ function addFeatureTracks_Frame1_Q!( pixel = (meas[1],meas[2]) from = (vlb_q,featidx, pixel) to = (vlb_q,featidx, pixel) - # # legcay - # mountain[1][track_id] = FeaturesDict() - # mountain[1][track_id][vlb_q] = (;from, to) # featToMany container fromkey = (from[1],from[2]) @@ -43,12 +42,10 @@ function addFeatureTracks_Frame1_Q!( end return featToMany - # return mountain end function addFeatureTracks_Frame2_PfwdQ!( - # mountain::FeatureMountain, featToMany, dfg::AbstractDFG, vlb_pq, @@ -57,10 +54,6 @@ function addFeatureTracks_Frame2_PfwdQ!( imgBlobKey = r"cam" ) - # if !haskey(mountain, 2) - # mountain[2] = FeatureTracks() - # end - vlb_p, vlb_q = vlb_pq[1], vlb_pq[2] ie_ib = getData(dfg, vlb_q, imgBlobKey) @@ -86,10 +79,6 @@ function addFeatureTracks_Frame2_PfwdQ!( pixel_q = tuple(trk_pP1_q0[2]...) from = (vlb_p, i_pP1_q0[1], pixel_p) to = (vlb_q, i_pP1_q0[2], pixel_q) - # # legacy - # mountain[2][track_id] = FeaturesDict() - # mountain[2][track_id][vlb_p] = (;from, to) - # mountain[2][track_id][vlb_q] = (;from, to) # featToMany container fromkey = (from[1],from[2]) @@ -104,12 +93,10 @@ function addFeatureTracks_Frame2_PfwdQ!( end return featToMany - # return mountain end function addFeatureTracks_Frame2_QbckR!( - # mountain::FeatureMountain, featToMany, dfg::AbstractDFG, vlb_qr, @@ -118,10 +105,6 @@ function addFeatureTracks_Frame2_QbckR!( imgBlobKey = r"cam" ) - # if !haskey(mountain, 2) - # mountain[2] = FeatureTracks() - # end - vlb_q, vlb_r = vlb_qr[1], vlb_qr[2] ie_ib = getData(dfg, vlb_q, imgBlobKey) @@ -151,10 +134,6 @@ function addFeatureTracks_Frame2_QbckR!( pixel_q = tuple(trk_rN1_q0[2]...) from = (vlb_r, i_rN1_q0[1], pixel_r) to = (vlb_q, i_rN1_q0[2], pixel_q) - # # legacy - # mountain[2][track_id] = FeaturesDict() - # mountain[2][track_id][vlb_r] = (; from, to) - # mountain[2][track_id][vlb_q] = (; from, to) # featToMany container fromkey = (from[1],from[2]) @@ -169,7 +148,6 @@ function addFeatureTracks_Frame2_QbckR!( end return featToMany - # return mountain end # # require both forward and backward tracks to coincide @@ -246,7 +224,8 @@ function addFeatureTracks( imgBlobKey = r"cam" ) # - featToMany_ = Dict{Tuple{Symbol,Int},MANYTRACKS}() + featToMany_ = FEATUREMOUNTAIN_DIRDICT() + # featToMany_ = FEATUREMOUNTAIN_DICT() # Dict{Tuple{Symbol,Int},MANYTRACKS}() lastlbl = :null @showprogress "feature pairs" for pair in pairs @@ -282,7 +261,7 @@ end function consolidateFeatureTracks!( - featToMany_::Dict{Tuple{Symbol,Int},MANYTRACKS}, + featToMany_::FEATUREMOUNTAINTYPES, # Dict{Tuple{Symbol,Int},MANYTRACKS}, ) ## find Frame3 options @@ -336,7 +315,7 @@ end function summarizeFeatureTracks!( - featToMany_::Dict{Tuple{Symbol,Int},MANYTRACKS}, + featToMany_::FEATUREMOUNTAINTYPES, # Dict{Tuple{Symbol,Int},MANYTRACKS}, ) ## summarize tracks to start label @@ -396,13 +375,17 @@ end function unionFeatureMountain( - fMa::Dict{Tuple{Symbol,Int},MANYTRACKS}, - fMb::Dict{Tuple{Symbol,Int},MANYTRACKS}, + fMa::FEATUREMOUNTAINTYPES, # Dict{Tuple{Symbol,Int},MANYTRACKS}, + fMb::FEATUREMOUNTAINTYPES, # Dict{Tuple{Symbol,Int},MANYTRACKS}, ) # start with everything from fMb + # FIXME, this deepcopy is going to explode the memory consumption rM = deepcopy(fMb) # then add everything from fMa - for (ka,va) in fMa + + # for (ka,va) in fMa + for ka in keys(fMa) + va = fMa[ka] # @info ka # union if already exists if haskey(rM, ka)