Downloads · 30 days
0
babmakkah01/babmakkah-test
babmakkah-test is a machine learning model from babmakkah01. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
from transformers import DPTImageProcessor, DPTForDepthEstimation import torch import numpy as np from PIL import Image import requests
Downloads · 30 days
0
Access
Public
Updated Dec 14, 2023
Repo size
—
Likes
0
Public
Click a slice to open those files.
Other1.5 KB · 62%
From the Hugging Face model README
from transformers import DPTImageProcessor, DPTForDepthEstimation import torch import numpy as np from PIL import Image import requests
url = "http://images.cocodataset.org/val2017/000000039769.jpg" image = Image.open(requests.get(url, stream=True).raw)
processor = DPTImageProcessor.from_pretrained("Intel/dpt-large") model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
inputs = processor(images=image, return_tensors="pt")
with torch.no_grad(): outputs = model(**inputs) predicted_depth = outputs.predicted_depth
prediction = torch.nn.functional.interpolate( predicted_depth.unsqueeze(1), size=image.size[::-1], mode="bicubic", align_corners=False, )
output = prediction.squeeze().cpu().numpy() formatted = (output * 255 / np.max(output)).astype("uint8") depth = Image.fromarray(formatted)