Spaces:
Runtime error
Runtime error
Download depth_estimator.py from limingcv/ControlNet-Plus-Plus: direct link, hf CLI and curl.
- Browser
- Download file 842 Bytes
-
https://huggingface.co/spaces/limingcv/ControlNet-Plus-Plus/resolve/89efab88c7b1d2179eb6ab58c4000009a2044334/depth_estimator.py
- Command line
-
hf download hf://spaces/limingcv/ControlNet-Plus-Plus@89efab88c7b1d2179eb6ab58c4000009a2044334/depth_estimator.py
-
curl -L -o depth_estimator.py https://huggingface.co/spaces/limingcv/ControlNet-Plus-Plus/resolve/89efab88c7b1d2179eb6ab58c4000009a2044334/depth_estimator.py
842 Bytes
| import numpy as np | |
| import PIL.Image | |
| from controlnet_aux.util import HWC3 | |
| from transformers import pipeline | |
| from cv_utils import resize_image | |
| class DepthEstimator: | |
| def __init__(self): | |
| self.model = pipeline('depth-estimation') | |
| def __call__(self, image: np.ndarray, **kwargs) -> PIL.Image.Image: | |
| detect_resolution = kwargs.pop('detect_resolution', 512) | |
| image_resolution = kwargs.pop('image_resolution', 512) | |
| image = np.array(image) | |
| image = HWC3(image) | |
| image = resize_image(image, resolution=detect_resolution) | |
| image = PIL.Image.fromarray(image) | |
| image = self.model(image) | |
| image = image['depth'] | |
| image = np.array(image) | |
| image = HWC3(image) | |
| image = resize_image(image, resolution=image_resolution) | |
| return PIL.Image.fromarray(image) | |