| 73 | } |
| 74 | |
| 75 | int main() |
| 76 | { |
| 77 | //float tt[20] = { 0.4928, 0.2981, 0.1731, 0.4038, 17.0000,0.3317, 0.7163, 0.5673, 0.2548, 0.0000,0.8714, |
| 78 | //0.8125, 0.1370, 0.2308, 14.0000,0.6250, 0.6202, 0.0144, 0.0240, 14.0000 }; |
| 79 | //auto targets = torch::from_blob(tt, { 4,5 }, torch::TensorOptions(torch::kFloat32)); |
| 80 | |
| 81 | //float anchor[12] = { 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 }; |
| 82 | //auto anchors_ = torch::from_blob(anchor, { 6,2 }, torch::TensorOptions(torch::kFloat32)).to(torch::Device(torch::kCUDA)); |
| 83 | //int image_size[2] = { 416, 416 }; |
| 84 | |
| 85 | //bool normalize = false; |
| 86 | //auto critia1 = YOLOLossImpl(anchors_, 20, image_size, 0.01, torch::Device(torch::kCUDA), normalize); |
| 87 | |
| 88 | //auto output = torch::ones({ 1,75,13,13 }, torch::kFloat).to(torch::Device(torch::kCUDA)); |
| 89 | ////auto tmp = torch::tensor({ 0.2, 0.2, 0.3, 0.3, 1.0 }, torch::kFloat).unsqueeze(0).to(torch::Device(torch::kCUDA)); |
| 90 | ////std::cout << tmp.sizes(); |
| 91 | //std::vector<torch::Tensor> targets_vec = { targets }; |
| 92 | //auto loss_numpos1 = critia1.forward(output, targets_vec); |
| 93 | //std::cout << loss_numpos1[0]; |
| 94 | |
| 95 | |
| 96 | |
| 97 | cv::Mat image = cv::imread("D:\\AllentFiles\\data\\dataset4work\\detection\\val\\images\\2007_005331.jpg"); |
| 98 | Detector detector; |
| 99 | detector.Initialize(-1, 416, 416, "D:\\AllentFiles\\data\\dataset4work\\detection\\name.txt"); |
| 100 | //detector.Train("D:\\AllentFiles\\data\\dataset4work\\detection", ".jpg", 30, |
| 101 | // 4, 0.001, "weights/detector.pt", "weights/yolo4_tiny.pt"); |
| 102 | |
| 103 | detector.LoadWeight("weights/detector.pt"); |
| 104 | |
| 105 | |
| 106 | auto model = YoloBody_tiny(3, 80); |
| 107 | torch::load(model, "weights/yolo4_tiny.pt"); |
| 108 | model->to(torch::kCUDA); |
| 109 | Predict(model, image, true, 0.1, 0.3); |
| 110 | |
| 111 | detector.Predict(image, true, 0.1); |
| 112 | int64 start = cv::getTickCount(); |
| 113 | int loops = 10; |
| 114 | for (int i = 0; i < loops; i++) { |
| 115 | detector.Predict(image, false); |
| 116 | } |
| 117 | double duration = (cv::getTickCount() - start) / cv::getTickFrequency(); |
| 118 | std::cout << duration/ loops <<" s per prediction" << std::endl; |
| 119 | |
| 120 | return 0; |
| 121 | } |
nothing calls this directly
no test coverage detected