GrumpyZhou / image-matching-toolbox

This is a toolbox repository to help evaluate various methods that perform image matching from a pair of images.
MIT License
543 stars 80 forks source link

A request for help when testing Hpatch `ValueError: zero-size array to reduction operation minimum which has no identity` #9

Closed GabbySuwichaya closed 3 years ago

GabbySuwichaya commented 3 years ago

Hi!

Thank you so much for releasing this toolbox and for the awesome paper on Patch2Pix. Here, I would like to kindly ask for your help.

I have tried to run your example for Patch2Pix and another one of SuperPoint + NCNet ...

The following code lines are in ./test_patch3pix.sh...

python -m immatch.eval_hpatches --gpu 0 \
    --config 'patch2pix' --match_thres 0.25 0.5 0.9  \
    --task 'both' --save_npy \
    --root_dir . 

However, I keep getting following error ValueError: zero-size array to reduction operation minimum which has no identity ... I am not sure how to fix it. So, please give the guidance...

Below here is the full error report.

Also, I have captured the screen to confirm at the bottom to confirm

(immatch) gabby-suwichaya@gabby-suwichaya:/mnt/HDD4TB1/image-matching-toolbox$ ./test_patch3pix.sh Can not import sparsencnet

>>>> Method=Patch2Pix Default config: {'class': 'Patch2Pix', 'ckpt': 'pretrained/patch2pix/patch2pix_pretrained.pth', 'ksize': 2, 'imsize': 1024, 'match_threshold': 0.25} Thres: [0.25, 0.5, 0.9]

Load model method:patch2pix 
Ckpt:pretrained/patch2pix/patch2pix_pretrained.pth
Initialize Patch2Pix: backbone=ResNet34 cstride=True upsample=8
Init regressor Namespace(conv_dims=[512, 512], conv_kers=[3, 3], conv_strs=[2, 1], fc_dims=[512, 256], feat_comb='pre', feat_dim=259, panc=1, pshift=8, psize=[16, 16], shared=False)
FeatRegressNet:  feat_comb:pre psize:16 out:5 feat_dim:518 conv_kers:[3, 3] conv_dims:[512, 512] conv_str:[2, 1] 
FeatRegressNet:  feat_comb:pre psize:16 out:5 feat_dim:518 conv_kers:[3, 3] conv_dims:[512, 512] conv_str:[2, 1] 
Xavier initialize all model parameters
Initialize ResNet using pretrained model from https://download.pytorch.org/models/resnet34-333f7ec4.pth
Reload all model parameters from weights dict
Initialize Patch2Pix
Matching thres: 0.25  Save to: ./outputs/hpatches/cache/Patch2Pix.im1024.m0.25.npy

>>Eval hpatches: method=Patch2Pix rthres=2 thres=[1, 3, 5, 10] 
Save results to ./outputs/hpatches/cache/Patch2Pix.im1024.m0.25.npy
/home/gabby-suwichaya/anaconda3/envs/immatch/lib/python3.7/site-packages/numpy/core/fromnumeric.py:3441: RuntimeWarning: Mean of empty slice.
  out=out, **kwargs)
/home/gabby-suwichaya/anaconda3/envs/immatch/lib/python3.7/site-packages/numpy/core/_methods.py:189: RuntimeWarning: invalid value encountered in double_scalars
  ret = ret.dtype.type(ret / rcount)
Traceback (most recent call last):
  File "/home/gabby-suwichaya/anaconda3/envs/immatch/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/gabby-suwichaya/anaconda3/envs/immatch/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/mnt/HDD4TB1/image-matching-toolbox/immatch/eval_hpatches.py", line 98, in <module>
    print_out=args.print_out
  File "/mnt/HDD4TB1/image-matching-toolbox/immatch/eval_hpatches.py", line 74, in eval_hpatches
    save_npy=result_npy
  File "/mnt/HDD4TB1/image-matching-toolbox/immatch/utils/hpatches_helper.py", line 323, in eval_hpatches
    lprint_(eval_summary(results, thres, save_npy=save_npy))
  File "/mnt/HDD4TB1/image-matching-toolbox/immatch/utils/hpatches_helper.py", line 28, in eval_summary
    summary += '# Features: mean={:.0f} min={:d} max={:d}\n'.format(np.mean(n_feats), np.min(n_feats), np.max(n_feats))
  File "<__array_function__ internals>", line 6, in amin
  File "/home/gabby-suwichaya/anaconda3/envs/immatch/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 2880, in amin
    keepdims=keepdims, initial=initial, where=where)
  File "/home/gabby-suwichaya/anaconda3/envs/immatch/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 86, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
ValueError: zero-size array to reduction operation minimum which has no identity

demo_problem

GrumpyZhou commented 3 years ago

Hi @GabbySuwichaya !

For faster debugging, I used superpoint since it runs fastest when one has a gpu. I ran the following command:

# Turn on --print_out to see each sample results
python -m immatch.eval_hpatches --gpu 0 \
    --config 'superpoint' --task 'both' \
    --root_dir . --print_out

And here are the console outputs:

debug_1

... (skip intermediate results)

image

So to figure out why you have that problem, you can do:

  1. Check whether your dataset are setup correctly: it should be placed as 'data/datasets/hpatches-sequences-release'
  2. Run this notebook from your local to see whether the repository is properly setup. If not, make sure you didn't miss anything in the readme.
  3. Run the command i posted for hpatch, and post the output here, if 1 & 2 didn't solve your problem.
GabbySuwichaya commented 3 years ago

Thanks! I found the error now, and the problem is solved. It was the directly of the HPatches data...

Here I would like to kindly ask one more question... There is a line which said Cannot import sparsencnet ...

Could you please guide me what causes this line... ? I am very sorry I am not very familiar with the code... Also should I try to solve it?

demo_2

GrumpyZhou commented 3 years ago

Hi @GabbySuwichaya ,

That line will appear when your environment doesn't contain MinkowskiEngine which is required by SparseNCNet. This is explained in install.md. So don't worry about it. It's expected to be there unless you want to run SparseNcNet, for which you need to follow the install.md.

GabbySuwichaya commented 3 years ago

Hi @GrumpyZhou,

Thanks so much for this. Yes, I will fix the problem accordingly. :)