cvg / LightGlue

LightGlue: Local Feature Matching at Light Speed (ICCV 2023)
Apache License 2.0
3.41k stars 336 forks source link

Cannot run the demo.ipynb #135

Open dengxiongshi opened 2 months ago

dengxiongshi commented 2 months ago

Hello, enveryone! When I run the demo.py, I got the error:

import sys; print('Python %s on %s' % (sys.version, sys.platform))
sys.path.extend(['D:\\python_work\\ImageFusion\\ImageRegistration\\LightGlue', 'D:/python_work/ImageFusion/ImageRegistration/LightGlue'])
Python 3.8.18 (default, Sep 11 2023, 13:39:12) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.3 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 8.12.3
Python 3.8.18 (default, Sep 11 2023, 13:39:12) [MSC v.1916 64 bit (AMD64)] on win32
runfile('D:/python_work/ImageFusion/ImageRegistration/LightGlue/demo.py', wdir='D:/python_work/ImageFusion/ImageRegistration/LightGlue')
*** Aborted at 1726733700 (unix time) try "date -d @1726733700" if you are using GNU date ***
    @     0x7ffc1f680ef5 _seh_filter_exe
    @     0x7ff694f52698 OPENSSL_Applink
    @     0x7ffbfe40e390 __C_specific_handler
    @     0x7ffc218d292f __chkstk
    @     0x7ffc21882554 RtlRaiseException
    @     0x7ffc218d143e KiUserExceptionDispatcher
    @     0x7ffbd6f226de void __cdecl __ExceptionPtrRethrow(void const * __ptr64)
    @     0x7ffb50495a7f (unknown)
    @     0x7ffb504b55af public: virtual char const * __ptr64 __cdecl pybind11::error_already_set::what(void)const __ptr64
    @     0x7ffb83a1de25 (unknown)
    @     0x7ffb83f791a9 PyInit_pycolmap
    @     0x7ffbd9851080 (unknown)
    @     0x7ffbd98526a5 __NLG_Return2
    @     0x7ffc218d1c96 RtlCaptureContext2
    @     0x7ffb83a20914 (unknown)
    @     0x7ffbce9b6f60 _PyMethodDef_RawFastCallKeywords
    @     0x7ffbce9b5f26 _PyObject_MakeTpCall
    @     0x7ffbce9c266b PyWrapper_New
    @     0x7ffbce9fe34a _PyObject_GenericGetAttrWithDict
    @     0x7ffbce9fd939 PyObject_GetAttrString
    @     0x7ffb83a568be PyInit_pycolmap
    @     0x7ffb83ab0bf6 PyInit_pycolmap
    @     0x7ffb83a87e7d PyInit_pycolmap
    @     0x7ffb83a450c0 (unknown)
    @     0x7ffb83a51b78 PyInit_pycolmap
    @     0x7ffb83a5167e PyInit_pycolmap
    @     0x7ffbceac21cd PyImport_AppendInittab
    @     0x7ffbceac1896 PyImport_Import
    @     0x7ffbce9f94b5 _PyCFunction_DebugMallocStats
    @     0x7ffbce9b606e PyVectorcall_Call
    @     0x7ffbcea93a20 PyEval_GetFuncDesc
    @     0x7ffbcea90571 _PyEval_EvalFrameDefault
Process finished with exit code 3

The is my code:

from pathlib import Path
import torch

from lightglue import LightGlue, SuperPoint
from lightglue.utils import load_image, rbd, match_pair
from lightglue import viz2d

torch.set_grad_enabled(False)
images = Path("assets")

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")  # 'mps', 'cpu'

extractor = SuperPoint(max_num_keypoints=2048).eval().to(device)  # load the extractor
matcher = LightGlue(features="superpoint").eval().to(device)

image0 = load_image(images / "DSC_0411.JPG")
image1 = load_image(images / "DSC_0410.JPG")

feats0 = extractor.extract(image0.to(device))
feats1 = extractor.extract(image1.to(device))
matches01 = matcher({"image0": feats0, "image1": feats1})
feats0, feats1, matches01 = [
    rbd(x) for x in [feats0, feats1, matches01]
]  # remove batch dimension

kpts0, kpts1, matches = feats0["keypoints"], feats1["keypoints"], matches01["matches"]
m_kpts0, m_kpts1 = kpts0[matches[..., 0]], kpts1[matches[..., 1]]

axes = viz2d.plot_images([image0, image1])
viz2d.plot_matches(m_kpts0, m_kpts1, color="lime", lw=0.2)
viz2d.add_text(0, f'Stop after {matches01["stop"]} layers', fs=20)

kpc0, kpc1 = viz2d.cm_prune(matches01["prune0"]), viz2d.cm_prune(matches01["prune1"])
viz2d.plot_images([image0, image1])
viz2d.plot_keypoints([kpts0, kpts1], colors=[kpc0, kpc1], ps=10)

feats0, feats1, matches01 = match_pair(extractor, matcher, image0, image1)

The environment is: torch==1.9.1+cu111 image