模型:
vinvino02/glpn-nyu
国际通用本地路径网络(GLPN)模型在NYUv2上进行了微调,用于单目深度估计。该模型由Kim等人在 Global-Local Path Networks for Monocular Depth Estimation with Vertical CutDepth 论文中介绍,并在 this repository 中首次发布。
免责声明:发布GLPN模型的团队未为此模型编写模型卡,因此此模型卡是由Hugging Face团队编写的。
GLPN使用SegFormer作为骨干网络,并在顶部添加了一个轻量级头部用于深度估计。
您可以使用原始模型进行单目深度估计。查看 model hub 以查找您感兴趣的任务的微调版本。
以下是如何使用此模型:
from transformers import GLPNFeatureExtractor, GLPNForDepthEstimation 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) feature_extractor = GLPNFeatureExtractor.from_pretrained("vinvino02/glpn-nyu") model = GLPNForDepthEstimation.from_pretrained("vinvino02/glpn-nyu") # prepare image for the model inputs = feature_extractor(images=image, return_tensors="pt") with torch.no_grad(): outputs = model(**inputs) predicted_depth = outputs.predicted_depth # interpolate to original size prediction = torch.nn.functional.interpolate( predicted_depth.unsqueeze(1), size=image.size[::-1], mode="bicubic", align_corners=False, ) # visualize the prediction output = prediction.squeeze().cpu().numpy() formatted = (output * 255 / np.max(output)).astype("uint8") depth = Image.fromarray(formatted)
有关更多代码示例,请参阅 documentation 。
@article{DBLP:journals/corr/abs-2201-07436, author = {Doyeon Kim and Woonghyun Ga and Pyunghwan Ahn and Donggyu Joo and Sehwan Chun and Junmo Kim}, title = {Global-Local Path Networks for Monocular Depth Estimation with Vertical CutDepth}, journal = {CoRR}, volume = {abs/2201.07436}, year = {2022}, url = {https://arxiv.org/abs/2201.07436}, eprinttype = {arXiv}, eprint = {2201.07436}, timestamp = {Fri, 21 Jan 2022 13:57:15 +0100}, biburl = {https://dblp.org/rec/journals/corr/abs-2201-07436.bib}, bibsource = {dblp computer science bibliography, https://dblp.org} }