Windows runtime WinML onnx示例产生错误的结果
我遵循这个WinML创建一个回归模型并对其进行推理。 我尝试使用WinML/WinRT运行onnx模型,但结果是错误的。我强制将数据读取为RGB而不是BGR,但其中包含alpha组件,例如RGBA,我怀疑错误的结果是由于alpha造成的,我在原始模型中没有alpha。我如何解决这个问题? 当我从解码器读取像素时,我得到RGBA,其中A(alpha)设置为255。我试图用1替换它,但解码器似乎是不可变的。 如果我可以确保输入到模型的像素是正确的,那么这将产生正确的结果。请按照创建视频帧的步骤进行操作,创建视频帧时不必担心alpha通道,因为WinML无论如何都会忽略此通道。如果需要,可以调用在不同像素格式之间进行转换Windows runtime WinML onnx示例产生错误的结果,windows-runtime,c++-winrt,windows-machine-learning,Windows Runtime,C++ Winrt,Windows Machine Learning,我遵循这个WinML创建一个回归模型并对其进行推理。 我尝试使用WinML/WinRT运行onnx模型,但结果是错误的。我强制将数据读取为RGB而不是BGR,但其中包含alpha组件,例如RGBA,我怀疑错误的结果是由于alpha造成的,我在原始模型中没有alpha。我如何解决这个问题? 当我从解码器读取像素时,我得到RGBA,其中A(alpha)设置为255。我试图用1替换它,但解码器似乎是不可变的。 如果我可以确保输入到模型的像素是正确的,那么这将产生正确的结果。请按照创建视频帧的步骤进行
VideoFrame LoadImageFile(hstring filePath)
{
printf("Loading the image...\n");
DWORD ticks = GetTickCount();
VideoFrame inputImage = nullptr;
try
{
// open the file
StorageFile file = StorageFile::GetFileFromPathAsync(filePath).get();
// get a stream on it
auto stream = file.OpenAsync(FileAccessMode::Read).get();
// Create the decoder from the stream
BitmapDecoder decoder = BitmapDecoder::CreateAsync(stream).get();
// get the bitmap
SoftwareBitmap softwareBitmap = decoder.GetSoftwareBitmapAsync().get();
// load a videoframe from it
inputImage = VideoFrame::CreateWithSoftwareBitmap(softwareBitmap);
}
catch (...)
{
printf("failed to load the image file, make sure you are using fully qualified paths\r\n");
exit(EXIT_FAILURE);
}
ticks = GetTickCount() - ticks;
printf("image file loaded in %d ticks\n", ticks);
// all done
return inputImage;
}
这回答了你的问题吗?
VideoFrame LoadImageFile(hstring filePath)
{
printf("Loading the image...\n");
DWORD ticks = GetTickCount();
VideoFrame inputImage = nullptr;
try
{
// open the file
StorageFile file = StorageFile::GetFileFromPathAsync(filePath).get();
// get a stream on it
auto stream = file.OpenAsync(FileAccessMode::Read).get();
// Create the decoder from the stream
BitmapDecoder decoder = BitmapDecoder::CreateAsync(stream).get();
// get the bitmap
SoftwareBitmap softwareBitmap = decoder.GetSoftwareBitmapAsync().get();
// load a videoframe from it
inputImage = VideoFrame::CreateWithSoftwareBitmap(softwareBitmap);
}
catch (...)
{
printf("failed to load the image file, make sure you are using fully qualified paths\r\n");
exit(EXIT_FAILURE);
}
ticks = GetTickCount() - ticks;
printf("image file loaded in %d ticks\n", ticks);
// all done
return inputImage;
}