Datasets:

Modalities:
Video
Audio
Languages:
English
ArXiv:
License:
File size: 1,399 Bytes
f89df01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import cv2
import torch
import numpy as np
from torch import Tensor
import torch.nn.functional as F

from imantics import Mask
from typing import List



def convert_ann_to_mask(ann: List, height: int, width: int):
    mask = np.zeros((height, width), dtype=np.uint8)
    poly = ann["segmentation"]
    
    for p in poly:
        p = np.array(p).reshape(-1, 2).astype(int)
        cv2.fillPoly(mask, [p], 1)
    return mask


def convert_mask_to_ann(mask: np.ndarray):
    polygons = Mask(mask).polygons()
    return polygons.segmentation


# Define a custom argument type for a list of strings
def list_of_strings(arg):
    return [float(thr) for thr in arg.split(',')]


def video_interpolation(video: Tensor, frame_sample_rate: int):
    expanded_heatmap = []
    for i in range(len(video) - 1):
        pre_heatmap, post_heatmap = video[i], video[i + 1]
        
        for j in range(frame_sample_rate):
            interpolated_heatmap = ((frame_sample_rate - j) / frame_sample_rate) * pre_heatmap \
                + (j / frame_sample_rate) * post_heatmap
            expanded_heatmap.append(interpolated_heatmap)
    expanded_heatmap.append(video[-1])
    return torch.stack(expanded_heatmap).unsqueeze(1)



def heatmap_interpolation(heatmap: Tensor, height: int, width: int):
    return F.interpolate(heatmap, size=(height, width), mode='bilinear', align_corners=False).squeeze().numpy()