File size: 637 Bytes
cacb27a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.

# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

import cv2
import h5py

import torch


def read_h5py(filename):
    with h5py.File(filename, "r") as f:
        data = torch.tensor(f['dataset'][:], dtype=torch.float32)
    return data


def read_img(frame_path):
    for retry in range(100):
        img = cv2.imread(frame_path)
        if img is not None:
            return torch.tensor(img / 255.0, dtype=torch.float32)[..., [2, 1, 0]]
        print('retry loading', retry, frame_path)