Improve model card: pipeline tag, library name, and usage example

#1
by nielsr HF Staff - opened
Files changed (1) hide show
  1. README.md +45 -5
README.md CHANGED
@@ -1,11 +1,12 @@
1
  ---
 
 
 
 
 
2
  tags:
3
  - model_hub_mixin
4
  - pytorch_model_hub_mixin
5
- license: cc-by-nc-4.0
6
- language:
7
- - en
8
- pipeline_tag: other
9
  ---
10
 
11
  <div align="center">
@@ -25,7 +26,7 @@ pipeline_tag: other
25
 
26
  ## Overview
27
 
28
- UFM(UniFlowMatch) is a simple, end-to-end trained transformer model that directly regresses pixel displacement image that applies concurrently to both optical flow and wide-baseline matching tasks.
29
 
30
  This model space contains the refine model.
31
 
@@ -33,6 +34,45 @@ This model space contains the refine model.
33
 
34
  Check out our [Github Repo](https://github.com/UniFlowMatch/UFM) and the hugging face [demo](https://huggingface.co/spaces/infinity1096/UFM).
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  ## Citation
38
  If you find our repository useful, please consider giving it a star ⭐ and citing our paper in your work:
 
1
  ---
2
+ language:
3
+ - en
4
+ license: cc-by-nc-4.0
5
+ pipeline_tag: image-to-image
6
+ library_name: pytorch
7
  tags:
8
  - model_hub_mixin
9
  - pytorch_model_hub_mixin
 
 
 
 
10
  ---
11
 
12
  <div align="center">
 
26
 
27
  ## Overview
28
 
29
+ UFM(UniFlowMatch) is a simple, end-to-end trained transformer model that directly regresses pixel displacement image that applies concurrently to both optical flow and wide-baseline matching tasks.
30
 
31
  This model space contains the refine model.
32
 
 
34
 
35
  Check out our [Github Repo](https://github.com/UniFlowMatch/UFM) and the hugging face [demo](https://huggingface.co/spaces/infinity1096/UFM).
36
 
37
+ ### Python API
38
+
39
+ ```python
40
+ import cv2
41
+ import torch
42
+
43
+ # Load the base model (for general use)
44
+ from uniflowmatch.models.ufm import UniFlowMatchConfidence
45
+ model = UniFlowMatchConfidence.from_pretrained("infinity1096/UFM-Base")
46
+
47
+ # Or load the refinement model (for higher accuracy)
48
+ from uniflowmatch.models.ufm import UniFlowMatchClassificationRefinement
49
+ model = UniFlowMatchClassificationRefinement.from_pretrained("infinity1096/UFM-Refine")
50
+
51
+ # Set the model to evaluation mode
52
+ model.eval()
53
+
54
+ # Load images using cv2 or PIL
55
+ source_image = cv2.imread("path/to/source.jpg")
56
+ target_image = cv2.imread("path/to/target.jpg")
57
+ source_rgb = cv2.cvtColor(source_image, cv2.COLOR_BGR2RGB) # Convert to RGB
58
+ target_rgb = cv2.cvtColor(target_image, cv2.COLOR_BGR2RGB) # Convert to RGB
59
+
60
+ # Convert to torch tensors (uint8 or float32)
61
+ # Forward call takes care of normalizing uint8 images appropriate to the UFM model
62
+ source_image = torch.from_numpy(source_rgb) # Shape: (H, W, 3)
63
+ target_image = torch.from_numpy(target_rgb) # Shape: (H, W, 3)
64
+
65
+ # Predict correspondences
66
+ with torch.no_grad():
67
+ result = model.predict_correspondences_batched(
68
+ source_image=source_image,
69
+ target_image=target_image,
70
+ )
71
+
72
+ flow = result.flow.flow_output[0].cpu().numpy()
73
+ covisibility = result.covisibility.mask[0].cpu().numpy()
74
+ ```
75
+
76
 
77
  ## Citation
78
  If you find our repository useful, please consider giving it a star ⭐ and citing our paper in your work: