Skip to content

Commit

Permalink
[Feature] Enable Depth-Anything model prediction with color and grays…
Browse files Browse the repository at this point in the history
…cale rendering modes
  • Loading branch information
CVHub520 committed Jul 26, 2024
1 parent bbab395 commit 837a642
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type: depth_anything_v2
name: depth_anything_v2_vit_b-r20240721
display_name: Depth Anything V2 (ViT-Base)
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.4.0/depth_anything_v2_vitb.onnx
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.4.0/depth_anything_v2_vitb.onnx
render_mode: color # 'color' or 'gray'
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type: depth_anything_v2
name: depth_anything_v2_vit_l-r20240721
display_name: Depth Anything V2 (ViT-Large)
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.4.0/depth_anything_v2_vitl.onnx
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.4.0/depth_anything_v2_vitl.onnx
render_mode: color # 'color' or 'gray'
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type: depth_anything_v2
name: depth_anything_v2_vit_s-r20240721
display_name: Depth Anything V2 (ViT-Small)
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.4.0/depth_anything_v2_vits.onnx
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.4.0/depth_anything_v2_vits.onnx
render_mode: color # 'color' or 'gray'
3 changes: 2 additions & 1 deletion anylabeling/configs/auto_labeling/depth_anything_vit_b.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type: depth_anything
name: depth_anything_vit_b-r20240124
display_name: Depth Anything (ViT-Base)
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.3.1/depth_anything_vitb14.onnx
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.3.1/depth_anything_vitb14.onnx
render_mode: color # 'color' or 'gray'
3 changes: 2 additions & 1 deletion anylabeling/configs/auto_labeling/depth_anything_vit_l.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type: depth_anything
name: depth_anything_vit_l-r20240124
display_name: Depth Anything (ViT-Large)
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.3.1/depth_anything_vitl14.onnx
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.3.1/depth_anything_vitl14.onnx
render_mode: color # 'color' or 'gray'
3 changes: 2 additions & 1 deletion anylabeling/configs/auto_labeling/depth_anything_vit_s.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type: depth_anything
name: depth_anything_vit_s-r20240124
display_name: Depth Anything (ViT-Small)
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.3.1/depth_anything_vits14.onnx
model_path: https://github.com/CVHub520/X-AnyLabeling/releases/download/v2.3.1/depth_anything_vits14.onnx
render_mode: color # 'color' or 'gray'
6 changes: 4 additions & 2 deletions anylabeling/services/auto_labeling/depth_anything.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def __init__(self, model_config, on_message) -> None:
)
self.net = OnnxBaseModel(model_abs_path, __preferred_device__)
self.input_shape = self.net.get_input_shape()[-2:]
self.render_mode = self.config.get("render_mode", "color")

def preprocess(self, input_image):
"""
Expand Down Expand Up @@ -298,8 +299,9 @@ def postprocess(self, outputs, orig_shape):
depth = cv2.resize(outputs[0, 0], (orig_w, orig_h))
depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0
depth = depth.astype(np.uint8)
depth_color = cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO)
return depth_color
if self.render_mode == "color":
return cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO)
return depth

def predict_shapes(self, image, image_path=None):
"""
Expand Down
7 changes: 4 additions & 3 deletions anylabeling/services/auto_labeling/depth_anything_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os

import cv2
import numpy as np
from PyQt5.QtCore import QCoreApplication

from anylabeling.app_info import __preferred_device__
Expand Down Expand Up @@ -43,6 +42,7 @@ def __init__(self, model_config, on_message) -> None:
self.model_path = model_abs_path
self.net = OnnxBaseModel(model_abs_path, )
self.input_shape = self.net.get_input_shape()[-2:]
self.render_mode = self.config.get("render_mode", "color")
self.device = "cuda" if __preferred_device__ == "GPU" else "cpu"

def preprocess(self, input_image):
Expand Down Expand Up @@ -88,8 +88,9 @@ def postprocess(self, depth, orig_shape):
depth = (depth - depth.min()) / (depth.max() - depth.min()) * 255.0
depth = depth.transpose(1, 2, 0).astype("uint8")
depth = cv2.resize(depth, (orig_w, orig_h), interpolation=cv2.INTER_CUBIC)
depth_color = cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO)
return depth_color
if self.render_mode == "color":
return cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO)
return depth

def predict_shapes(self, image, image_path=None):
"""
Expand Down

0 comments on commit 837a642

Please sign in to comment.