Skip to content

Latest commit

ย 

History

History
121 lines (98 loc) ยท 4 KB

intelisl_midas_v2.md

File metadata and controls

121 lines (98 loc) ยท 4 KB
layout background-class body-class category title summary image author tags github-link github-id featured_image_1 featured_image_2 accelerator demo-model-link
hub_detail
hub-background
hub
researchers
MiDaS
MiDaS models for computing relative depth from a single image.
intel-logo.png
Intel ISL
vision
intel-isl/MiDaS
midas_samples.png
no-image
cuda-optional

๋ชจ๋ธ ์„ค๋ช…

MiDaS๋Š” ๋‹จ์ผ ์ด๋ฏธ์ง€๋กœ๋ถ€ํ„ฐ ์ƒ๋Œ€์  ์—ญ ๊นŠ์ด(relative inverse depth)๋ฅผ ๊ณ„์‚ฐํ•ฉ๋‹ˆ๋‹ค. ๋ณธ ์ €์žฅ์†Œ๋Š” ์ž‘์ง€๋งŒ ๊ณ ์†์˜ ๋ชจ๋ธ๋ถ€ํ„ฐ ๊ฐ€์žฅ ๋†’์€ ์ •ํ™•๋„๋ฅผ ์ œ๊ณตํ•˜๋Š” ๋งค์šฐ ํฐ ๋ชจ๋ธ๊นŒ์ง€ ๋‹ค์–‘ํ•œ ์‚ฌ๋ก€๋ฅผ ๋‹ค๋ฃจ๋Š” ์—ฌ๋Ÿฌ ๋ชจ๋ธ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๋ชจ๋ธ์€ ๊ด‘๋ฒ”์œ„ํ•œ ์ž…๋ ฅ์—์„œ ๋†’์€ ํ’ˆ์งˆ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค๋ชฉ์ (multi-objective) ์ตœ์ ํ™”๋ฅผ ์‚ฌ์šฉํ•ด 10๊ฐœ์˜ ๊ฐœ๋ณ„ ๋ฐ์ดํ„ฐ ์…‹์— ๋Œ€ํ•ด ํ›ˆ๋ จ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

์ข…์† ํŒจํ‚ค์ง€ ์„ค์น˜

MiDas ๋ชจ๋ธ์€ timm์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์„ค์น˜ํ•ด ์ฃผ์„ธ์š”.

pip install timm

์‚ฌ์šฉ ์˜ˆ์‹œ

ํŒŒ์ดํ† ์น˜ ํ™ˆํŽ˜์ด์ง€๋กœ๋ถ€ํ„ฐ ์ด๋ฏธ์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค.

import cv2
import torch
import urllib.request

import matplotlib.pyplot as plt

url, filename = ("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
urllib.request.urlretrieve(url, filename)

๋ชจ๋ธ์„ ๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค. (๊ฐœ์š”๋Š” https://github.com/intel-isl/MiDaS/#Accuracy ๋ฅผ ์ฐธ์กฐํ•˜์„ธ์š”.)

model_type = "DPT_Large"     # MiDaS v3 - Large     (highest accuracy, slowest inference speed)
#model_type = "DPT_Hybrid"   # MiDaS v3 - Hybrid    (medium accuracy, medium inference speed)
#model_type = "MiDaS_small"  # MiDaS v2.1 - Small   (lowest accuracy, highest inference speed)

midas = torch.hub.load("intel-isl/MiDaS", model_type)

GPU ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•œ ํ™˜๊ฒฝ์ด๋ผ๋ฉด, ๋ชจ๋ธ์— GPU๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
midas.to(device)
midas.eval()

์—ฌ๋Ÿฌ๊ฐ€์ง€ ๋ชจ๋ธ์— ์ž…๋ ฅํ•  ์ด๋ฏธ์ง€๋ฅผ ํฌ๊ธฐ ๋ณ€๊ฒฝ(resize)์ด๋‚˜ ์ •๊ทœํ™”(normalize)ํ•˜๊ธฐ ์œ„ํ•œ ๋ณ€ํ™˜(transform)์„ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.

midas_transforms = torch.hub.load("intel-isl/MiDaS", "transforms")

if model_type == "DPT_Large" or model_type == "DPT_Hybrid":
    transform = midas_transforms.dpt_transform
else:
    transform = midas_transforms.small_transform

์ด๋ฏธ์ง€๋ฅผ ๋กœ๋“œํ•˜๊ณ  ๋ณ€ํ™˜(transforms)์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค.

img = cv2.imread(filename)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

input_batch = transform(img).to(device)

๊ธฐ์กด ํ•ด์ƒ๋„๋กœ ์˜ˆ์ธก ๋ฐ ํฌ๊ธฐ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

with torch.no_grad():
    prediction = midas(input_batch)

    prediction = torch.nn.functional.interpolate(
        prediction.unsqueeze(1),
        size=img.shape[:2],
        mode="bicubic",
        align_corners=False,
    ).squeeze()

output = prediction.cpu().numpy()

๊ฒฐ๊ณผ ์ถœ๋ ฅ

plt.imshow(output)
# plt.show()

์ฐธ๊ณ ๋ฌธํ—Œ

Towards Robust Monocular Depth Estimation: Mixing Datasets for Zero-shot Cross-dataset Transfer

Vision Transformers for Dense Prediction

๋งŒ์•ฝ MiDaS ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ๋ณธ ๋…ผ๋ฌธ์„ ์ธ์šฉํ•ด ์ฃผ์„ธ์š”:

@article{Ranftl2020,
	author    = {Ren\'{e} Ranftl and Katrin Lasinger and David Hafner and Konrad Schindler and Vladlen Koltun},
	title     = {Towards Robust Monocular Depth Estimation: Mixing Datasets for Zero-shot Cross-dataset Transfer},
	journal   = {IEEE Transactions on Pattern Analysis and Machine Intelligence (TPAMI)},
	year      = {2020},
}
@article{Ranftl2021,
	author    = {Ren\'{e} Ranftl and Alexey Bochkovskiy and Vladlen Koltun},
	title     = {Vision Transformers for Dense Prediction},
	journal   = {ArXiv preprint},
	year      = {2021},
}