/* * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * SPDX-License-Identifier: Apache-2.0 */ #include "trtmc/runtime/family_loader.h" #include #include #include #include #include #include int main(int argc, char** argv) { try { if (argc != 5) throw std::invalid_argument("usage: zoedepth_e2e BUNDLE RUNTIME_ROOT INPUTS_JSON OUTPUT_DIRECTORY"); std::ifstream input(argv[3]); const auto requests = nlohmann::json::parse(input); auto model = trtmc::load_task(argv[1], argv[2]); auto* task = dynamic_cast(model.get()); if (!task) throw std::runtime_error("zoedepth does not implement IMonocularDepth"); nlohmann::json results = nlohmann::json::array(); std::vector first, first_pixels; int first_h = 0, first_w = 0; for (const auto& request : requests) { const int h = request.at("height"), w = request.at("width"); if (h < 2 || w < 2 || h > 8192 || w > 8192) throw std::invalid_argument("invalid fixture geometry"); std::vector pixels(static_cast(h) * w * 3); std::ifstream source(request.at("file").get(), std::ios::binary); source.read(reinterpret_cast(pixels.data()), pixels.size() * sizeof(float)); if (!source) throw std::runtime_error("cannot read RGB fixture"); auto result = task->estimate_depth(pixels.data(), h, w); if (result.height != h || result.width != w || result.depth.size() != static_cast(h) * w) throw std::runtime_error("zoedepth returned invalid metric map geometry"); if (results.empty()) { first = result.depth; first_pixels = pixels; first_h = h; first_w = w; } const auto name = "depth-" + std::to_string(results.size()) + ".f32"; std::ofstream output(std::filesystem::path(argv[4]) / name, std::ios::binary); output.write(reinterpret_cast(result.depth.data()), result.depth.size() * sizeof(float)); if (!output) throw std::runtime_error("cannot save native depth map"); results.push_back({{"file", name}, {"height", h}, {"width", w}}); } for (int mode = 0; mode < 5; ++mode) { auto pixels = first_pixels; if (mode == 2) pixels[0] = std::numeric_limits::quiet_NaN(); if (mode == 3) pixels[0] = -0.1F; bool rejected = false; try { if (mode == 0) task->estimate_depth(nullptr, first_h, first_w); else if (mode == 1) task->estimate_depth(pixels.data(), 0, first_w); else if (mode == 4) { std::vector square(64 * 64 * 3); task->estimate_depth(square.data(), 64, 64); } else task->estimate_depth(pixels.data(), first_h, first_w); } catch (const std::exception&) { rejected = true; } if (!rejected) throw std::runtime_error("zoedepth accepted an invalid image"); } if (task->estimate_depth(first_pixels.data(), first_h, first_w).depth != first) throw std::runtime_error("zoedepth state leaked after rejected input"); std::cout << results.dump() << '\n'; return 0; } catch (const std::exception& error) { std::cerr << error.what() << '\n'; return 1; } }