text stringlengths 0 184 |
|---|
if dm[st_idx, idx] < 10000: |
matching_list.append(tuple(sorted((st_idx, idx.item())))) |
total+=1 |
matching_list = sorted(list(set(matching_list))) |
return matching_list |
import pycolmap |
print(f"pycolmap version: {pycolmap.__version__}") |
# Collect vital info from the dataset |
@dataclasses.dataclass |
class Prediction: |
image_id: str | None # A unique identifier for the row -- unused otherwise. Used only on the hidden test set. |
dataset: str |
filename: str |
cluster_index: int | None = None |
rotation: np.ndarray | None = None |
translation: np.ndarray | None = None |
# Set is_train=True to run the notebook on the training data. |
# Set is_train=False if submitting an entry to the competition (test data is hidden, and different from what you see on the "test" folder). |
is_train = False |
data_dir = '/kaggle/input/image-matching-challenge-2025' |
workdir = '/kaggle/working/result/' |
os.makedirs(workdir, exist_ok=True) |
if is_train: |
sample_submission_csv = os.path.join(data_dir, 'train_labels.csv') |
else: |
sample_submission_csv = os.path.join(data_dir, 'sample_submission.csv') |
samples = {} |
competition_data = pd.read_csv(sample_submission_csv) |
for _, row in competition_data.iterrows(): |
# Note: For the test data, the "scene" column has no meaning, and the rotation_matrix and translation_vector columns are random. |
if row.dataset not in samples: |
samples[row.dataset] = [] |
samples[row.dataset].append( |
Prediction( |
image_id=None if is_train else row.image_id, |
dataset=row.dataset, |
filename=row.image |
) |
) |
for dataset in samples: |
print(f'Dataset "{dataset}" -> num_images={len(samples[dataset])}') |
import multiprocessing |
import os |
import numpy as np |
import torch |
import matplotlib.pyplot as plt |
import cv2 |
def save_match_viz_image( |
key1, |
key2, |
view1, |
view2, |
matches_im0, |
matches_im1, |
feature_dir, |
n_viz: int = 100 |
): |
""" |
Save a visual match image for a pair of images using descriptor matches. |
Parameters: |
key1, key2: str |
Base filenames of the matched image pair (used for naming the output). |
view1, view2: dict |
MASt3R inference outputs containing 'img' and 'true_shape'. |
matches_im0, matches_im1: np.ndarray of shape (N, 2) |
Coordinates of matched keypoints in image 0 and image 1. |
feature_dir: str |
Path to save the visualized match image. |
n_viz: int |
Number of matches to visualize (default: 100). |
""" |
if matches_im0.shape[0] == 0: |
return # nothing to draw |
n_viz = min(n_viz, matches_im0.shape[0]) |
idx = np.round(np.linspace(0, matches_im0.shape[0] - 1, n_viz)).astype(int) |
viz_matches_im0 = matches_im0[idx] |
viz_matches_im1 = matches_im1[idx] |
image_mean = torch.tensor([0.5, 0.5, 0.5]).reshape(1, 3, 1, 1) |
image_std = torch.tensor([0.5, 0.5, 0.5]).reshape(1, 3, 1, 1) |
viz_imgs = [] |
for view in [view1, view2]: |
rgb_tensor = view['img'].cpu() * image_std + image_mean |
rgb_np = rgb_tensor.squeeze(0).permute(1, 2, 0).clamp(0, 1).numpy() |
viz_imgs.append((rgb_np * 255).astype(np.uint8)) |
H0, W0 = viz_imgs[0].shape[:2] |
H1, W1 = viz_imgs[1].shape[:2] |
img0 = np.pad(viz_imgs[0], ((0, max(H1 - H0, 0)), (0, 0), (0, 0)), 'constant') |
img1 = np.pad(viz_imgs[1], ((0, max(H0 - H1, 0)), (0, 0), (0, 0)), 'constant') |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.