Skip to content
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

switch feature mountain tracker to FolderDict #1008

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions ext/CaesarImagesExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
51 changes: 17 additions & 34 deletions ext/Images/FeatureMountain.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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])
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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])
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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])
Expand All @@ -169,7 +148,6 @@ function addFeatureTracks_Frame2_QbckR!(
end

return featToMany
# return mountain
end

# # require both forward and backward tracks to coincide
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -282,7 +261,7 @@ end


function consolidateFeatureTracks!(
featToMany_::Dict{Tuple{Symbol,Int},MANYTRACKS},
featToMany_::FEATUREMOUNTAINTYPES, # Dict{Tuple{Symbol,Int},MANYTRACKS},
)
## find Frame3 options

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @Affie , this may be part of the memory use issue. This PR will help some, and we can refactor more in a follow-up PR.

# 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)
Expand Down
Loading