123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include <gflags/gflags.h>
- #include <unistd.h>
- #include <csignal>
- #include <future>
- #include <iostream>
- #include <memory>
- #include <utility>
- #include "cxxutil/log.h"
- #include "detection_runner.h"
- #include "device/mlu_context.h"
- DEFINE_bool(show, false, "show image");
- DEFINE_bool(save_video, true, "save output to local video file");
- DEFINE_int32(repeat_time, 0, "process repeat time");
- DEFINE_string(data_path, "", "video path");
- DEFINE_string(model_path, "", "infer offline model path");
- DEFINE_string(label_path, "", "label path");
- DEFINE_string(func_name, "subnet0", "model function name");
- DEFINE_string(track_model_path, "", "track model path");
- DEFINE_string(track_func_name, "subnet0", "track model function name");
- DEFINE_int32(wait_time, 0, "time of one test case");
- DEFINE_string(net_type, "", "neural network type, SSD or YOLOv3");
- std::shared_ptr<StreamRunner> g_runner;
- bool g_exit = false;
- void HandleSignal(int sig) {
- g_runner->Stop();
- g_exit = true;
- LOGI(SAMPLES) << "Got INT signal, ready to exit!";
- }
- int main(int argc, char** argv) {
- gflags::ParseCommandLineFlags(&argc, &argv, true);
- edk::log::InitLogging(true, true);
-
- CHECK(SAMPLES, FLAGS_data_path. size() != 0u);
- CHECK(SAMPLES, FLAGS_model_path.size() != 0u);
- CHECK(SAMPLES, FLAGS_func_name. size() != 0u);
- CHECK(SAMPLES, FLAGS_label_path.size() != 0u);
- CHECK(SAMPLES, FLAGS_net_type. size() != 0u);
- CHECK(SAMPLES, FLAGS_wait_time >= 0);
- CHECK(SAMPLES, FLAGS_repeat_time >= 0);
- try {
- g_runner = std::make_shared<DetectionRunner>(FLAGS_model_path, FLAGS_func_name, FLAGS_label_path,
- FLAGS_track_model_path, FLAGS_track_func_name,
- FLAGS_data_path, FLAGS_net_type, FLAGS_show, FLAGS_save_video);
- } catch (edk::Exception& e) {
- LOGE(SAMPLES) << "Create stream runner failed" << e.what();
- return -1;
- }
- std::future<bool> process_loop_return = std::async(std::launch::async, &StreamRunner::RunLoop, g_runner.get());
- if (0 < FLAGS_wait_time) {
- alarm(FLAGS_wait_time);
- }
- signal(SIGALRM, HandleSignal);
-
- edk::MluContext context;
- context.SetDeviceId(0);
- context.BindDevice();
- g_runner->DemuxLoop(FLAGS_repeat_time);
- process_loop_return.wait();
- g_runner.reset();
- if (!process_loop_return.get()) {
- return 1;
- }
- LOGI(SAMPLES) << "run stream app SUCCEED!!!" << std::endl;
- edk::log::ShutdownLogging();
- return 0;
- }
|