MM4SPA / tvcalib

MIT License
28 stars 11 forks source link

Where can i find extremities_{image_id}.json files? Or how can i produce them? #9

Open LeonardoAcquaroli opened 4 months ago

LeonardoAcquaroli commented 4 months ago

Hello, I'm trying the model on the WC14 dataset, the inference.ipynb works after some changes on my laptop but the pixel2world_homography_example.ipynb does not.

I'm stuck on this cell:


# load annotations from file
file_points_raw = (
    Path(hparams["dataset"]["extremities_annotations"])
    / f'{hparams["dataset"]["extremities_prefix"]}{image_id}.json'
)
if not file_points_raw.exists():
    raise FileNotFoundError(file_points_raw)
with open(file_points_raw) as fr:
    keypoints_raw = json.load(fr)

pixel_stacked = {}
for label, points in keypoints_raw.items():
    points_sel = points
    if len(points_sel) > 0:
        xx = torch.tensor([a["x"] for a in points_sel])
        yy = torch.tensor([a["y"] for a in points_sel])
        pixel_stacked[label] = torch.stack([xx, yy], dim=-1)  # (?, 2)
        # scale pixel annotations from [0, 1] range to source image resolution
        # as this ranges from [1, {image_height, image_width}] shift pixel one left
        pixel_stacked[label][:, 0] = pixel_stacked[label][:, 0] * (1280 - 1)
        pixel_stacked[label][:, 1] = pixel_stacked[label][:, 1] * (720 - 1)
pixels = torch.cat([x for x in pixel_stacked.values()])
print(pixels.shape, pixels.dtype)

torchvision.transforms.functional.to_pil_image(torchvision.utils.draw_keypoints((image * 255.).to(torch.uint8), pixels.unsqueeze(0), colors="blue", radius=5)).resize((320, 180))

The error it returns is:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[30], [line 7](vscode-notebook-cell:?execution_count=30&line=7)
      [2](vscode-notebook-cell:?execution_count=30&line=2) file_points_raw = (
      [3](vscode-notebook-cell:?execution_count=30&line=3)     Path(hparams["dataset"]["extremities_annotations"])
      [4](vscode-notebook-cell:?execution_count=30&line=4)     / f'{hparams["dataset"]["extremities_prefix"]}{image_id}.json'
      [5](vscode-notebook-cell:?execution_count=30&line=5) )
      [6](vscode-notebook-cell:?execution_count=30&line=6) if not file_points_raw.exists():
----> [7](vscode-notebook-cell:?execution_count=30&line=7)     raise FileNotFoundError(file_points_raw)
      [8](vscode-notebook-cell:?execution_count=30&line=8) with open(file_points_raw) as fr:
      [9](vscode-notebook-cell:?execution_count=30&line=9)     keypoints_raw = json.load(fr)

FileNotFoundError: data\segment_localization\np4_nc8_r4_md30\wc14-test\extremities_1.json

I tried to see across all the scripts or the notebooks but still didn't come up with a way to produce the extremities json files, are they to be downloaded?

Thanks in advance for the help and kudos for you great work!

fmagera commented 3 months ago

Hi, I think this is what you're looking for : custom_extremities.py. Cheers!