Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small bug fixes #79

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions romatch/models/matcher.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import os
import math
import os
import warnings
from warnings import warn

import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
from einops import rearrange
import warnings
from warnings import warn
from PIL import Image

from romatch.utils import get_tuple_transform_ops
from romatch.utils.kde import kde
from romatch.utils.local_correlation import local_correlation
from romatch.utils.utils import cls_to_flow_refine, get_autocast_params
from romatch.utils.kde import kde


class ConvRefiner(nn.Module):
def __init__(
Expand Down Expand Up @@ -654,7 +655,12 @@ def match(
test_transform = get_tuple_transform_ops(
resize=(hs, ws), normalize=True
)
im_A, im_B = test_transform((Image.open(im_A_path).convert('RGB'), Image.open(im_B_path).convert('RGB')))
if isinstance(im_A_path, (str, os.PathLike)):
im_A, im_B = Image.open(im_A_path).convert("RGB"), Image.open(im_B_path).convert("RGB")
else:
im_A, im_B = im_A_path, im_B_path
im_A, im_B = test_transform((im_A, im_B))

im_A, im_B = im_A[None].to(device), im_B[None].to(device)
scale_factor = math.sqrt(self.upsample_res[0] * self.upsample_res[1] / (self.w_resized * self.h_resized))
batch = {"im_A": im_A, "im_B": im_B, "corresps": finest_corresps}
Expand Down
6 changes: 3 additions & 3 deletions romatch/models/model_zoo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union
from typing import Union, Tuple
import torch
from .roma_models import roma_model, tiny_roma_v1_model

Expand Down Expand Up @@ -27,7 +27,7 @@ def tiny_roma_v1_outdoor(device, weights = None, xfeat = None):

return tiny_roma_v1_model(weights = weights, xfeat = xfeat).to(device)

def roma_outdoor(device, weights=None, dinov2_weights=None, coarse_res: Union[int,tuple[int,int]] = 560, upsample_res: Union[int,tuple[int,int]] = 864, amp_dtype: torch.dtype = torch.float16):
def roma_outdoor(device, weights=None, dinov2_weights=None, coarse_res: Union[int,Tuple[int,int]] = 560, upsample_res: Union[int,Tuple[int,int]] = 864, amp_dtype: torch.dtype = torch.float16):
if isinstance(coarse_res, int):
coarse_res = (coarse_res, coarse_res)
if isinstance(upsample_res, int):
Expand All @@ -51,7 +51,7 @@ def roma_outdoor(device, weights=None, dinov2_weights=None, coarse_res: Union[in
print(f"Using coarse resolution {coarse_res}, and upsample res {model.upsample_res}")
return model

def roma_indoor(device, weights=None, dinov2_weights=None, coarse_res: Union[int,tuple[int,int]] = 560, upsample_res: Union[int,tuple[int,int]] = 864, amp_dtype: torch.dtype = torch.float16):
def roma_indoor(device, weights=None, dinov2_weights=None, coarse_res: Union[int,Tuple[int,int]] = 560, upsample_res: Union[int,Tuple[int,int]] = 864, amp_dtype: torch.dtype = torch.float16):
if isinstance(coarse_res, int):
coarse_res = (coarse_res, coarse_res)
if isinstance(upsample_res, int):
Expand Down