Skip to content

Commit

Permalink
Merge pull request #1480 from alicevision/mug/fixSegmentationWindowsB…
Browse files Browse the repository at this point in the history
…uild

[segmentation] fix windows build
  • Loading branch information
cbentejac authored Jun 28, 2023
2 parents 4ca0496 + a713d8b commit dc8c4f5
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/aliceVision/segmentation/segmentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ bool Segmentation::initialize()
api.SessionOptionsAppendExecutionProvider_CUDA_V2(static_cast<OrtSessionOptions*>(ortSessionOptions), cuda_options);
api.ReleaseCUDAProviderOptions(cuda_options);

_ortSession = std::make_unique<Ort::Session>(*_ortEnvironment, _parameters.modelWeights.c_str(), ortSessionOptions);
#if defined(_WIN32) || defined(_WIN64)
std::wstring modelWeights(_parameters.modelWeights.begin(), _parameters.modelWeights.end());
_ortSession = std::make_unique<Ort::Session>(*_ortEnvironment, modelWeights.c_str(), ortSessionOptions);
#else
_ortSession = std::make_unique<Ort::Session>(*_ortEnvironment, _parameters.modelWeights.c_str(), ortSessionOptions);
#endif

Ort::MemoryInfo memInfoCuda("Cuda", OrtAllocatorType::OrtArenaAllocator, 0, OrtMemType::OrtMemTypeDefault);
Ort::Allocator cudaAllocator(*_ortSession, memInfoCuda);
Expand All @@ -66,7 +71,12 @@ bool Segmentation::initialize()
_cudaInput = cudaAllocator.Alloc(_output.size() * sizeof(float));
_cudaOutput = cudaAllocator.Alloc(_output.size() * sizeof(float));
#else
_ortSession = std::make_unique<Ort::Session>(ortEnvironment, _parameters.modelWeights.c_str(), ortSessionOptions);
#if defined(_WIN32) || defined(_WIN64)
std::wstring modelWeights(_parameters.modelWeights.begin(), _parameters.modelWeights.end());
_ortSession = std::make_unique<Ort::Session>(ortEnvironment, modelWeights.c_str(), ortSessionOptions);
#else
_ortSession = std::make_unique<Ort::Session>(*_ortEnvironment, _parameters.modelWeights.c_str(), ortSessionOptions);
#endif
#endif

return true;
Expand Down Expand Up @@ -226,7 +236,7 @@ bool Segmentation::labelsFromModelOutput(image::Image<ScoredLabel> & labels, con
}
}

labels(outputY, outputX) = {maxClasse, maxVal};
labels(outputY, outputX) = {static_cast<IndexT>(maxClasse), static_cast<float>(maxVal)};
}
}

Expand All @@ -239,8 +249,10 @@ bool Segmentation::processTile(image::Image<ScoredLabel> & labels, const image::

std::vector<const char*> inputNames{"input"};
std::vector<const char*> outputNames{"output"};
std::vector<int64_t> inputDimensions = {1, 3, _parameters.modelHeight, _parameters.modelWidth};
std::vector<int64_t> outputDimensions = {1, _parameters.classes.size(), _parameters.modelHeight, _parameters.modelWidth};
std::vector<int64_t> inputDimensions =
{1, 3, _parameters.modelHeight, _parameters.modelWidth};
std::vector<int64_t> outputDimensions =
{1, static_cast<int64_t>(_parameters.classes.size()), _parameters.modelHeight, _parameters.modelWidth};

std::vector<float> output(_parameters.classes.size() * _parameters.modelHeight * _parameters.modelWidth);
Ort::Value outputTensors = Ort::Value::CreateTensor<float>(
Expand Down Expand Up @@ -284,8 +296,10 @@ bool Segmentation::processTileGPU(image::Image<ScoredLabel> & labels, const imag

std::vector<const char*> inputNames{"input"};
std::vector<const char*> outputNames{"output"};
std::vector<int64_t> inputDimensions = {1, 3, _parameters.modelHeight, _parameters.modelWidth};
std::vector<int64_t> outputDimensions = {1, _parameters.classes.size(), _parameters.modelHeight, _parameters.modelWidth};
std::vector<int64_t> inputDimensions =
{1, 3, _parameters.modelHeight, _parameters.modelWidth};
std::vector<int64_t> outputDimensions =
{1, static_cast<int64_t>(_parameters.classes.size()), _parameters.modelHeight, _parameters.modelWidth};


Ort::Value outputTensors = Ort::Value::CreateTensor<float>(
Expand Down

0 comments on commit dc8c4f5

Please sign in to comment.