test_superpoint_handler.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import numpy as np
  2. import pytest
  3. from superpoint_superglue_deployment import SuperPointHandler
  4. def test_initialization_success():
  5. SuperPointHandler(
  6. {
  7. "use_gpu": False,
  8. "input_shape": (-1, -1),
  9. }
  10. )
  11. def test_initialization_failure():
  12. with pytest.raises(AssertionError):
  13. SuperPointHandler(
  14. {
  15. "use_gpu": False,
  16. "input_shape": (100, 100),
  17. }
  18. )
  19. with pytest.raises(AssertionError):
  20. SuperPointHandler(
  21. {
  22. "use_gpu": False,
  23. "input_shape": (3000, 100),
  24. }
  25. )
  26. def test_inference():
  27. superpoint_handler = SuperPointHandler(
  28. {
  29. "use_gpu": True,
  30. "input_shape": (-1, -1),
  31. "keypoint_threshold": 0.001,
  32. }
  33. )
  34. image = np.random.rand(300, 300) * 255
  35. image = image.astype(np.uint8)
  36. keypoints, _ = superpoint_handler.detect_and_compute(image)
  37. assert len(keypoints) > 0
  38. def test_inference_failure():
  39. superpoint_handler = SuperPointHandler(
  40. {
  41. "use_gpu": True,
  42. "input_shape": (-1, -1),
  43. "keypoint_threshold": 0.001,
  44. }
  45. )
  46. image = np.random.rand(300, 300, 3) * 255
  47. image = image.astype(np.uint8)
  48. with pytest.raises(AssertionError):
  49. superpoint_handler.detect_and_compute(image)