Spaces:
Running
Running
Download utils/depth_utils.py from umaradnaan/Vid2ShapeAI: direct link, hf CLI and curl.
- Browser
- Download file 659 Bytes
-
https://huggingface.co/spaces/umaradnaan/Vid2ShapeAI/resolve/main/utils/depth_utils.py
- Command line
-
hf download hf://spaces/umaradnaan/Vid2ShapeAI/utils/depth_utils.py
-
curl -L -o depth_utils.py https://huggingface.co/spaces/umaradnaan/Vid2ShapeAI/resolve/main/utils/depth_utils.py
659 Bytes
| import torch | |
| import cv2 | |
| from transformers import DPTFeatureExtractor, DPTForDepthEstimation | |
| extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large") | |
| model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large") | |
| model.eval() | |
| def estimate_depth(frame_paths): | |
| depth_maps = [] | |
| for path in frame_paths: | |
| image = cv2.imread(path) | |
| image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | |
| inputs = extractor(images=image, return_tensors="pt") | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| depth = outputs.predicted_depth[0].cpu().numpy() | |
| depth_maps.append(depth) | |
| return depth_maps | |