Scroll Top

Distillanydepth (large)

C++ (Windows, Linux, MacOS / CUDA and Metal accelerated) port of https://github.com/Westlake-AGI-Lab/Distill-Any-Depth.

Example Input & Outputs

Inputs Outputs
Input
Input
Input
Result

Demo Code

 1#include "blace_ai.h"
 2#include <opencv2/opencv.hpp>
 3
 4// include the models you want to use
 5#include "DistillAnyDepth_v1_large_v1_ALL_export_version_v17.h"
 6
 7int main() {
 8  ::blace::workload_management::BlaceWorld blace;
 9
10  // register model at server
11  blace::util::registerModel(DistillAnyDepth_v1_large_v1_ALL_export_version_v17,
12                             blace::util::getPathToExe());
13
14  // load image into op
15  auto exe_path = blace::util::getPathToExe();
16  std::filesystem::path photo_path = exe_path / "manga.png";
17  auto img_op = CONSTRUCT_OP(blace::ops::FromImageFileOp(photo_path.string()));
18
19  // construct model inference arguments
20  blace::ml_core::InferenceArgsCollection infer_args;
21  infer_args.inference_args.device = blace::util::get_accelerator().value();
22
23  // construct inference operation
24  auto infer_op = CONSTRUCT_OP(blace::ops::InferenceOp(
25      DistillAnyDepth_v1_large_v1_ALL_export_version_v17_IDENT, {img_op},
26      infer_args, 0));
27
28  // normalize depth to zero-one range
29  auto result_depth = CONSTRUCT_OP(blace::ops::NormalizeToZeroOneOP(infer_op));
30
31  // construct evaluator and evaluate to cv::Mat
32  blace::computation_graph::GraphEvaluator evaluator(result_depth);
33  auto cv_result = evaluator.evaluateToCVMat().value();
34
35  // multiply for plotting
36  cv_result *= 255.;
37
38  // save to disk and return
39  auto out_file = exe_path / "depth_result.png";
40  cv::imwrite(out_file.string(), cv_result);
41
42  return 0;
43}

Follow the 5 minute instructions to build and run the demo.

Tested on version v0.9.51 of blace.ai sdk. Might also work on newer or older releases (check if release notes of blace.ai state breaking changes).

Artifacts

Payload Demo Project Header

License