{"id":425,"date":"2022-09-29T09:53:57","date_gmt":"2022-09-29T16:53:57","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/windowsai\/?p=425"},"modified":"2022-09-29T09:53:57","modified_gmt":"2022-09-29T16:53:57","slug":"real-time-image-blurring-directx-resource-binding-in-the-windows-ml-samples-gallery","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/windowsai\/real-time-image-blurring-directx-resource-binding-in-the-windows-ml-samples-gallery\/","title":{"rendered":"Real-Time Image Blurring &#038; DirectX Resource Binding in the Windows ML Samples Gallery"},"content":{"rendered":"<p><span data-contrast=\"auto\">Last November, we announced the release of the <\/span><a href=\"https:\/\/devblogs.microsoft.com\/windowsai\/introducing-the-windows-ml-samples-gallery\/\"><span data-contrast=\"none\">Windows ML Samples Gallery<\/span><\/a><span data-contrast=\"auto\">. The newest release of the gallery adds 4 new samples, 2 of which are discussed in detail below.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<h2><span data-contrast=\"auto\">Real-Time Background Image Blurring<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/h2>\n<p><span style=\"font-size: 10pt;\">Linnea May\u202f\u00a0<\/span><\/p>\n<hr \/>\n<p><span data-contrast=\"auto\">Real-time machine learning inference is a hot topic in ML, with applications such as real-time object detection in autonomous cars or background image blurring of a video stream during a work call. This new sample demonstrates the best practices to follow with Windows Machine Learning (Windows ML) and Microsoft Media Foundation to run background image blurring during inference on a real-time video stream at 30+ frames per second when using a dedicated GPU. <\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/img_blur.jpg\"><img decoding=\"async\" class=\"alignnone wp-image-466\" src=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/img_blur-300x157.jpg\" alt=\"Image Background image blurring running at 30 frames per second\" width=\"524\" height=\"274\" srcset=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/img_blur-300x157.jpg 300w, https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/img_blur.jpg 522w\" sizes=\"(max-width: 524px) 100vw, 524px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><i><span data-contrast=\"auto\">Background image blurring running at 30 frames per second.\u00a0<\/span><\/i><span data-ccp-props=\"{&quot;335551550&quot;:2,&quot;335551620&quot;:2}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">The sample uses an asynchronous <\/span><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/medfound\/media-foundation-transforms\"><span data-contrast=\"none\">Media Foundation Transform<\/span><\/a><span data-contrast=\"auto\"> (MFT) to apply an effect to the input video stream.\u00a0<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">The MFT will start by asynchronously requesting a new video sample from the capture source which in this case is the camera. This sample is converted into a shareable VideoFrame then run through the composition of three models: a preprocessing model, a Fully Convolutional Network, and a postprocessing model. Once the sample has been transformed, it\u2019s returned to the Media Foundation processing pipeline via an asynchronous callback to the preview sink, which displays the sample to the screen.\u00a0<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><span data-ccp-props=\"{&quot;335551550&quot;:2,&quot;335551620&quot;:2}\"><a href=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/bgrnd_blur_data_flow.png\"><img decoding=\"async\" class=\" wp-image-462 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/bgrnd_blur_data_flow-300x170.png\" alt=\"The basic data flow of the Background Blur sample\" width=\"377\" height=\"214\" srcset=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/bgrnd_blur_data_flow-300x170.png 300w, https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/bgrnd_blur_data_flow-1024x581.png 1024w, https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/bgrnd_blur_data_flow-768x436.png 768w, https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/bgrnd_blur_data_flow.png 1095w\" sizes=\"(max-width: 377px) 100vw, 377px\" \/><\/a>\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><i><span data-contrast=\"auto\">The basic data flow of the Background Blur sample.<\/span><\/i><span data-ccp-props=\"{&quot;335551550&quot;:2,&quot;335551620&quot;:2}\">\u00a0<\/span><\/p>\n<p><a href=\"https:\/\/github.com\/microsoft\/onnxruntime\/blob\/5fbfca3d58b88d0da29c6b206c36980052a4392c\/winml\/api\/Microsoft.AI.MachineLearning.Experimental.idl#L109\"><span data-contrast=\"none\">Microsoft.AI.MachineLearningExperimental.LearningModelJoinOptions<\/span><\/a><span data-contrast=\"auto\"> fuses together three stages of the model:\u00a0<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<ol>\n<li data-leveltext=\"%1.\" data-font=\"Calibri\" data-listid=\"4\" data-list-defn-props=\"{&quot;335552541&quot;:0,&quot;335559684&quot;:-1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769242&quot;:[65533,0],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;%1.&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"auto\">Preprocessing: The FCN needs 0-1 scaling and z-score normalization, so we use Windows ML\u2019s <\/span><a href=\"https:\/\/github.com\/microsoft\/onnxruntime\/blob\/5fbfca3d58b88d0da29c6b206c36980052a4392c\/winml\/api\/Microsoft.AI.MachineLearning.Experimental.idl#L88\"><span data-contrast=\"none\">LearningModelBuilder<\/span><\/a><span data-contrast=\"auto\"> to compose ONNX operators into a preprocessing stage.<\/span><\/li>\n<li data-leveltext=\"%1.\" data-font=\"Calibri\" data-listid=\"4\" data-list-defn-props=\"{&quot;335552541&quot;:0,&quot;335559684&quot;:-1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769242&quot;:[65533,0],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;%1.&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><a href=\"https:\/\/github.com\/onnx\/models\/tree\/main\/vision\/object_detection_segmentation\/fcn\"><span data-contrast=\"none\">FCN ResNet-50<\/span><\/a><span data-contrast=\"auto\"> takes in a preprocessed image of shape (N, 3, height, width), where N is the batch size, and outputs shape (N, 21, height, width) where each pixel is one-hot encoded as one of FCN-ResNet\u2019s 21 possible classes.<\/span><\/li>\n<li data-leveltext=\"%1.\" data-font=\"Calibri\" data-listid=\"4\" data-list-defn-props=\"{&quot;335552541&quot;:0,&quot;335559684&quot;:-1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769242&quot;:[65533,0],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;%1.&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"auto\">Postprocessing: We use another LearningModelBuilder to isolate and blur the pixels that are classified as \u201cbackground\u201d, then compose it with the non-blurred foreground.\u00a0\u00a0<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/li>\n<\/ol>\n<h4 aria-level=\"2\">Getting started<\/h4>\n<p><span data-contrast=\"auto\">Windows Machine Learning<\/span><span data-ccp-props=\"{&quot;335551550&quot;:2,&quot;335551620&quot;:2}\"> Resources<\/span><\/p>\n<table data-tablestyle=\"MsoTableGrid\" data-tablelook=\"1184\" aria-rowcount=\"6\">\n<tbody>\n<tr aria-rowindex=\"1\">\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Resource<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Description<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"2\">\n<td data-celllook=\"0\"><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/pull\/469\"><span data-contrast=\"auto\">Background Blur Sample Code<\/span><\/a><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Source code for the background image blur sample<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"3\">\n<td data-celllook=\"0\"><a href=\"https:\/\/github.com\/microsoft\/onnxruntime\/blob\/5fbfca3d58b88d0da29c6b206c36980052a4392c\/winml\/api\/Microsoft.AI.MachineLearning.Experimental.idl\"><span data-contrast=\"auto\">Windows ML Experimental API<\/span><\/a><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Documentation for the LearningModelBuilder and LearningModelJoinOptions<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"4\">\n<td data-celllook=\"0\"><a href=\"https:\/\/github.com\/microsoft\/onnxruntime\/blob\/22739137c419bb8a86b8f9ff5c8def60b63370c7\/winml\/test\/api\/LearningModelSessionAPITest.cpp#L962\"><span data-contrast=\"auto\">ORT model building unit tests<\/span><\/a><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">A good intro to building models with LearningModelBuilder and LearningModelJoinOptions<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"5\">\n<td data-celllook=\"0\"><a href=\"https:\/\/github.com\/onnx\/onnx\/blob\/main\/docs\/Operators.md\"><span data-contrast=\"auto\">ONNX operators schema<\/span><\/a><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">ONNX operators that can be used when building a model with LearningModelBuilder<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"6\">\n<td data-celllook=\"0\"><a href=\"https:\/\/github.com\/onnx\/models\/tree\/main\/vision\/object_detection_segmentation\/fcn\"><span data-contrast=\"auto\">ONNX Model Zoo FCN<\/span><\/a><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Open-source models in the ONNX format<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span data-contrast=\"auto\">Media Foundation<\/span><span data-ccp-props=\"{&quot;335551550&quot;:2,&quot;335551620&quot;:2}\"> Resources<\/span><\/p>\n<table data-tablestyle=\"MsoTableGrid\" data-tablelook=\"1184\" aria-rowcount=\"4\">\n<tbody>\n<tr aria-rowindex=\"1\">\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Resource<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Description<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"2\">\n<td data-celllook=\"0\"><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/medfound\/media-foundation-transforms\"><span data-contrast=\"auto\">Introduction to Media Foundation Transforms<\/span><\/a><span data-contrast=\"auto\">\u00a0<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Start here to learn more about Media Foundation Transforms as a model for processing media data<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"3\">\n<td data-celllook=\"0\"><a href=\"https:\/\/github.com\/microsoft\/Windows-classic-samples\/tree\/main\/Samples\/MediaFoundationTransformDecoder\"><span data-contrast=\"auto\">Windows Async MFT Sample<\/span><\/a><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Demonstrates how to create an asynchronous Media Foundation Transform<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"4\">\n<td data-celllook=\"0\"><a href=\"https:\/\/github.com\/microsoft\/Windows-classic-samples\/tree\/main\/Samples\/CaptureEngineVideoCapture\"><span data-contrast=\"auto\">Windows Capture Engine Sample<\/span><\/a><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Demonstrates how to use the Media Foundation <\/span><a href=\"https:\/\/docs.microsoft.com\/en-us\/windows\/win32\/api\/mfcaptureengine\/nn-mfcaptureengine-imfcaptureengine\"><span data-contrast=\"none\">CaptureEngine<\/span><\/a><span data-contrast=\"auto\"> to capture video<\/span><span data-ccp-props=\"{}\">\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span data-ccp-props=\"{}\">\u00a0<\/span><\/p>\n<h2><span data-contrast=\"auto\">DirectX Resource Binding<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span style=\"font-size: 10pt;\">Numfor Mbiziwo-Tiapo\u00a0<\/span><\/p>\n<hr \/>\n<p><span data-contrast=\"auto\">Learn how to bind and inference on Direct3D 12 Resources using ONNX Runtime in the <\/span><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/tree\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGallery\/Samples\/DXResourceBindingORT\"><span data-contrast=\"none\">DX Resource Binding ORT Sample<\/span><\/a><span data-contrast=\"auto\">.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\"> <a href=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/DXResourceBindingSample.png\"><img decoding=\"async\" class=\"alignnone wp-image-465\" src=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/DXResourceBindingSample-300x184.png\" alt=\"Image DX Resource Binding Sample\" width=\"670\" height=\"411\" srcset=\"https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/DXResourceBindingSample-300x184.png 300w, https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/DXResourceBindingSample-1024x629.png 1024w, https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/DXResourceBindingSample-768x472.png 768w, https:\/\/devblogs.microsoft.com\/windowsai\/wp-content\/uploads\/sites\/71\/2022\/08\/DXResourceBindingSample.png 1490w\" sizes=\"(max-width: 670px) 100vw, 670px\" \/><\/a><\/span><\/p>\n<p style=\"text-align: center;\"><i><span data-contrast=\"auto\">DX Resource Binding Sample<\/span><\/i><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">In this sample, images are drawn to the screen using Direct3D 12. The images are then preprocessed and inferenced on in real-time using the ONNX Runtime C++ API.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">The general structure of the sample is stated below:<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"4\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/DXResourceBinding.h\"><span data-contrast=\"none\">DXResourceBinding.h<\/span><\/a><span data-contrast=\"auto\"> \/ <\/span><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/DXResourceBinding.cpp\"><span data-contrast=\"none\">.cpp<\/span><\/a><span data-contrast=\"auto\"> : main interface between D3D code and ORT code<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"4\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/D3D12Quad.h\"><span data-contrast=\"none\">D3D12Quad.h<\/span><\/a><span data-contrast=\"auto\"> \/ <\/span><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/D3D12Quad.cpp\"><span data-contrast=\"none\">.cpp<\/span><\/a><span data-contrast=\"auto\"> : handles all D3D-related\u00a0 functions, including drawing the images to the screen in an HWND<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"4\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"3\" data-aria-level=\"1\"><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/ORTHelpers.h\"><span data-contrast=\"none\">ORTHelpers.h<\/span><\/a><span data-contrast=\"auto\"> \/ <\/span><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/ORTHelpers.cpp\"><span data-contrast=\"none\">.cpp<\/span><\/a><span data-contrast=\"auto\"> : handles all ORT functions for preprocessing and evaluation. Also shows <\/span><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/ORTHelpers.cpp#L122\"><span data-contrast=\"none\">how to create an ORT Value from a D3D resource<\/span><\/a><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-contrast=\"auto\">The sample follows this sequence of steps:<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"6\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;multilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/D3D12Quad.cpp#L438\"><span data-contrast=\"none\">Step 1<\/span><\/a><span data-contrast=\"auto\"> : Buffer is drawn to the screen using Direct3D 12.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"6\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;multilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/D3D12Quad.cpp#L347\"><span data-contrast=\"none\">Step 2<\/span><\/a><span data-contrast=\"auto\"> : An empty D3D12_RESOURCE_DIMENSION_BUFFER is created that will serve as the copy destination for the image being drawn to the screen which is of type D3D12_RESOURCE_DIMENSION_TEXTURE2D<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<li style=\"list-style-type: none;\">\n<ul>\n<li data-leveltext=\"o\" data-font=\"Courier New\" data-listid=\"6\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Courier New&quot;,&quot;469769242&quot;:[9675],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;o&quot;,&quot;469777815&quot;:&quot;multilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"2\"><span data-contrast=\"auto\">The image must be copied into this buffer because DirectML expects resource dimension buffers<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/li>\n<\/ul>\n<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"7\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/D3D12Quad.cpp#L371\"><span data-contrast=\"none\">Step 3<\/span><\/a><span data-contrast=\"auto\"> : The texture 2d is copied into the resource dimension buffer<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"7\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/ORTHelpers.cpp#L49\"><span data-contrast=\"none\">Step 4:<\/span><\/a><span data-contrast=\"auto\"> The buffer is converted to an ORT Value and passed through a preprocessing model that shrinks the tensor to a size of 224 x 224 x 3 (the expected input size for EfficientNetLite)<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"7\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" aria-setsize=\"-1\" data-aria-posinset=\"3\" data-aria-level=\"1\"><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/blob\/master\/Samples\/WinMLSamplesGallery\/WinMLSamplesGalleryNative\/ORTHelpers.cpp#L96\"><span data-contrast=\"none\">Step 5<\/span><\/a><span data-contrast=\"auto\">: The preprocessed input is the passed through EfficientNet where the image is classified<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<h5><b><span data-contrast=\"none\">Try it out and stay involved<\/span><\/b><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/h5>\n<p><span data-contrast=\"none\">The Windows ML Samples Gallery can be downloaded from the\u202f<\/span><a href=\"https:\/\/www.microsoft.com\/store\/apps\/9PKBFQKBCLM9\"><span data-contrast=\"none\">Microsoft Store<\/span><\/a><span data-contrast=\"none\">\u202for from\u202f<\/span><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/tree\/master\/Samples\/WinMLSamplesGallery#build-from-source\"><span data-contrast=\"none\">GitHub<\/span><\/a><span data-contrast=\"none\">. We encourage you to try it out and give feedback by reporting issues or requesting new samples on the\u202f<\/span><a href=\"https:\/\/github.com\/microsoft\/Windows-Machine-Learning\/issues\"><span data-contrast=\"none\">issues page<\/span><\/a><span data-contrast=\"none\">.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;134233118&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:0,&quot;335559740&quot;:240}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">Stay tuned to the Windows AI Blog for more updates and news!<\/span><span data-ccp-props=\"{&quot;134233118&quot;:true,&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last November, we announced the release of the Windows ML Samples Gallery. The newest release of the gallery adds 4 new samples, 2 of which are discussed in detail below.\u00a0 \u00a0 Real-Time Background Image Blurring\u00a0 Linnea May\u202f\u00a0 Real-time machine learning inference is a hot topic in ML, with applications such as real-time object detection in [&hellip;]<\/p>\n","protected":false},"author":94589,"featured_media":74,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-425","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-windows-ai"],"acf":[],"blog_post_summary":"<p>Last November, we announced the release of the Windows ML Samples Gallery. The newest release of the gallery adds 4 new samples, 2 of which are discussed in detail below.\u00a0 \u00a0 Real-Time Background Image Blurring\u00a0 Linnea May\u202f\u00a0 Real-time machine learning inference is a hot topic in ML, with applications such as real-time object detection in [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/posts\/425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/users\/94589"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/comments?post=425"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/posts\/425\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/media\/74"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/media?parent=425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/categories?post=425"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/windowsai\/wp-json\/wp\/v2\/tags?post=425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}