#include #include #include #include #include #include void MIGraphXSamplesUsage(char* programName) { printf("Usage : %s \n", programName); printf("index:\n"); printf("\t 0) YOLOX sample.\n"); // printf("\t 1) YOLOX Dynamic sample.\n"); 暂不支持 } void Sample_YOLOX(); void Sample_YOLOX_Dynamic(); int main(int argc, char *argv[]) { if (argc < 2 || argc > 2) { MIGraphXSamplesUsage(argv[0]); return -1; } if (!strncmp(argv[1], "-h", 2)) { MIGraphXSamplesUsage(argv[0]); return 0; } switch (*argv[1]) { case '0': { Sample_YOLOX(); break; } case '1': { // Sample_YOLOX_Dynamic(); 暂不支持 break; } default : { MIGraphXSamplesUsage(argv[0]); break; } } return 0; } void Sample_YOLOX() { // 创建YOLOX检测器 migraphxSamples::DetectorYOLOX detector; migraphxSamples::InitializationParameterOfDetector initParamOfDetectorYOLOX; initParamOfDetectorYOLOX.configFilePath = CONFIG_FILE; migraphxSamples::ErrorCode errorCode=detector.Initialize(initParamOfDetectorYOLOX, false); if(errorCode!=migraphxSamples::SUCCESS) { LOG_ERROR(stdout, "fail to initialize detector!\n"); exit(-1); } LOG_INFO(stdout, "succeed to initialize detector\n"); // 读取测试图片 cv::Mat srcImage = cv::imread("../Resource/Images/image_test.jpg",1); // 静态推理固定尺寸 std::vector inputShape={1,3,640,640}; // 推理 std::vector predictions; double time1 = cv::getTickCount(); detector.Detect(srcImage,inputShape,predictions,false); double time2 = cv::getTickCount(); double elapsedTime = (time2 - time1)*1000 / cv::getTickFrequency(); LOG_INFO(stdout, "inference time:%f ms\n", elapsedTime); // 获取推理结果 LOG_INFO(stdout,"========== Detection Results ==========\n"); for(int i=0;i srcImages; cv::String folder = "../Resource/Images/DynamicPics"; std::vector imagePathList; cv::glob(folder,imagePathList); for (int i = 0; i < imagePathList.size(); ++i) { cv:: Mat srcImage=cv::imread(imagePathList[i], 1); srcImages.push_back(srcImage); } // 设置动态推理shape std::vector> inputShapes; inputShapes.push_back({1,3,416,416}); inputShapes.push_back({1,3,608,608}); for (int i = 0; i < srcImages.size(); ++i) { // 推理 std::vector predictions; double time1 = cv::getTickCount(); detector.Detect(srcImages[i], inputShapes[i], predictions, true); double time2 = cv::getTickCount(); double elapsedTime = (time2 - time1)*1000 / cv::getTickFrequency(); LOG_INFO(stdout, "inference image%d time:%f ms\n", i, elapsedTime); // 获取推理结果 LOG_INFO(stdout,"========== Detection Image%d Results ==========\n", i); for(int j=0;j