| 372 | } |
| 373 | |
| 374 | void Segmentation::run(const Cloud::Ptr cloud, cv::Mat& maskImg){ |
| 375 | std::vector<float> cloudVector; |
| 376 | for (const auto& point : cloud->points) { |
| 377 | cloudVector.push_back(point.x); cloudVector.push_back(point.y); |
| 378 | cloudVector.push_back(point.z); cloudVector.push_back(point.intensity); |
| 379 | } |
| 380 | |
| 381 | if(_verbose){ |
| 382 | std::cout << "Projecting data" << std::endl; |
| 383 | _timer.tic(); |
| 384 | } |
| 385 | auto netInput = _doProjection(cloudVector, cloud->width*cloud->height); |
| 386 | |
| 387 | // int dims[] = {64,2048}; |
| 388 | // std::vector<float> flattened_inp; |
| 389 | // for (int i = 0; i < _img_h*_img_w; ++i) { |
| 390 | // size_t proj_idx = proj_ys[i] * _img_w + proj_xs[i]; |
| 391 | // flattened_inp.push_back(netInput[proj_idx][0]); |
| 392 | // } |
| 393 | // cv::Mat result = cv::Mat(2, dims, CV_32F, flattened_inp.data()); |
| 394 | // cv::FileStorage file("/opt/bags/inf/inp.ext", cv::FileStorage::WRITE); |
| 395 | // file << "mat" << result; |
| 396 | |
| 397 | if(_verbose){ |
| 398 | _timer.toc(); |
| 399 | } |
| 400 | |
| 401 | std::vector<float> outputTensorValues(_outputTensorSize); |
| 402 | std::vector<float> inputTensorValues(_inputTensorSize); |
| 403 | std::vector<size_t> invalid_idxs; |
| 404 | |
| 405 | if(_verbose){ |
| 406 | std::cout << "Making tensor" << std::endl; |
| 407 | _timer.tic(); |
| 408 | } |
| 409 | |
| 410 | _makeTensor(netInput, inputTensorValues, invalid_idxs); |
| 411 | |
| 412 | if(_verbose){ |
| 413 | _timer.toc(); |
| 414 | } |
| 415 | |
| 416 | if(_verbose){ |
| 417 | std::cout << "Running Inference" << std::endl; |
| 418 | _timer.tic(); |
| 419 | } |
| 420 | std::vector<Ort::Value> inputTensors; |
| 421 | std::vector<Ort::Value> outputTensors; |
| 422 | inputTensors.push_back(Ort::Value::CreateTensor<float>( |
| 423 | *_memoryInfo, inputTensorValues.data(), _inputTensorSize, _inputDims.data(), |
| 424 | _inputDims.size())); |
| 425 | |
| 426 | outputTensors.push_back(Ort::Value::CreateTensor<float>( |
| 427 | *_memoryInfo, outputTensorValues.data(), _outputTensorSize, |
| 428 | _outputDims.data(), _outputDims.size())); |
| 429 | |
| 430 | _session->Run(Ort::RunOptions{nullptr}, _inputNames.data(), |
| 431 | inputTensors.data(), 1, _outputNames.data(), |