Distillanydepth (default)
C++ (Windows, Linux, MacOS / CUDA and Metal accelerated) port of https://github.com/Westlake-AGI-Lab/Distill-Any-Depth.
Example Input & Outputs
Inputs | Outputs |
![]() |
![]() |
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_default_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(
12 DistillAnyDepth_v1_default_v1_ALL_export_version_v17,
13 blace::util::getPathToExe());
14
15 // load image into op
16 auto exe_path = blace::util::getPathToExe();
17 std::filesystem::path photo_path = exe_path / "butterfly.jpg";
18 auto img_op = CONSTRUCT_OP(blace::ops::FromImageFileOp(photo_path.string()));
19
20 // construct model inference arguments
21 blace::ml_core::InferenceArgsCollection infer_args;
22 infer_args.inference_args.device = blace::util::get_accelerator().value();
23
24 // construct inference operation
25 auto infer_op = CONSTRUCT_OP(blace::ops::InferenceOp(
26 DistillAnyDepth_v1_default_v1_ALL_export_version_v17_IDENT, {img_op},
27 infer_args, 0));
28
29 // normalize depth to zero-one range
30 auto result_depth = CONSTRUCT_OP(blace::ops::NormalizeToZeroOneOP(infer_op));
31
32 // construct evaluator and evaluate to cv::Mat
33 blace::computation_graph::GraphEvaluator evaluator(result_depth);
34 auto cv_result = evaluator.evaluateToCVMat().value();
35
36 // multiply for plotting
37 cv_result *= 255.;
38
39 // save to disk and return
40 auto out_file = exe_path / "depth_result.png";
41 cv::imwrite(out_file.string(), cv_result);
42
43 return 0;
44}
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 |