naver / kapture-localization

Provide mapping and localization pipelines based on kapture format
BSD 3-Clause "New" or "Revised" License
269 stars 42 forks source link

accuracy problem at the late fusion step #19

Closed AddASecond closed 3 years ago

AddASecond commented 3 years ago

Question

During reproducing the late fusion step on the Aachen Day-Night v1.1 data set(with 4 global features that kapture provided, AP-GeM-LM18/ DELG/ densevlad_multi/ netvlad_vd16pitts/),I found the accuracy at night is very low compared to the results in the paper.

with gharm Top20 config2, I got

No. day night
mine 90.7 / 97.1 / 99.5 68.6 / 83.8 / 95.8
your paper 90.5 / 96.8 / 99.4 74.9 / 90.1 / 98.4
diff +0.2 / +0.3 / +0.1 -6.3 / - 6.3 / - 2.6

I wonder whether it‘s an implementation problem or is there any other trick?

What did I do:

Step1: use full dataset to construct a single map according to https://github.com/naver/kapture-localization/blob/main/pipeline/examples/run_aachen-v11.sh

Step2: do late fusion using https://github.com/naver/kapture-localization/blob/823f85430c4739b398b5a1cf11ef7d942b0e917d/tools/kapture_image_retrieval_late_fusion.py Since there is no example of fusion script, I wrote one based on my understanding:

`# 0a) Define paths and params PYTHONBIN=python3.8 WORKING_DIR=${PWD} DATASETS_PATH=${WORKING_DIR}/datasets DATASET=Aachen-Day-Night-v1.1 mkdir -p ${DATASETS_PATH}

TOPK=20 # number of retrieved images for mapping and localization KPTS=20000 # number of local features to extract

-gfeat ${WORKING_DIR}/${DATASET}/global_features/AP-GeM-LM18/global_features ${WORKING_DIR}/${DATASET}/global_features/DELG/global_features ${WORKING_DIR}/${DATASET}/global_features/densevlad_multi/global_features ${WORKING_DIR}/${DATASET}/global_features/netvlad_vd16pitts/global_features \

-gfeat ${WORKING_DIR}/${DATASET}/global_features/AP-GeM-LM18 ${WORKING_DIR}/${DATASET}/global_features/DELG ${WORKING_DIR}/${DATASET}/global_features/densevlad_multi ${WORKING_DIR}/${DATASET}/global_features/netvlad_vd16pitts \

1)kapture_image_retrieval_late_fusion

kapture_image_retrieval_late_fusion.py -v debug \ -i ${WORKING_DIR}/${DATASET}/map_plus_query/ \ --query ${WORKING_DIR}/${DATASET}/query/ \ -o ${WORKING_DIR}/${DATASET}/pairs_fusion.txt \ --topk ${TOPK} \ 'generalized_harmonic_mean' --weights 1 1 1 1`

Step3: using the pairs_fusion.txt obtained in step2, I did: `# 0a) Define paths and params PYTHONBIN=python3.8 WORKING_DIR=${PWD} DATASETS_PATH=${WORKING_DIR}/datasets DATASET=Aachen-Day-Night-v1.1 mkdir -p ${DATASETS_PATH}

TOPK=20 # number of retrieved images for mapping and localization KPTS=20000 # number of local features to extract

7) localization pipeline

LOCAL=r2d2_WASF_N8_big GLOBAL=Fusion kapture_pipeline_localize.py -v debug -f \ -s compute_image_pairs compute_matches geometric_verification \ -i ${WORKING_DIR}/${DATASET}/mapping \ --query ${WORKING_DIR}/${DATASET}/query \ -kpt ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/keypoints \ -desc ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/descriptors \ --pairsfile-path ${WORKING_DIR}/${DATASET}/pairs_fusion.txt \ -matches ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/NN_no_gv/matches \ -matches-gv ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/NN_colmap_gv/matches \ --colmap-map ${WORKING_DIR}/${DATASET}/colmap-sfm/${LOCAL}/Resnet101-AP-GeM-LM18 \ -o ${WORKING_DIR}/${DATASET}/colmap-localize/${LOCAL}/${GLOBAL} \ --topk ${TOPK} \ --config 2 `

additional questions:

1.how to correctly use the 'kapture_image_retrieval_late_fusion.py' in step2? I'm very confused especially with the -gfeat parameter; As shown above, what I passed to gfeat can't work properly so I use the default

Thanks in advance

yocabon commented 3 years ago

Hi, I'll answer the additional question since it's probably related to the low results you got. In kapture_image_retrieval_late_fusion.py, -i is the mapping data; not the map_plus_query data.

so in order to make that work, you would use

kapture_create_kapture_proxy.py with

-i ${WORKING_DIR}/${DATASET}/mapping -o ${WORKING_DIR}/${DATASET}/gharm/mapping -gfeat ${WORKING_DIR}/${DATASET}/global_features/AP-GeM-LM18/global_features ${WORKING_DIR}/${DATASET}/global_features/DELG/global_features ${WORKING_DIR}/${DATASET}/global_features/densevlad_multi/global_features ${WORKING_DIR}/${DATASET}/global_features/netvlad_vd16pitts/global_features

(the resulting ${WORKING_DIR}/${DATASET}/gharm/mapping/reconstruction/global_features should have 4 folders)

and

kapture_create_kapture_proxy.py with

-i ${WORKING_DIR}/${DATASET}/query -o ${WORKING_DIR}/${DATASET}/gharm/query -gfeat ${WORKING_DIR}/${DATASET}/global_features/AP-GeM-LM18/global_features ${WORKING_DIR}/${DATASET}/global_features/DELG/global_features ${WORKING_DIR}/${DATASET}/global_features/densevlad_multi/global_features ${WORKING_DIR}/${DATASET}/global_features/netvlad_vd16pitts/global_features

then if you want gharm pairs for mapping (map <-> map -- which we would do unless we built a map with distance or many pairs), you would call

kapture_image_retrieval_late_fusion.py -v debug \
-i ${WORKING_DIR}/${DATASET}/gharm/mapping \
-o ${WORKING_DIR}/${DATASET}/pairs_fusion_mapping.txt \
--topk ${TOPK} generalized_harmonic_mean

and for query -> map pairs

kapture_image_retrieval_late_fusion.py -v debug \
-i ${WORKING_DIR}/${DATASET}/gharm/mapping \
--query ${WORKING_DIR}/${DATASET}/gharm/query \
-o ${WORKING_DIR}/${DATASET}/pairs_fusion_query.txt \
--topk ${TOPK} generalized_harmonic_mean

note that the -gfeat parameter is only here to help you select the global features types you want to use, in this case you would do -gfeat AP-GeM-LM18 DELG netvlad_vd16pitts for example if you didn't want to use netvlad.

I hope this helps.

AddASecond commented 3 years ago

Great ! result improved after fusion, following your script, but at night still remain -2~-3 diff:

No. day night
your paper, fusion 90.5 / 96.8 / 99.4 74.9 / 90.1 / 98.4
fusion during map & query 90.5 / 97.0 / 99.5 72.8 / 86.9 / 98.4
diff +0.0 / +0.2 / +0.1 -2.1 / -3.2 / +0.0
mapping with AP-GeM, fusion at query only 90.7 / 96.7 / 99.5 73.3 / 88.0 / 97.9
diff +0.2 / -0.1 / +0.1 -1.6 / -2.1 / -0.5

Questions:

what caused it? Since the coarse 5m/10 has no diff, is the diff cause by steps after retrieval , such as keypoint/matching/BA? Since I follow the pipeline/example/aachen**.sh, it is a little bit hard for me to immediately figure out

What did I do

after generate pairs file of mapping and query, follow the 6/7 step here https://github.com/naver/kapture-localization/blob/main/pipeline/examples/run_aachen-v11.sh, only change -gfeat to --pairsfile-path

6) mapping pipeline LOCAL=r2d2_WASF_N8_big GLOBAL=Fusion kapture_pipeline_mapping.py -v debug -f \ -i ${WORKING_DIR}/${DATASET}/mapping \ -kpt ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/keypoints \ -desc ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/descriptors \ --pairsfile-path ${WORKING_DIR}/${DATASET}/pairs_fusion_mapping.txt \ -matches ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/NN_no_gv/matches \ -matches-gv ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/NN_colmap_gv/matches \ --colmap-map ${WORKING_DIR}/${DATASET}/colmap-sfm/${LOCAL}/${GLOBAL} \ --topk ${TOPK}

7) localization pipeline LOCAL=r2d2_WASF_N8_big GLOBAL=Fusion kapture_pipeline_localize.py -v debug -f \ -i ${WORKING_DIR}/${DATASET}/mapping \ --query ${WORKING_DIR}/${DATASET}/query \ -kpt ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/keypoints \ -desc ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/descriptors \ --pairsfile-path ${WORKING_DIR}/${DATASET}/pairs_fusion_query.txt \ -matches ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/NN_no_gv/matches \ -matches-gv ${WORKING_DIR}/${DATASET}/local_features/${LOCAL}/NN_colmap_gv/matches \ --colmap-map ${WORKING_DIR}/${DATASET}/colmap-sfm/${LOCAL}/${GLOBAL} \ -o ${WORKING_DIR}/${DATASET}/colmap-localize/${LOCAL}/${GLOBAL} \ --topk ${TOPK} \ --config 2

yocabon commented 3 years ago

with the mapping / localization pipeline, there's some run to run variance. aachen night images have higher variance because there's less of them, and they are harder. The geometric verification step and the final localization step (lo-ransac in colmap) give different results every time you run them, though -2.1 / -3.2 seem a lot.

I don't think there's any difference between what you're running and what we did for the paper.

In my pairsfile, it starts with

query/day/milestone/2010-10-30_17-47-25_73.jpg, db/1356.jpg, 0.13922809252648216
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/71.jpg, 0.13220867963305727
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/70.jpg, 0.12887233625725292
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/4084.jpg, 0.12481698227594262
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/64.jpg, 0.12477330702644496
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/1354.jpg, 0.12371302688386088
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/1334.jpg, 0.12253192928737655
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/65.jpg, 0.12000423719088804
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/2556.jpg, 0.11840915465816204
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/334.jpg, 0.11683821923796689
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/1857.jpg, 0.11071069818545554
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/604.jpg, 0.10891863591822326
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/2548.jpg, 0.10873844898220208
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/2549.jpg, 0.10793434369352062
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/72.jpg, 0.10565871217480893
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/2259.jpg, 0.10440086328152454
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/603.jpg, 0.10273132200898816
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/4085.jpg, 0.09994221752165777
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/1815.jpg, 0.09716742747119145
query/day/milestone/2010-10-30_17-47-25_73.jpg, db/435.jpg, 0.09392194548227684

can you confirm that you obtained the same ?

AddASecond commented 3 years ago

hi yocabon, the day query results images are same, but the scores are not exactly the same.

Since what's cared is night scence, I paste the query_night pairsfile here https://gist.github.com/AddASecond/be321955b207edc40c4a948c5aebf657

which could derive from pairs_fusion_query.txt by sudo cat pairs_fusion_query.txt |grep night >> ./pairs_fusion_query_night.txt

Would you confirm that you obtained the same ? Many Thanks

yocabon commented 3 years ago

They are the same (minus rounding differences) and 5 additional query images on my end (these are not part of the visual localization challenge query list so they do not matter)

query/night/nexus5x_additional_night/IMG_20170702_003519.jpg
query/night/nexus5x_additional_night/IMG_20170702_004734.jpg
query/night/nexus5x_additional_night/IMG_20170702_005427.jpg
query/night/nexus5x_additional_night/IMG_20170702_005557.jpg
query/night/nexus5x_additional_night/IMG_20170702_005615.jpg
AddASecond commented 3 years ago

Well It's a little bit strange that the results keep exactly the same while I re-run the map/localization step in the pipeline(on Aachen 1.1), only the order of pictures is different. Usually there should be some fluctuations because of geometric verification or RANSAC as you mentioned before?

humenbergerm commented 3 years ago

That's really strange and it never happened to us. Are you sure that you use a different output folder for each run or that you delete the last results before a new run?