Home
%3CLINGO-SUB%20id%3D%22lingo-sub-318077%22%20slang%3D%22en-US%22%3E%F0%9F%94%99%20Back%20to%20the%20future%20now%20%E2%8F%A9%3A%20Execute%20your%20Azure%20%E2%98%81%20trained%20Machine%20Learning%20%F0%9F%A7%AA%20models%20on%20HoloLens!%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-318077%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Nov%2015%2C%202018%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CSTRONG%3E%20Artificial%20Intelligence%20%3C%2FSTRONG%3E%20is%20everywhere%20and%20powered%20by%20the%20Cloud.%20We%20can%20now%20go%20even%20further%20and%20bring%20AI%20to%20%3CSTRONG%3E%20HoloLens%20%3C%2FSTRONG%3E%20gracefully%20thanks%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Ffr-fr%2Fwindows%2Fai%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Windows%20Machine%20Learning%20%3C%2FA%3E%20and%20Windows%2010!%20%3CBR%20%2F%3E%3CBR%20%2F%3ELet's%20go%20and%20make%20it%20real%20with%20a%20full%20working%20and%20reusable%20sample.%20Yes!%20%3CEM%3E%20Reusable%20%3C%2FEM%3E%20because%2C%20you%20can%20train%20your%20own%20Custom%20Vision%20model%20and%20run%20it%20using%20this%20sample%20%E2%99%BB%20without%20any%20code%20modification.%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3E%20My%20colleagues%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fmeulta%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Etienne%20Margraff%20%3C%2FA%3E%20and%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fqmatteoq%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Matteo%20Pagani%20%3C%2FA%3E%20already%20gave%20lot%20of%20details%20and%20useful%20explanations%20about%20Windows%20ML.%20Feel%20free%20to%20refer%20to%20their%20good%20blog%20posts%20in%20the%20%3CEM%3E%20References%20%3C%2FEM%3E%20section%20at%20the%20end%20of%20this%20article.%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3EThe%20idea%20is%20the%20following%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EWe%20use%20a%20%3CA%20href%3D%22https%3A%2F%2Fwww.customvision.ai%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Custom%20Vision%20%3C%2FA%3E%20model%20that%20we%20train%20in%20Azure%20to%20recognize%20objects%2Fsituations%2Fmachines%2Fpersons%2Fetc.%20(In%20fact%2C%20almost%20what%20you%20want%20%F0%9F%98%8F).%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EWe%20export%20this%20model%20as%20a%20ONNX%201.2%20file.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EWe%20develop%20a%20HoloLens%20app%20which%20gets%20video%20frames%20in%20continue.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%20%3CSTRONG%3E%E2%8F%A9%E2%9C%94%20The%20app%20uses%20the%20model%20locally%20for%20evaluation%20and%20predicts%20what%20is%20in%20front%20of%20the%20user%20wearing%20the%20HoloLens!%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E--%3C%2FP%3E%0A%3CH2%20id%3D%22step-1-train--a-machine-learning-model-in-azure%22%20id%3D%22toc-hId-1730743730%22%20id%3D%22toc-hId-1730743730%22%3EStep%201.%20Train%20%F0%9F%A5%BC%20a%20Machine%20Learning%20Model%20in%20Azure%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22-create-the-custom-vision-model%22%20id%3D%22toc-hId--1017926736%22%20id%3D%22toc-hId--1017926736%22%3E%F0%9F%86%95%20Create%20the%20Custom%20Vision%20model%3C%2FH3%3E%0A%3CP%3E%3CBR%20%2F%3EConnect%20to%20%3CA%20href%3D%22https%3A%2F%2Fwww.customvision.ai%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fwww.customvision.ai%2F%20%3C%2FA%3E%20and%20click%20on%20the%20%3CSTRONG%3E%20NEW%20PROJECT%20%3C%2FSTRONG%3E%20button%20to%20create%20a%20new%20Custom%20Vision%20project.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20325px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67876i87252540AABEBF56%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EFill%20in%20the%20details%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EA%20%3CEM%3E%20name%20%3C%2FEM%3E%20and%20a%20%3CEM%3E%20description%20%3C%2FEM%3E%20.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20590px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67879i68A8859DD0A54899%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EChoose%20if%20you%20want%20to%20use%20the%20%3CSTRONG%3E%20Limited%20Trial%20%3C%2FSTRONG%3E%20mode%20or%20use%2Fcreate%20an%20%3CSTRONG%3E%20Azure%20resource%20group%20%3C%2FSTRONG%3E%20for%20hosting%20the%20Custom%20Vision%20service%20in%20Azure.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20590px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67881i454C99D5ACB3D071%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3E%20Choosing%20the%20resource%20group%20option%20makes%20sense%20if%20you%20want%20to%20use%20your%20Custom%20Vision%20model%20everywhere.%20I%20mean%3A%20it%20uses%20Azure%20to%20provide%20a%20REST%20endpoint%20API%20that%20can%20be%20used%20in%20mobile%20apps%20or%20on%20computers%20running%20Windows%2C%20MacOS%2C%20Linux%20or%20even%20in%20Web%20sites.%20And%20all%20this%2C%20without%20to%20worry%20about%20the%20technology%20used.%20%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20evaluating%20the%20model%20locally%20on%20the%20HoloLens%2C%20you%20can%20go%20for%20the%20Limited%20Trial%20as%20we%20will%20not%20use%20the%20Azure%20Custom%20Vision%20endpoint.%20Please%20note%20that%2C%20later%2C%20if%20you%20want%20to%20instantiate%20an%20Azure%20resource%20for%20this%20Custom%20Vision%20model's%20evaluation%20on%20other%20platforms%2C%20you%20can%20do%20it%20by%20clicking%20on%20the%20%3CEM%3E%20gear%20%3C%2FEM%3E%20on%20the%20top%20right%20of%20the%20page%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20724px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67883iD1FC48CA506887E3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EThen%2C%20at%20the%20bottom%20of%20the%20details'%20page%20for%20your%20model%2C%20you%20create%20the%20Azure%20resource%20by%20clicking%20on%20the%20%3CSTRONG%3E%20Move%20To%20Azure%20%3C%2FSTRONG%3E%20button%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20304px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67884i5805682A576A55B4%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3ESo%2C%20let's%20go%20back%20to%20our%20model%20creation%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EChoose%20%3CSTRONG%3E%20Classification%20%3C%2FSTRONG%3E%20for%20the%20project%20type.%20That%20means%20that%20we%20would%20like%20to%20tag%20the%20whole%20image.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20385px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67886i2C3C8D853ADBBA5E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3E%20For%20your%20information%2C%20%3CSTRONG%3E%20Object%20Detection%20%3C%2FSTRONG%3E%20finds%20also%20the%20location%20of%20the%20object%20within%20an%20image.%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EGo%20for%20%3CSTRONG%3E%20Multilabel%20(Multiple%20tags%20per%20image)%20%3C%2FSTRONG%3E%20as%20we%20would%20like%20to%20not%20be%20blocked%20to%20use%20only%20one%20tag.%20As%20an%20example%3A%20The%20image%20can%20contain%20a%20machine%20factory%20B214%20type%202%20and%20another%20machine%20whom%20id%20is%20A78%20Alpha2.%20Tags%20applied%20to%20the%20image%20will%20be%20%22B214%20type%202%22%20and%20%22A78%20Alpha2%22.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20373px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67888iDBE97E438723A953%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3ELastly%2C%20but%20may%20be%20the%20most%20important%2C%20%E2%9A%A0%20take%20%3CSTRONG%3E%20General%20(compact)%20%3C%2FSTRONG%3E%20%E2%9A%A0.%20Choosing%20a%20%3CSTRONG%3E%20compact%20%3C%2FSTRONG%3E%20model%20is%20mandatory%20to%20be%20able%20to%20use%20it%20with%20Windows%20ML%20on%20HoloLens%20or%20in%20a%20Windows%2010%20UWP%20app.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20236px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67889iF1BF167D5B1DCE5A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E%F0%9F%86%97%20We%20are%20all%20set%20for%20the%20creation!%3C%2FP%3E%0A%3CH3%20id%3D%22-train-the-model%22%20id%3D%22toc-hId-724883599%22%20id%3D%22toc-hId-724883599%22%3E%E2%9A%97%20Train%20the%20model%3C%2FH3%3E%0A%3CP%3E%3CBR%20%2F%3ETo%20do%20so%2C%20the%20steps%20are%20straight%20forward%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EJust%20upload%20photos%20using%20the%20%3CSTRONG%3E%20Add%20images%20%3C%2FSTRONG%3E%20button.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67891iCBBEB3772502C0AD%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EGive%20one%20or%20more%20tags%20to%20the%20images%20to%20upload.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20605px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67892i6DAAD642830897DC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EAt%20any%20time%2C%20you%20can%20review%2C%20add%20or%20change%20the%20tags%20to%20the%20images.%20%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20385px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67894iEF1CE3C7DC758B9A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EWhen%20you%20are%20done%2C%20click%20on%20the%20Train%20button.%20%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20529px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67896iD1296DF43CE46F4A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20more%20details%2C%20feel%20free%20to%20read%20Test%20and%20retrain%20a%20model%20with%20Custom%20Vision%20Service%20.%20%3CBR%20%2F%3E%3CBR%20%2F%3EHere%20are%20some%20explanations%20about%20the%20results%20we%20get%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EYou%20can%20change%20the%20%3CSTRONG%3E%20Probability%20Threshold%20%3C%2FSTRONG%3E%20for%20a%20prediction%20to%20be%20valid.%20For%20example%3A%2085%25%20means%20that%20any%20predictions%20whom%20score%20%26lt%3B%2085%25%20will%20not%20be%20considered%20as%20a%20valid%20prediction.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3EPrecision%20%3C%2FSTRONG%3E%20%3D%20Gives%20you%20the%20%25%20of%20correct%20predictions.%20For%20example%3A%20For%20%3CEM%3E%20Benoit%20%3C%2FEM%3E%20%2C%20we%20have%207%20tagged%20pictures%20and%20the%20model's%20evaluation%20predicted%20this%20tag%20for%20all%207%20pictures%20(so%20100%25).%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3E%3CSTRONG%3ERecall%20%3C%2FSTRONG%3E%20%3D%20Gives%20you%20the%20%25%20of%20found%20tags.%20For%20example%3A%20For%20%3CEM%3E%20Sebastien%20%3C%2FEM%3E%20%2C%20we%20have%2012%20tagged%20pictures%20and%20the%20model%20was%20able%20to%20predict%20this%20tag%20for%2091%2C7%25%20of%20the%20pictures%20(11%20pictures).%20%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20960px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67897i68EAB705AAD0E9A3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CH2%20id%3D%22step-2-export--the-model-as-onnx-12%22%20id%3D%22toc-hId--1630759857%22%20id%3D%22toc-hId--1630759857%22%3EStep%202.%20Export%20%F0%9F%93%A6%20the%20model%20as%20ONNX%201.2%3C%2FH2%3E%0A%3CP%3E%3CBR%20%2F%3EAgain%2C%20this%20steps%20is%20easy%20and%20well%20documented%20by%20the%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fappconsult%2F2018%2F11%2F06%2Fupgrade-your-winml-application-to-the-latest-bits%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20article%20written%20by%20Matteo%20%3C%2FA%3E%20%3A%20Just%20click%20on%20the%20%3CSTRONG%3E%20Export%20%3C%2FSTRONG%3E%20button.%20%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20855px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67898i4F4B2178647AF36A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E%E2%9A%A0%20Be%20sure%20to%20choose%20the%20%3CSTRONG%3E%20ONNX%201.2%20format%20%3C%2FSTRONG%3E%20%E2%9A%A0%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20603px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67900i33D24881A5490C1B%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EYou%20see%20there%20that%20your%20app%20will%20run%20on%20Windows%20starting%20at%20the%20%3CSTRONG%3E%20Build%2017738%20%3C%2FSTRONG%3E%20which%20means%20%3CSTRONG%3E%20Windows%20version%201809%20%3C%2FSTRONG%3E%20or%20above.%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3E%20As%20I%20write%20this%20article%2C%20the%20Windows%20version%201809%20can%20be%20installed%20on%20HoloLens%20by%20participating%20to%20the%20Windows%20Insider%20Preview%20Slow%20ring.%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22step-3-create-a-unity-app--for-hololens-that-captures-the-camera--frames%22%20id%3D%22toc-hId-112050478%22%20id%3D%22toc-hId-112050478%22%3EStep%203.%20Create%20a%20Unity%20App%20%F0%9F%95%B9%20for%20HoloLens%20that%20captures%20the%20camera%20%F0%9F%8E%A5%20frames%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22project-setup-%22%20id%3D%22toc-hId-1658347308%22%20id%3D%22toc-hId-1658347308%22%3EProject%20setup%20%F0%9F%93%8F%3C%2FH3%3E%0A%3CP%3E%3CBR%20%2F%3EI%20worked%20with%20the%20following%20versions%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EWindows%20version%201809%20for%20the%20PC%20and%20HoloLens%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EVisual%20Studio%202017%20version%2015.9.0%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EWindows%20SDK%20version%2010.0.17763.0%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EUnity%202017.4.13f1%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3E%20You%20can%20skip%20this%20part%20if%20you%20are%20familiar%20with%20Unity%20and%20Mixed%20Reality.%20%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20not%2C%20please%20refer%20to%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fappconsult%2F2018%2F06%2F14%2Fcreate-a-windows-mixed-reality-app-from-0-the-unity-project%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Create%20a%20Windows%20Mixed%20Reality%20App%20from%200%20%E2%80%93%20The%20Unity%20project%20%3C%2FA%3E%20.%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3EThe%20Unity%20project%20has%20to%20be%20configured%20for%20Windows%20Mixed%20Reality%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EFile%20%3C%2FSTRONG%3E%20menu%20%2F%20%3CSTRONG%3E%20Build%20Settings%20%3C%2FSTRONG%3E%20%E2%9E%A1%20%3CSTRONG%3E%20Universal%20Windows%20Platform%20%3C%2FSTRONG%3E%20selected%20as%20the%20Build%20platform%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EEdit%20%3C%2FSTRONG%3E%20menu%20%2F%20%3CSTRONG%3E%20Project%20Settings%20%3C%2FSTRONG%3E%20%2F%20%3CSTRONG%3E%20Player%20%3C%2FSTRONG%3E%20%E2%9E%A1%20%3CSTRONG%3E%20Virtual%20Reality%20Supported%20%3C%2FSTRONG%3E%20checked%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EEdit%20%3C%2FSTRONG%3E%20menu%20%2F%20%3CSTRONG%3E%20Project%20Settings%20%3C%2FSTRONG%3E%20%2F%20%3CSTRONG%3E%20Player%20%3C%2FSTRONG%3E%20%E2%9E%A1%20%3CSTRONG%3E%20Other%20Settings%20%3C%2FSTRONG%3E%20%2F%20%3CSTRONG%3E%20.NET%20%3C%2FSTRONG%3E%20as%20Scripting%20Backend.%20Please%20also%20use%20the%20%3CSTRONG%3E%20Experimental%20(.NET%204.6%20Equivalent)%20%3C%2FSTRONG%3E%20for%20the%20Scripting%20Runtime%20Version.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CH3%20id%3D%22technical-piping--for-being-able-to-give-update-to-the-user%22%20id%3D%22toc-hId--893809653%22%20id%3D%22toc-hId--893809653%22%3ETechnical%20piping%20%F0%9F%94%A9%20for%20being%20able%20to%20give%20update%20to%20the%20user%3C%2FH3%3E%0A%3CP%3E%3CBR%20%2F%3EThe%20purpose%20is%20to%20be%20able%20to%20display%20a%20text%20message%20in%20front%20of%20the%20user%20from%20any%20code%20within%20the%20app.%20We%20first%20add%20a%20startup%20script%20to%20the%20scene%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3EFrom%20the%20%3CSTRONG%3E%20GameObject%20%3C%2FSTRONG%3E%20menu%20%3CSTRONG%3E%20Create%20an%20empty%20object%20%3C%2FSTRONG%3E%20and%20name%20it%20%22ScriptManager%22.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20160px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67901i41A4F3C5F5E9019F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3ESelect%20the%20ScriptManager%20object%20in%20the%20Hierarchy%20and%20click%20on%20Add%20Componennt%20%2F%20new%20script%20and%20name%20it%20%22UnityScanScene%22.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20277px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67903i13B55A6D59FC428F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20512px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67905iE26D1BEC5EFB5687%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EDouble%20click%20on%20the%20UnityScanScene%20script%20to%20modify%20it%20in%20Visual%20Studio%3B%20Replace%20the%20existing%20code%20by%20the%20one%20below.%20Let%20me%20give%20you%20some%20details%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EWe%20use%20an%20interface%20%3CSTRONG%3E%20IUnityScanScene%20%3C%2FSTRONG%3E%20with%20one%20unique%20public%20method%20%3CSTRONG%3E%20ModifyOutputText%20%3C%2FSTRONG%3E%20.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EThe%20startup%20script%20we%20are%20modifying%20(UnityScanScene)%20implements%20this%20interface.%20The%20method%20%3CSTRONG%3E%20ModifyOutputText%20%3C%2FSTRONG%3E%20just%20modifies%20a%20string.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EThe%20%3CSTRONG%3E%20Update%20%3C%2FSTRONG%3E%20method%20of%20the%20script%20(UnityScanScene)%20is%20executed%20for%20each%20frame.%20We%20just%20modify%20the%20text%20of%20a%203D%20Text%20object%20based%20on%20the%20modified%20string.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3EAll%20this%20%22piping%22%20is%20really%20useful%20for%20giving%20feedback%20to%20the%20user%20(text%20or%20other)%20from%20any%20code%20from%20any%20class%20within%20the%20project.%20You%20will%20see%20it%20in%20action%20later%20in%20this%20article.%3C%2FP%3E%0A%3CPRE%3Eusing%20System.Collections%3B%0Ausing%20System.Collections.Generic%3B%0Ausing%20UnityEngine%3B%0A%0A%2F%2F%2F%20%26lt%3Bsummary%26gt%3B%0A%2F%2F%2F%20The%20Interface%20gives%20one%20method%20to%20implement.%20This%20method%20modifies%20the%20text%20to%20display%20in%20Unity%0A%2F%2F%2F%20Any%20code%20can%20then%20call%20this%20method%20outside%20the%20Unity%20MonoBehavior%20object%0A%2F%2F%2F%20%26lt%3B%2Fsummary%26gt%3B%0Apublic%20interface%20IUnityScanScene%0A%7B%0A%20void%20ModifyOutputText(string%20newText)%3B%0A%7D%0A%0Apublic%20class%20UnityScanScene%20%3A%20MonoBehaviour%2C%20IUnityScanScene%0A%7B%0A%20%2F%2F%20Unity%203D%20Text%20object%20that%20contains%20%0A%20%2F%2F%20the%20displayed%20TextMesh%20in%20the%20FOV%0A%20public%20GameObject%20OutputText%3B%0A%20%2F%2F%20TextMesh%20object%20provided%20by%20the%20OutputText%20game%20object%0A%20private%20TextMesh%20OutputTextMesh%3B%0A%20%2F%2F%20string%20to%20be%20affected%20to%20the%20TextMesh%20object%0A%20private%20string%20OutputTextString%20%3D%20string.Empty%3B%0A%20%2F%2F%20Indicate%20if%20we%20have%20to%20Update%20the%20text%20displayed%0A%20private%20bool%20OutputTextChanged%20%3D%20false%3B%0A%0A%20%2F%2F%20Use%20this%20for%20initialization%0A%20async%20void%20Start%20()%0A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20OutputTextMesh%20%3D%20OutputText.GetComponent%26lt%3BTextMesh%26gt%3B()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20OutputTextMesh.text%20%3D%20string.Empty%3B%0A%0A%23if%20UNITY_WSA%20%26amp%3B%26amp%3B%20!UNITY_EDITOR%20%2F%2F%20**RUNNING%20ON%20WINDOWS**%0A%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20We%20will%20create%20our%20Camera%20scan%20engine%20here%0A%23else%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20**RUNNING%20IN%20UNITY**%0A%20%20%20%20%20%20%20%20%20%20%20%20ModifyOutputText(%22Sorry%20%3B-(%20The%20app%20is%20not%20supported%20in%20the%20Unity%20player.%22)%3B%0A%23endif%0A%20%7D%0A%0A%20%2F%2F%2F%20%26lt%3Bsummary%26gt%3B%0A%20%2F%2F%2F%20Modify%20the%20text%20to%20be%20displayed%20in%20the%20FOV%0A%20%2F%2F%2F%20or%2Fand%20in%20the%20debug%20traces%0A%20%2F%2F%2F%20%2B%20Indicate%20that%20we%20have%20to%20update%20the%20text%20to%20display%0A%20%2F%2F%2F%20%26lt%3B%2Fsummary%26gt%3B%0A%20%2F%2F%2F%20%26lt%3Bparam%20name%3D%22newText%22%26gt%3Bnew%20string%20value%20to%20display%26lt%3B%2Fparam%26gt%3B%0A%20public%20void%20ModifyOutputText(string%20newText)%0A%20%7B%0A%20%20OutputTextString%20%3D%20newText%3B%0A%20%20OutputTextChanged%20%3D%20true%3B%0A%20%7D%0A%0A%20%2F%2F%20Update%20is%20called%20once%20per%20frame%0A%20void%20Update%20()%0A%20%7B%0A%20%20if%20(OutputTextChanged)%0A%20%20%7B%0A%20%20%20OutputTextMesh.text%20%3D%20OutputTextString%3B%0A%20%20%20OutputTextChanged%20%3D%20false%3B%0A%20%20%7D%0A%20%7D%0A%0A%7D%3C%2FPRE%3E%0A%3CH3%20id%3D%22display--some-text-in-the-field-of-view%22%20id%3D%22toc-hId-849000682%22%20id%3D%22toc-hId-849000682%22%3EDisplay%20%F0%9F%93%BA%20some%20text%20in%20the%20field%20of%20view%3C%2FH3%3E%0A%3CP%3E%3CBR%20%2F%3EAdd%20a%20%3CSTRONG%3E%203D%20Text%20%3C%2FSTRONG%3E%20object%20as%20a%20child%20of%20the%20camera%3B%20Name%20it%20%22OutputText%22%3B%20Change%20its%20properties%20as%20shown%20below.%20The%20purpose%20is%20to%20see%20some%20text%20at%20a%20nice%20distance%20and%20in%20the%20center%20of%20the%20field%20of%20view.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20952px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67907i42A74371A29FDC85%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3ETo%20be%20able%20to%20update%20this%20%3CSTRONG%3E%203D%20Text%20%3C%2FSTRONG%3E%20object%2C%20drag%20%26amp%3B%20drop%20the%20%3CSTRONG%3E%20OutputText%20%3C%2FSTRONG%3E%20object%20from%20the%20hierarchy%20to%20the%20%3CSTRONG%3E%20Output%20text%20%3C%2FSTRONG%3E%20property%20of%20the%20%3CSTRONG%3E%20ScriptManager%20%3C%2FSTRONG%3E%20object.%20This%20action%20gives%20to%20the%20UnityScanScene%20class%20the%20reference%20to%20the%203D%20Text%20to%20modify.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20506px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67909iE2C1255A5D542CF7%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3ETo%20do%20a%20small%20verification%2C%20you%20can%20press%20the%20Unity%20PLAY%20button.%20%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20514px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67910iEBD339C697924082%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH3%20id%3D%22camera-scan-engine--%22%20id%3D%22toc-hId--1703156279%22%20id%3D%22toc-hId--1703156279%22%3ECamera%20scan%20engine%20%E2%9A%99%20%F0%9F%8E%A5%3C%2FH3%3E%0A%3CP%3E%3CBR%20%2F%3EOk%2C%20it%20is%20now%20time%20to%20take%20care%20of%20the%20camera%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3EAdd%20a%20new%20folder%20in%20the%20Assets%20named%20%22UWP%22%20in%20order%20to%20place%20within%20it%20only%20C%23%20code%20that%20runs%20on%20Windows.%20%3CBR%20%2F%3E%3CBR%20%2F%3EAdd%20a%20script%20named%20%22ScanEngine%22.%20Here%20is%20the%20Assets%20folder%20look%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20383px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67911iDDC6C7934F271C9D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EReplace%20the%20content%20of%20the%20ScanEngine.cs%20file%20with%20the%20code%20below.%3C%2FP%3E%0A%3CPRE%3E%23if%20UNITY_WSA%20%26amp%3B%26amp%3B%20!UNITY_EDITOR%0Ausing%20System%3B%0Ausing%20System.Linq%3B%0Ausing%20System.Threading.Tasks%3B%0Ausing%20Windows.Media.Capture%3B%0Ausing%20Windows.Media.Capture.Frames%3B%0Ausing%20Windows.Media.MediaProperties%3B%0A%0Apublic%20class%20ScanEngine%0A%7B%0A%20%20%20%20public%20TimeSpan%20PredictionFrequency%20%3D%20TimeSpan.FromMilliseconds(400)%3B%0A%0A%20%20%20%20private%20MediaCapture%20CameraCapture%3B%0A%20%20%20%20private%20MediaFrameReader%20CameraFrameReader%3B%0A%0A%20%20%20%20private%20Int64%20FramesCaptured%3B%0A%0A%20%20%20%20IUnityScanScene%20UnityApp%3B%0A%0A%0A%20%20%20%20public%20ScanEngine()%0A%20%20%20%20%7B%20%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20async%20Task%20Inititalize(IUnityScanScene%20unityApp)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20UnityApp%20%3D%20unityApp%3B%0A%0A%20%20%20%20%20%20%20%20await%20InitializeCameraCapture()%3B%0A%20%20%20%20%20%20%20%20await%20InitializeCameraFrameReader()%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20private%20async%20Task%20InitializeCameraCapture()%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20CameraCapture%20%3D%20new%20MediaCapture()%3B%0A%20%20%20%20%20%20%20%20MediaCaptureInitializationSettings%20settings%20%3D%20new%20MediaCaptureInitializationSettings()%3B%0A%20%20%20%20%20%20%20%20settings.StreamingCaptureMode%20%3D%20StreamingCaptureMode.Video%3B%0A%20%20%20%20%20%20%20%20await%20CameraCapture.InitializeAsync(settings)%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20private%20async%20Task%20InitializeCameraFrameReader()%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20var%20frameSourceGroups%20%3D%20await%20MediaFrameSourceGroup.FindAllAsync()%3B%20%0A%20%20%20%20%20%20%20%20MediaFrameSourceGroup%20selectedGroup%20%3D%20null%3B%0A%20%20%20%20%20%20%20%20MediaFrameSourceInfo%20colorSourceInfo%20%3D%20null%3B%0A%0A%20%20%20%20%20%20%20%20foreach%20(var%20sourceGroup%20in%20frameSourceGroups)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20foreach%20(var%20sourceInfo%20in%20sourceGroup.SourceInfos)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(sourceInfo.MediaStreamType%20%3D%3D%20MediaStreamType.VideoPreview%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%26amp%3B%26amp%3B%20sourceInfo.SourceKind%20%3D%3D%20MediaFrameSourceKind.Color)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20colorSourceInfo%20%3D%20sourceInfo%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20(colorSourceInfo%20!%3D%20null)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20selectedGroup%20%3D%20sourceGroup%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20var%20colorFrameSource%20%3D%20CameraCapture.FrameSources%5BcolorSourceInfo.Id%5D%3B%0A%20%20%20%20%20%20%20%20var%20preferredFormat%20%3D%20colorFrameSource.SupportedFormats.Where(format%20%3D%26gt%3B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20format.Subtype%20%3D%3D%20MediaEncodingSubtypes.Argb32%3B%0A%0A%20%20%20%20%20%20%20%20%7D).FirstOrDefault()%3B%0A%0A%20%20%20%20%20%20%20%20CameraFrameReader%20%3D%20await%20CameraCapture.CreateFrameReaderAsync(colorFrameSource)%3B%0A%20%20%20%20%20%20%20%20await%20CameraFrameReader.StartAsync()%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20void%20StartPullCameraFrames()%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20Task.Run(async%20()%20%3D%26gt%3B%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20(%3B%20%3B%20)%20%2F%2F%20Forever%20%3D%20While%20the%20app%20runs%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20FramesCaptured%2B%2B%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20await%20Task.Delay(PredictionFrequency)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20using%20(var%20frameReference%20%3D%20CameraFrameReader.TryAcquireLatestFrame())%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20using%20(var%20videoFrame%20%3D%20frameReference%3F.VideoMediaFrame%3F.GetVideoFrame())%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(videoFrame%20%3D%3D%20null)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%3B%20%2F%2Fignoring%20frame%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(videoFrame.Direct3DSurface%20%3D%3D%20null)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20videoFrame.Dispose()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20continue%3B%20%2F%2Fignoring%20frame%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20try%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20HERE%2C%20We%20will%20evaluate%20the%20model%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20catch%20(Exception%20ex)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20System.Diagnostics.Debug.WriteLine(ex.Message)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20finally%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%7D%0A%0A%7D%0A%23endif%3C%2FPRE%3E%0A%3CP%3E%3CCODE%3E%3CBR%20%2F%3E%0A%20%20%3C%2FCODE%3E%20%3CBR%20%2F%3EThe%20UnityScanScene.cs%20script%20will%20use%20this%20class%20this%20way%3A%3C%2FP%3E%0A%3CPRE%3E%20async%20void%20Start%20()%0A%20%7B%0A%20%20%20%20%20%20%20%20OutputTextMesh%20%3D%20OutputText.GetComponent%26lt%3BTextMesh%26gt%3B()%3B%0A%20%20%20%20%20%20%20%20OutputTextMesh.text%20%3D%20string.Empty%3B%0A%0A%23if%20UNITY_WSA%20%26amp%3B%26amp%3B%20!UNITY_EDITOR%20%2F%2F%20RUNNING%20ON%20WINDOWS**%0A%20%20%20%20%20%20%20%20CameraScanEngine%20%3D%20new%20ScanEngine()%3B%20%20%20%20%20%20%20%2F%2F%20%26lt%3B--%201%0A%20%20%20%20%20%20%20%20await%20CameraScanEngine.Inititalize(this)%3B%20%20%2F%2F%20%26lt%3B--%202%0A%20%20%20%20%20%20%20%20CameraScanEngine.StartPullCameraFrames()%3B%20%20%2F%2F%20%26lt%3B--%203%0A%23else%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20RUNNING%20IN%20UNITY**%0A%20%20%20%20%20%20%20%20ModifyOutputText(%22Sorry%20%3B-(%20The%20app%20is%20not%20supported%20in%20the%20Unity%20player.%22)%3B%0A%23endif%0A%20%7D%3C%2FPRE%3E%0A%3CP%3E%3CCODE%3E%3CBR%20%2F%3E%0A%20%20%3C%2FCODE%3E%20%3CBR%20%2F%3E%E2%9D%97%20It%20is%20now%20time%20to%20modify%20the%20UnityScanScene.cs%20accordingly%20in%20order%20to%20have%20the%20code%20above%20for%20the%20Start%20method.%20%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%20to%20give%20you%20some%20explanations%20%F0%9F%98%85.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EWe%20create%20our%20Camera%20helper%20%3CSTRONG%3E%20CameraScanEngine%20%3C%2FSTRONG%3E%20from%20the%20%3CSTRONG%3E%20ScanEngine%20%3C%2FSTRONG%3E%20class.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3ECalling%20%3CCODE%3E%0A%20%20%20%20%20CameraScanEngine.Inititalize(this)%0A%20%20%20%20%3C%2FCODE%3E%20in%20the%20UnityScanScene.cs%20startup%20script%20gives%20the%20ability%20to%20call%20the%20public%20%3CSTRONG%3E%20ModifyOutputText%20%3C%2FSTRONG%3E%20method%20of%20the%20IUnityScanScene%20interface%20from%20the%20CameraScanEngine%20object.%20Here%20is%20the%20proof%3A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20589px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67913i6540BDE27B34AB3D%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EAlso%2C%20it%20really%20initializes%20the%20HoloLens%20camera%20for%20being%20able%20to%20capture%20the%20video%20frames.%20Under%20the%20hood%2C%20we%20use%20the%20%3CCODE%3E%0A%20%20%20MediaCapture%0A%20%20%3C%2FCODE%3E%20class.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EThe%20HoloLens%20camera%20is%20initialized%20and%20we%20can%20get%20the%20frames.%20The%20%3CCODE%3E%0A%20%20%20%20%20StartPullCameraFrames()%0A%20%20%20%20%3C%2FCODE%3E%20call%20initiates%20an%20infinite%20loop%20for%20pulling%20for%20frames.%20We%20will%20replace%20the%20line%20%3CCODE%3E%0A%20%20%20%20%20%2F%2F%20HERE%2C%20We%20will%20evaluate%20the%20model%0A%20%20%20%20%3C%2FCODE%3E%20by%20the%20code%20for%20evaluating%20the%20model%20on%20the%20frame%20later.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20this%20camera%20helper%20code%2C%20I%20thank%20Etienne%20Margraff%20with%20his%20article%20(%20%3CA%20href%3D%22https%3A%2F%2Fmeulta.com%2Fen%2F2018%2F05%2F18%2Fexperimenting-with-windows-machine-learning-and-mixed-reality%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Preview%20API%20-%20Experimenting%20with%20Windows%20Machine%20Learning%20and%20Mixed%20Reality%20%3C%2FA%3E%20-%20Feel%20free%20to%20read%20it%20for%20further%20details%20about%20this%20code).%3C%2FP%3E%0A%3CH2%20id%3D%22step-4-integrate--the-model-in-the-app%22%20id%3D%22toc-hId-236167561%22%20id%3D%22toc-hId-236167561%22%3EStep%204.%20Integrate%20%E2%A4%B5%20the%20model%20in%20the%20app%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22adding-the-file-in-the-package-%22%20id%3D%22toc-hId-1067303102%22%20id%3D%22toc-hId-1067303102%22%3EAdding%20the%20file%20in%20the%20package%20%F0%9F%93%A5%3C%2FH3%3E%0A%3CP%3E%3CBR%20%2F%3EBack%20to%20step%202%2C%20we%20saved%20the%20model%20as%20a%20ONNX%201.2%20file%20on%20the%20disk.%20It%20is%20now%20time%20to%20add%20it%20to%20the%20Unity%20App%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3EJust%20name%20the%20model%20%22ONNXModel.onnx%22%20and%20drag%20%26amp%3B%20drop%20it%20to%20a%20new%20folder%20named%20%3CSTRONG%3E%20StreamingAssets%20%3C%2FSTRONG%3E%20in%20the%20%3CSTRONG%3E%20Assets%20%3C%2FSTRONG%3E%20folder.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20383px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67915i942C3E766A997A77%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EThis%20%3CA%20href%3D%22https%3A%2F%2Fdocs.unity3d.com%2FManual%2FStreamingAssets.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20StreamingAssets%20folder%20%3C%2FA%3E%20is%20special%20for%20Unity%3A%20it%20will%20be%20copied%20to%20the%20%3CSTRONG%3E%20Data%20%3C%2FSTRONG%3E%20folder%20inside%20the%20UWP%20application%20that%20will%20be%20deployed%20on%20the%20HoloLens.%20This%20way%2C%20we%20will%20be%20able%20to%20load%20the%20file%20by%20code%20from%20the%20package%20installation%20folder.%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%20%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3E%20It%20is%20also%20possible%20to%20add%20the%20ONNX%20file%20directly%20to%20the%20resulting%20C%23%20UWP%20application.%20The%20Unity%20way%20of%20adding%20it%20is%20not%20mandatory.%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22add-a-wrapper-class--for-the-model%22%20id%3D%22toc-hId--1484853859%22%20id%3D%22toc-hId--1484853859%22%3EAdd%20a%20wrapper%20class%20%F0%9F%94%A7%20for%20the%20model%3C%2FH3%3E%0A%3CP%3E%3CBR%20%2F%3EThis%20was%20the%20tricky%20part%20of%20the%20job%20and%20the%20one%20that%20changed%20from%20the%20Preview%20APIs%20and%20the%20ones%20released.%20The%20long%20story%20is%20well%20detailed%20by%20Matteo%20Pagani%20in%20the%20two%20referenced%20articles%20(%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fappconsult%2F2018%2F05%2F23%2Fadd-a-bit-of-machine-learning-to-your-windows-application-thanks-to-winml%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Preview%20API%20-%20Add%20a%20bit%20of%20machine%20learning%20to%20your%20Windows%20application%20thanks%20to%20WinML%20%3C%2FA%3E%20and%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fappconsult%2F2018%2F11%2F06%2Fupgrade-your-winml-application-to-the-latest-bits%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Upgrade%20your%20WinML%20application%20to%20the%20latest%20bits%20%3C%2FA%3E%20).%20%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20today%2C%20long%20story%20short%3A%20we%20do%20not%20use%20the%20generated%20class%20by%20Visual%20Studio%20for%20our%20model%20wrapper%20but%20the%20following%20one%20below.%20This%20class%20is%20'generic'%20and%20works%20for%20your%20own%20custom%20vision%20trained%20model.%20%3CBR%20%2F%3E%3CBR%20%2F%3EHere%20are%20the%20steps%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3EIn%20Unity%2C%20add%20a%20new%20script%20named%20'ONNXModel'%20in%20the%20%3CSTRONG%3E%20Assets%2FUWP%20%3C%2FSTRONG%3E%20folder.%20This%20is%20our%20'generic'%20model%20wrapper%20class.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20382px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67917i9A13DB30033A69EE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EDouble%20click%20on%20%3CSTRONG%3E%20ONNXModel.cs%20%3C%2FSTRONG%3E%20and%20replace%20the%20content%20of%20the%20script%20by%20the%20following%20code%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%23if%20UNITY_WSA%20%26amp%3B%26amp%3B%20!UNITY_EDITOR%0Ausing%20System%3B%0Ausing%20System.Collections.Generic%3B%0Ausing%20System.Diagnostics%3B%0Ausing%20System.Threading.Tasks%3B%0Ausing%20Windows.AI.MachineLearning%3B%0Ausing%20Windows.Media%3B%0Ausing%20Windows.Storage%3B%0A%0Apublic%20sealed%20class%20ONNXModelInput%0A%7B%0A%20%20%20%20public%20VideoFrame%20Data%20%7B%20get%3B%20set%3B%20%7D%0A%7D%0A%0Apublic%20sealed%20class%20ONNXModelOutput%0A%7B%0A%20%20%20%20public%20TensorString%20ClassLabel%20%3D%20TensorString.Create(new%20long%5B%5D%20%7B%201%2C%201%20%7D)%3B%0A%20%20%20%20public%20IList%26lt%3BIDictionary%26lt%3Bstring%2C%20float%26gt%3B%26gt%3B%20Loss%20%3D%20new%20List%26lt%3BIDictionary%26lt%3Bstring%2C%20float%26gt%3B%26gt%3B()%3B%0A%7D%0A%0A%2F%2F%2F%20%26lt%3Bsummary%26gt%3B%0A%2F%2F%2F%20These%20classes%20ONNXModel%2C%20ONNXModelInput%2C%20ONNXModelOutput%20never%20change%0A%2F%2F%2F%20We%20just%20load%20a%20different%20custom%20model%0A%2F%2F%2F%20%0A%2F%2F%2F%20In%20order%20to%20evalutate%20a%20model%3A%0A%2F%2F%2F%201.%20Call%20the%20static%20method%20ONNXModel.CreateOnnxModel(%26lt%3B%26lt%3BMyModelStorageFile%26gt%3B%26gt%3B)%0A%2F%2F%2F%202.%20Call%20EvaluateAsync%20method%20on%20the%20created%20Model%20before%0A%2F%2F%2F%20%26lt%3B%2Fsummary%26gt%3B%0Apublic%20sealed%20class%20ONNXModel%0A%7B%0A%20%20%20%20private%20LearningModel%20_learningModel%20%3D%20null%3B%0A%20%20%20%20private%20LearningModelSession%20_session%3B%0A%0A%20%20%20%20public%20static%20async%20Task%26lt%3BONNXModel%26gt%3B%20CreateOnnxModel(StorageFile%20file)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20LearningModel%20learningModel%20%3D%20null%3B%0A%0A%20%20%20%20%20%20%20%20try%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20learningModel%20%3D%20await%20LearningModel.LoadFromStorageFileAsync(file)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20catch%20(Exception%20e)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20exceptionStr%20%3D%20e.ToString()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20Debug.WriteLine(exceptionStr)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20throw%20e%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20return%20new%20ONNXModel()%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20_learningModel%20%3D%20learningModel%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20_session%20%3D%20new%20LearningModelSession(learningModel)%0A%20%20%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20async%20Task%26lt%3BONNXModelOutput%26gt%3B%20EvaluateAsync(ONNXModelInput%20input)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20var%20output%20%3D%20new%20ONNXModelOutput()%3B%0A%20%20%20%20%20%20%20%20var%20binding%20%3D%20new%20LearningModelBinding(_session)%3B%0A%20%20%20%20%20%20%20%20binding.Bind(%22data%22%2C%20input.Data)%3B%0A%20%20%20%20%20%20%20%20binding.Bind(%22classLabel%22%2C%20output.ClassLabel)%3B%0A%20%20%20%20%20%20%20%20binding.Bind(%22loss%22%2C%20output.Loss)%3B%0A%20%20%20%20%20%20%20%20LearningModelEvaluationResult%20evalResult%20%3D%20await%20_session.EvaluateAsync(binding%2C%20%220%22)%3B%0A%0A%20%20%20%20%20%20%20%20return%20output%3B%0A%20%20%20%20%7D%0A%7D%0A%23endif%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%20%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3E%20All%20code%20dedicated%20to%20UWP%20is%20surrounded%20by%20%3CCODE%3E%0A%20%20%20%20%23if%20UNITY_WSA%20%26amp%3B%26amp%3B%20!UNITY_EDITOR%0A%20%20%20%3C%2FCODE%3E%20.%20It%20allows%20us%20to%20be%20sure%20to%20run%20this%20code%20only%20on%20Windows.%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3EThe%20%3CCODE%3E%0A%20%20%20CreateOnnxModel()%0A%20%20%3C%2FCODE%3E%20static%20method%20is%20in%20charge%20of%20loading%20the%20file.%20The%20%3CCODE%3E%0A%20%20%20EvaluateAsync()%0A%20%20%3C%2FCODE%3E%20performs%20the%20model'%20evaluation.%20%3CBR%20%2F%3E%3CBR%20%2F%3EAgain%2C%20this%20code%20will%20not%20change%20if%20you%20create%20your%20own%20custom%20vision%20model%20(Classification%20%2F%20Multilabel%20%2F%20General%20Compact).%20%3CBR%20%2F%3E%3CBR%20%2F%3ELet's%20add%20now%20a%20'high%20level'%20model%20helper%20in%20order%20to%20put%20the%20glue%20between%20the%20captured%20frame%20and%20the%20model%20evaluation.%3C%2FP%3E%0A%3CH3%20id%3D%22load--and-evaluate--the-model-for-each-frame%22%20id%3D%22toc-hId-257956476%22%20id%3D%22toc-hId-257956476%22%3ELoad%20%F0%9F%93%A4%20and%20evaluate%20%E2%9A%99%20the%20model%20for%20each%20frame%3C%2FH3%3E%0A%3CP%3E%3CBR%20%2F%3EIn%20Unity%2C%20add%20a%20new%20script%20named%20'ONNXModelHelper'%20in%20the%20%3CSTRONG%3E%20Assets%2FUWP%20%3C%2FSTRONG%3E%20folder.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20383px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67918i118F7596E1BF95C0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EUse%20this%20code%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%23if%20UNITY_WSA%20%26amp%3B%26amp%3B%20!UNITY_EDITOR%0Ausing%20System%3B%0Ausing%20System.Diagnostics%3B%0Ausing%20System.Threading.Tasks%3B%0Ausing%20Windows.Media%3B%0Ausing%20Windows.Storage%3B%0A%0Apublic%20class%20ONNXModelHelper%0A%7B%0A%20%20%20%20private%20ONNXModel%20Model%20%3D%20null%3B%0A%20%20%20%20private%20string%20ModelFilename%20%3D%20%22ONNXModel.onnx%22%3B%0A%20%20%20%20private%20Stopwatch%20TimeRecorder%20%3D%20new%20Stopwatch()%3B%0A%20%20%20%20private%20IUnityScanScene%20UnityApp%3B%0A%0A%20%20%20%20public%20ONNXModelHelper()%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20UnityApp%20%3D%20null%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20ONNXModelHelper(IUnityScanScene%20unityApp)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20UnityApp%20%3D%20unityApp%3B%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20async%20Task%20LoadModelAsync()%20%2F%2F%20%26lt%3B--%201%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20ModifyText(%24%22Loading%20%7BModelFilename%7D...%20Patience%22)%3B%0A%0A%20%20%20%20%20%20%20%20try%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20TimeRecorder%20%3D%20Stopwatch.StartNew()%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20modelFile%20%3D%20await%20StorageFile.GetFileFromApplicationUriAsync(%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20new%20Uri(%24%22ms-appx%3A%2F%2F%2FData%2FStreamingAssets%2F%7BModelFilename%7D%22))%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20Model%20%3D%20await%20ONNXModel.CreateOnnxModel(modelFile)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20TimeRecorder.Stop()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20ModifyText(%24%22Loaded%20%7BModelFilename%7D%3A%20Elapsed%20time%3A%20%7BTimeRecorder.ElapsedMilliseconds%7D%20ms%22)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20catch%20(Exception%20ex)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20ModifyText(%24%22error%3A%20%7Bex.Message%7D%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20Model%20%3D%20null%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%0A%20%20%20%20public%20async%20Task%20EvaluateVideoFrameAsync(VideoFrame%20frame)%20%2F%2F%20%26lt%3B--%202%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20if%20(frame%20!%3D%20null)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20try%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20TimeRecorder.Restart()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ONNXModelInput%20inputData%20%3D%20new%20ONNXModelInput()%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20inputData.Data%20%3D%20frame%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20output%20%3D%20await%20Model.EvaluateAsync(inputData).ConfigureAwait(false)%3B%20%2F%2F%20%26lt%3B--%203%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20product%20%3D%20output.ClassLabel.GetAsVectorView()%5B0%5D%3B%20%2F%2F%20%26lt%3B--%204%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20loss%20%3D%20output.Loss%5B0%5D%5Bproduct%5D%3B%20%2F%2F%20%26lt%3B--%205%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20TimeRecorder.Stop()%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20lossStr%20%3D%20string.Join(product%2C%20%22%20%22%20%2B%20(loss%20*%20100.0f).ToString(%22%230.00%22)%20%2B%20%22%25%22)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20string%20message%20%3D%20%24%22(%7BDateTime.Now.Hour%7D%3A%7BDateTime.Now.Minute%7D%3A%7BDateTime.Now.Second%7D)%22%20%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%24%22%20Evaluation%20took%20%7BTimeRecorder.ElapsedMilliseconds%7Dms%5Cn%22%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20string%20prediction%20%3D%20%24%22Prediction%3A%20%7Bproduct%7D%20%7BlossStr%7D%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(loss%20%26gt%3B%200.5f)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20message%20%2B%3D%20prediction%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20message%20%3D%20message.Replace(%22%5C%5Cn%22%2C%20%22%5Cn%22)%3B%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ModifyText(message)%3B%20%2F%2F%20%26lt%3B--%206%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20%20%20catch%20(Exception%20ex)%0A%20%20%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20var%20err_message%20%3D%20%24%22error%3A%20%7Bex.Message%7D%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ModifyText(err_message)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%0A%20%20%20%20private%20void%20ModifyText(string%20text)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20System.Diagnostics.Debug.WriteLine(text)%3B%0A%20%20%20%20%20%20%20%20if%20(UnityApp%20!%3D%20null)%0A%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20UnityApp.ModifyOutputText(text)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D%0A%23endif%3C%2FPRE%3E%0A%3CP%3E%3CBR%20%2F%3EExplanations%20%F0%9F%93%9A%3A%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EThe%20helper%20method%20effectively%20loads%20the%20ONNX%20Model%20using%20%3CCODE%3E%0A%20%20%20%20%20StorageFile.GetFileFromApplicationUriAsync()%0A%20%20%20%20%3C%2FCODE%3E%20.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3E%3CCODE%3E%0A%20%20%20%20%20EvaluateVideoFrameAsync()%0A%20%20%20%20%3C%2FCODE%3E%20is%20called%20by%20the%20ScanEngine%20for%20every%20frame.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3ESo%2C%20there%20is%20an%20action%20for%20you%20%F0%9F%98%85%3A%20Please%20replace%20%3CCODE%3E%0A%20%20%20%2F%2F%20HERE%2C%20We%20will%20evaluate%20the%20model%0A%20%20%3C%2FCODE%3E%20by%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CCODE%3E%0A%20%20%20await%20ModelHelper.EvaluateVideoFrameAsync(videoFrame).ConfigureAwait(false)%3B%0A%20%20%3C%2FCODE%3E%20.%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3E%3CCODE%3E%0A%20%20%20%20%20Model.EvaluateAsync()%0A%20%20%20%20%3C%2FCODE%3E%20calls%20the%20wrapper%20method%20for%20the%20model's%20evaluation.%20We%20get%20the%20result%20in%20the%20%3CSTRONG%3E%20output%20%3C%2FSTRONG%3E%20object.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3E%3CCODE%3E%0A%20%20%20%20%20var%20product%20%3D%20output.ClassLabel.GetAsVectorView()%5B0%5D%0A%20%20%20%20%3C%2FCODE%3E%20is%20the%20name%20of%20the%20most%20scored%20prediction.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3E%3CCODE%3E%0A%20%20%20%20%20output.Loss%5B0%5D%5Bproduct%5D%0A%20%20%20%20%3C%2FCODE%3E%20is%20the%20score%20of%20this%20prediction.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3COL%3E%0A%3CLI%3EWe%20call%20the%20private%20method%20%3CCODE%3E%0A%20%20%20%20%20ModifyText%0A%20%20%20%20%3C%2FCODE%3E%20to%20modify%20the%20text%20to%20display%20in%20HoloLens%20thanks%20to%20%3CCODE%3E%0A%20%20%20%20%20UnityApp.ModifyOutputText()%0A%20%20%20%20%3C%2FCODE%3E%20.%20The%20display%20is%20about%20giving%20the%20predication%20and%20the%20score.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3EWe%20should%20have%20all%20set%20%F0%9F%A4%AF%F0%9F%98%AA%F0%9F%A5%B3!%20You%20just%20have%20to%20build%20the%20Unity%20app%3B%20It%20generates%20the%20C%23%20UWP%20Solution%20that%20you%20can%20compile%20%3CSTRONG%3Ein%20%20MASTER%20x%3C%2FSTRONG%3E86%20%20and%20deploy%20to%20you%20HoloLens.%20%3CBR%20%2F%3E%3CBR%20%2F%3EHere%20is%20what%20you%20can%20get%20%F0%9F%98%82%3CBR%20%2F%3E%3CBR%20%2F%3E%3CEM%3E%20%20Good%20prediction%20for%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fbenoitlp%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20%20Benoit%3C%2FA%3E%20%20!%3C%2FEM%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20450px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67920iBD0B27A9E649B99E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CEM%3E%20%20A%20'low'%20prediction%20for%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2FFlo_Plsr%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20%20Florent%3C%2FA%3E%20%20(who%20is%20not%20me%20%F0%9F%98%89%20and%20who%20was%20not%20part%20of%20the%20Model's%20trainin%3C%2FEM%3Eg)%20%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20450px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67922iB3AE03F2B5094551%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%20%3CSTRONG%3EDisclaimer%20%E2%9A%96%3A%20%3C%2FSTRONG%3E%20Again%2C%20this%20model%20was%20only%20trained%20with%20less%20than%2020%20pictures%20which%20is%20a%20way%20too%20low%20to%20pretend%20having%20a%20correct%20model%20for%20prediction.%20But%20you%20have%20the%20idea!%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3EAll%20updated%20and%20optimized%20source%20code%20is%20on%20GitHub%20-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FMicrosoft%2FWindows-AppConsult-Samples-MixedReality%2Ftree%2Fmaster%2FHoloLensWinML%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fgithub.com%2FMicrosoft%2FWindows-AppConsult-Samples-MixedReality%2Ftree%2Fmaster%2FHoloLensWinML%20%3C%2FA%3E%20.%3C%2FP%3E%0A%3CH2%20id%3D%22conclusion%22%20id%3D%22toc-hId--497249126%22%20id%3D%22toc-hId--497249126%22%3EConclusion%3C%2FH2%3E%0A%3CP%3E%3CBR%20%2F%3ETalking%20about%20performance%3A%20The%20app%20deployed%20on%20HoloLens%20loads%20the%20~3Mb%20ONNX%20model%20in%20about%20300ms.%20The%20model's%20evaluation%20is%20done%20in%20average%20in%20250%20to%20400ms.%20So%20right%20now%2C%20we%20have%20a%20minimum%20of%202%20frames%20analyzed%20by%20second%3B%20Based%20on%20the%20fact%20that%20only%20the%20HoloLens%20processor%20does%20the%20job%2C%20it%20is%20pretty%20good%3A%20We%20can%20imagine%20scenarios%20in%20factories%20for%20safety%20or%20monitoring%2C%20in%20maintenance%20or%20diagnostics%20operations%20or%20even%20in%20medical%20assistance.%20%3CBR%20%2F%3E%3CBR%20%2F%3EThe%20future%3F%20Who%20knows%3F%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fakipman%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20Alex%20Kipman%20%3C%2FA%3E%20and%20his%20team%20for%20sure%20%F0%9F%98%89%3CBR%20%2F%3E%3CBR%20%2F%3E%20What%20I%20can%20say%20is%20that%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fresearch%2Fblog%2Fsecond-version-hololens-hpu-will-incorporate-ai-coprocessor-implementing-dnns%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20%20work%20is%20in%20progress%20a%20new%20Holographic%20Processing%20Unit%20(HPU)%20for%20HoloLens%3C%2FA%3E%20%20%3A%3C%2FP%3E%0A%3CBLOCKQUOTE%3E...the%20second%20version%20of%20the%20HPU%2C%20currently%20under%20development%2C%20will%20incorporate%20an%20AI%20coprocessor%20to%20natively%20and%20flexibly%20implement%20DNNs.%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3EDNN%20stands%20for%20%3CSTRONG%3E%20Deep%20Neural%20Networks%20%3C%2FSTRONG%3E%20which%20is%20what%20we%20are%20using%20%F0%9F%8E%89.%20We%20can%20expect%20that%20this%20future%20AI%20chip%20would%20be%20dedicated%20for%20this%20kind%20of%20work%20and%20performance%20would%20be%20decoupled%20%F0%9F%92%B9!%3CBR%20%2F%3E%3CBR%20%2F%3E%20Last%20word%20of%20this%20article%20is%20from%20the%20link%20above%3A%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%3CBR%20%2F%3E%0A%3CH2%20id%3D%22mixed-reality-and-artificial-intelligence-represent-the-future-of-computing-and-were-excited-to-be-advancing-this-frontier%22%20id%3D%22toc-hId-1245561209%22%20id%3D%22toc-hId-1245561209%22%3EMixed%20reality%20and%20artificial%20intelligence%20represent%20the%20future%20of%20computing%2C%20and%20we%E2%80%99re%20excited%20to%20be%20advancing%20this%20frontier.%3C%2FH2%3E%0A%3C%2FBLOCKQUOTE%3E%0A%3CP%3E%3CBR%20%2F%3EBye%2C%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fsbovo%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20%40sbovo%20%3C%2FA%3E%20for%20the%20%F0%9F%92%BB%20%F0%9F%8E%AE%20Windows%20AppConsult%20team.%20%3CBR%20%2F%3E%3CBR%20%2F%3E--%3C%2FP%3E%0A%3CH2%20id%3D%22credits%22%20id%3D%22toc-hId--1306595752%22%20id%3D%22toc-hId--1306595752%22%3ECredits%3C%2FH2%3E%0A%3CP%3E%3CBR%20%2F%3EI%20would%20like%20to%20thank%20%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fmeulta%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EEtienne%20Margraff%20%3C%2FA%3E%20for%20the%20first%20article%20on%20this%20topic%20on%20HoloLens%2F%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fqmatteoq%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EMatteo%20Pagani%20%3C%2FA%3E%20for%20his%20articles%20and%20reviewing%20this%20one.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2Fbenoitlp%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EBenoit%20%3C%2FA%3E%20my%20co-presenter%20on%20Mixed%20Reality%20events%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E%20%3CA%20href%3D%22https%3A%2F%2Ftwitter.com%2FFlo_Plsr%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EFlorent%20%3C%2FA%3E%20for%20his%20support%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CH2%20id%3D%22references%22%20id%3D%22toc-hId-436214583%22%20id%3D%22toc-hId-436214583%22%3EReferences%3C%2FH2%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EAll%20source%20code%20HOLOLENS%20V2-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fsbovo%2FHoloLens-Windows-MachineLearning%2Ftree%2Fmaster%2FHoloLensV2WinML%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Fsbovo%2FHoloLens-Windows-MachineLearning%2Ftree%2Fmaster%2FHoloLensV2WinML%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EAll%20source%20code%20HOLOLENS%20V1-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FMicrosoft%2FWindows-AppConsult-Samples-MixedReality%2Ftree%2Fmaster%2FHoloLensWinML%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fgithub.com%2FMicrosoft%2FWindows-AppConsult-Samples-MixedReality%2Ftree%2Fmaster%2FHoloLensWinML%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ECustom%20Vision%20-%20%3CA%20href%3D%22https%3A%2F%2Fwww.customvision.ai%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fwww.customvision.ai%2F%3C%2FA%3E%20%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EWindows%20Machine%20Learning%20-%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Ffr-fr%2Fwindows%2Fai%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fdocs.microsoft.com%2Ffr-fr%2Fwindows%2Fai%2F%3C%2FA%3E%20%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3ESecond%20version%20of%20HoloLens%20HPU%20will%20incorporate%20AI%20coprocessor%20for%20implementing%20DNNs%20-%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fresearch%2Fblog%2Fsecond-version-hololens-hpu-will-incorporate-ai-coprocessor-implementing-dnns%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fresearch%2Fblog%2Fsecond-version-hololens-hpu-will-incorporate-ai-coprocessor-implementing-dnns%2F%3C%2FA%3E%20%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EOpen%20Neural%20Network%20Exchange%20Github%20-%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Fonnx%2Fonnx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fgithub.com%2Fonnx%2Fonnx%3C%2FA%3E%20%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EONNX%20Format%20initiative%20-%20%3CA%20href%3D%22https%3A%2F%2Fonnx.ai%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fonnx.ai%2F%3C%2FA%3E%20%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E(Preview%20API)%20Experimenting%20with%20Windows%20Machine%20Learning%20and%20Mixed%20Reality%20-%20%3CA%20href%3D%22https%3A%2F%2Fmeulta.com%2Fen%2F2018%2F05%2F18%2Fexperimenting-with-windows-machine-learning-and-mixed-reality%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fmeulta.com%2Fen%2F2018%2F05%2F18%2Fexperimenting-with-windows-machine-learning-and-mixed-reality%2F%3C%2FA%3E%20%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3E(Preview%20API)%20Add%20a%20bit%20of%20machine%20learning%20to%20your%20Windows%20application%20thanks%20to%20WinML%20-%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fappconsult%2F2018%2F05%2F23%2Fadd-a-bit-of-machine-learning-to-your-windows-application-thanks-to-winml%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fblogs.msdn.microsoft.com%2Fappconsult%2F2018%2F05%2F23%2Fadd-a-bit-of-machine-learning-to-your-windows-application-thanks-to-winml%2F%3C%2FA%3E%20%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EUpgrade%20your%20WinML%20application%20to%20the%20latest%20bits%20-%20%3CA%20href%3D%22https%3A%2F%2Fblogs.msdn.microsoft.com%2Fappconsult%2F2018%2F11%2F06%2Fupgrade-your-winml-application-to-the-latest-bits%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fblogs.msdn.microsoft.com%2Fappconsult%2F2018%2F11%2F06%2Fupgrade-your-winml-application-to-the-latest-bits%2F%3C%2FA%3E%20%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CUL%3E%0A%3CLI%3EIntegrate%20a%20model%20into%20your%20app%20with%20Windows%20ML%20-%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Ffr-fr%2Fwindows%2Fai%2Fintegrate-model%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fdocs.microsoft.com%2Ffr-fr%2Fwindows%2Fai%2Fintegrate-model%3C%2FA%3E%20%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-318077%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20MSDN%20on%20Nov%2015%2C%202018%20Artificial%20Intelligence%20is%20everywhere%20and%20powered%20by%20the%20Cloud.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-318077%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ecustom%20vision%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EHoloLens%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMachine%20Learning%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Emixed%20reality%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eunity%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EUWP%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EVisual%20Studio%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Ewinml%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

First published on MSDN on Nov 15, 2018
Artificial Intelligence is everywhere and powered by the Cloud. We can now go even further and bring AI to HoloLens gracefully thanks to Windows Machine Learning and Windows 10!

Let's go and make it real with a full working and reusable sample. Yes! Reusable because, you can train your own Custom Vision model and run it using this sample ♻ without any code modification.

Note: My colleagues Etienne Margraff and Matteo Pagani already gave lot of details and useful explanations about Windows ML. Feel free to refer to their good blog posts in the References section at the end of this article.


The idea is the following:

    • We use a Custom Vision model that we train in Azure to recognize objects/situations/machines/persons/etc. (In fact, almost what you want 😏).

 

    • We export this model as a ONNX 1.2 file.

 

    • We develop a HoloLens app which gets video frames in continue.



⏩✔ The app uses the model locally for evaluation and predicts what is in front of the user wearing the HoloLens!

--

Step 1. Train 🥼 a Machine Learning Model in Azure

 

🆕 Create the Custom Vision model


Connect to https://www.customvision.ai/ and click on the NEW PROJECT button to create a new Custom Vision project.



Fill in the details:

    • A name and a description .





    • Choose if you want to use the Limited Trial mode or use/create an Azure resource group for hosting the Custom Vision service in Azure.



Note: Choosing the resource group option makes sense if you want to use your Custom Vision model everywhere. I mean: it uses Azure to provide a REST endpoint API that can be used in mobile apps or on computers running Windows, MacOS, Linux or even in Web sites. And all this, without to worry about the technology used.

For evaluating the model locally on the HoloLens, you can go for the Limited Trial as we will not use the Azure Custom Vision endpoint. Please note that, later, if you want to instantiate an Azure resource for this Custom Vision model's evaluation on other platforms, you can do it by clicking on the gear on the top right of the page:



Then, at the bottom of the details' page for your model, you create the Azure resource by clicking on the Move To Azure button:


So, let's go back to our model creation:

    • Choose Classification for the project type. That means that we would like to tag the whole image.



Note: For your information, Object Detection finds also the location of the object within an image.



    • Go for Multilabel (Multiple tags per image) as we would like to not be blocked to use only one tag. As an example: The image can contain a machine factory B214 type 2 and another machine whom id is A78 Alpha2. Tags applied to the image will be "B214 type 2" and "A78 Alpha2".





    • Lastly, but may be the most important, ⚠ take General (compact) ⚠. Choosing a compact model is mandatory to be able to use it with Windows ML on HoloLens or in a Windows 10 UWP app.





🆗 We are all set for the creation!

⚗ Train the model


To do so, the steps are straight forward:

    1. Just upload photos using the Add images button.





    1. Give one or more tags to the images to upload.





At any time, you can review, add or change the tags to the images.


When you are done, click on the Train button.


For more details, feel free to read Test and retrain a model with Custom Vision Service .

Here are some explanations about the results we get:

    1. You can change the Probability Threshold for a prediction to be valid. For example: 85% means that any predictions whom score < 85% will not be considered as a valid prediction.

 

    1. Precision = Gives you the % of correct predictions. For example: For Benoit , we have 7 tagged pictures and the model's evaluation predicted this tag for all 7 pictures (so 100%).

 

    1. Recall = Gives you the % of found tags. For example: For Sebastien , we have 12 tagged pictures and the model was able to predict this tag for 91,7% of the pictures (11 pictures).



Step 2. Export 📦 the model as ONNX 1.2


Again, this steps is easy and well documented by the article written by Matteo : Just click on the Export button.


⚠ Be sure to choose the ONNX 1.2 format



You see there that your app will run on Windows starting at the Build 17738 which means Windows version 1809 or above.

Note: As I write this article, the Windows version 1809 can be installed on HoloLens by participating to the Windows Insider Preview Slow ring.

 

Step 3. Create a Unity App 🕹 for HoloLens that captures the camera 🎥 frames

 

Project setup 📏


I worked with the following versions:

    • Windows version 1809 for the PC and HoloLens

 

    • Visual Studio 2017 version 15.9.0

 

    • Windows SDK version 10.0.17763.0

 

    • Unity 2017.4.13f1



Note: You can skip this part if you are familiar with Unity and Mixed Reality.

If not, please refer to Create a Windows Mixed Reality App from 0 – The Unity project .


The Unity project has to be configured for Windows Mixed Reality:

    • File menu / Build Settings Universal Windows Platform selected as the Build platform

 

    • Edit menu / Project Settings / Player Virtual Reality Supported checked

 

    • Edit menu / Project Settings / Player Other Settings / .NET as Scripting Backend. Please also use the Experimental (.NET 4.6 Equivalent) for the Scripting Runtime Version.



Technical piping 🔩 for being able to give update to the user


The purpose is to be able to display a text message in front of the user from any code within the app. We first add a startup script to the scene:

From the GameObject menu Create an empty object and name it "ScriptManager".



Select the ScriptManager object in the Hierarchy and click on Add Componennt / new script and name it "UnityScanScene".




Double click on the UnityScanScene script to modify it in Visual Studio; Replace the existing code by the one below. Let me give you some details:

    • We use an interface IUnityScanScene with one unique public method ModifyOutputText .

 

    • The startup script we are modifying (UnityScanScene) implements this interface. The method ModifyOutputText just modifies a string.

 

    • The Update method of the script (UnityScanScene) is executed for each frame. We just modify the text of a 3D Text object based on the modified string.



All this "piping" is really useful for giving feedback to the user (text or other) from any code from any class within the project. You will see it in action later in this article.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// The Interface gives one method to implement. This method modifies the text to display in Unity
/// Any code can then call this method outside the Unity MonoBehavior object
/// </summary>
public interface IUnityScanScene
{
	void ModifyOutputText(string newText);
}

public class UnityScanScene : MonoBehaviour, IUnityScanScene
{
	// Unity 3D Text object that contains 
	// the displayed TextMesh in the FOV
	public GameObject OutputText;
	// TextMesh object provided by the OutputText game object
	private TextMesh OutputTextMesh;
	// string to be affected to the TextMesh object
	private string OutputTextString = string.Empty;
	// Indicate if we have to Update the text displayed
	private bool OutputTextChanged = false;

	// Use this for initialization
	async void Start ()
	{
            OutputTextMesh = OutputText.GetComponent<TextMesh>();
            OutputTextMesh.text = string.Empty;

#if UNITY_WSA && !UNITY_EDITOR // **RUNNING ON WINDOWS**
            // We will create our Camera scan engine here
#else                          // **RUNNING IN UNITY**
            ModifyOutputText("Sorry ;-( The app is not supported in the Unity player.");
#endif
	}

	/// <summary>
	/// Modify the text to be displayed in the FOV
	/// or/and in the debug traces
	/// + Indicate that we have to update the text to display
	/// </summary>
	/// <param name="newText">new string value to display</param>
	public void ModifyOutputText(string newText)
	{
		OutputTextString = newText;
		OutputTextChanged = true;
	}

	// Update is called once per frame
	void Update ()
	{
		if (OutputTextChanged)
		{
			OutputTextMesh.text = OutputTextString;
			OutputTextChanged = false;
		}
	}

}

Display 📺 some text in the field of view


Add a 3D Text object as a child of the camera; Name it "OutputText"; Change its properties as shown below. The purpose is to see some text at a nice distance and in the center of the field of view.



To be able to update this 3D Text object, drag & drop the OutputText object from the hierarchy to the Output text property of the ScriptManager object. This action gives to the UnityScanScene class the reference to the 3D Text to modify.



To do a small verification, you can press the Unity PLAY button.

Camera scan engine ⚙ 🎥


Ok, it is now time to take care of the camera:

Add a new folder in the Assets named "UWP" in order to place within it only C# code that runs on Windows.

Add a script named "ScanEngine". Here is the Assets folder look:



Replace the content of the ScanEngine.cs file with the code below.

#if UNITY_WSA && !UNITY_EDITOR
using System;
using System.Linq;
using System.Threading.Tasks;
using Windows.Media.Capture;
using Windows.Media.Capture.Frames;
using Windows.Media.MediaProperties;

public class ScanEngine
{
    public TimeSpan PredictionFrequency = TimeSpan.FromMilliseconds(400);

    private MediaCapture CameraCapture;
    private MediaFrameReader CameraFrameReader;

    private Int64 FramesCaptured;

    IUnityScanScene UnityApp;


    public ScanEngine()
    { 
    }

    public async Task Inititalize(IUnityScanScene unityApp)
    {
        UnityApp = unityApp;

        await InitializeCameraCapture();
        await InitializeCameraFrameReader();
    }

    private async Task InitializeCameraCapture()
    {
        CameraCapture = new MediaCapture();
        MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
        settings.StreamingCaptureMode = StreamingCaptureMode.Video;
        await CameraCapture.InitializeAsync(settings);
    }

    private async Task InitializeCameraFrameReader()
    {
        var frameSourceGroups = await MediaFrameSourceGroup.FindAllAsync(); 
        MediaFrameSourceGroup selectedGroup = null;
        MediaFrameSourceInfo colorSourceInfo = null;

        foreach (var sourceGroup in frameSourceGroups)
        {
            foreach (var sourceInfo in sourceGroup.SourceInfos)
            {
                if (sourceInfo.MediaStreamType == MediaStreamType.VideoPreview
                    && sourceInfo.SourceKind == MediaFrameSourceKind.Color)
                {
                    colorSourceInfo = sourceInfo;
                    break;
                }
            }
            if (colorSourceInfo != null)
            {
                selectedGroup = sourceGroup;
                break;
            }
        }

        var colorFrameSource = CameraCapture.FrameSources[colorSourceInfo.Id];
        var preferredFormat = colorFrameSource.SupportedFormats.Where(format =>
        {
            return format.Subtype == MediaEncodingSubtypes.Argb32;

        }).FirstOrDefault();

        CameraFrameReader = await CameraCapture.CreateFrameReaderAsync(colorFrameSource);
        await CameraFrameReader.StartAsync();
    }

    public void StartPullCameraFrames()
    {
        Task.Run(async () =>
        {
            for (; ; ) // Forever = While the app runs
            {
                FramesCaptured++;
                await Task.Delay(PredictionFrequency);
                using (var frameReference = CameraFrameReader.TryAcquireLatestFrame())
                using (var videoFrame = frameReference?.VideoMediaFrame?.GetVideoFrame())
                {

                    if (videoFrame == null)
                    {
                        continue; //ignoring frame
                    }

                    if (videoFrame.Direct3DSurface == null)
                    {
                        videoFrame.Dispose();
                        continue; //ignoring frame
                    }

                    try
                    {
                        // HERE, We will evaluate the model
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.Message);
                    }
                    finally
                    {
                    }
                }

            }

        });
    }

}
#endif



The UnityScanScene.cs script will use this class this way:

	async void Start ()
	{
        OutputTextMesh = OutputText.GetComponent<TextMesh>();
        OutputTextMesh.text = string.Empty;

#if UNITY_WSA && !UNITY_EDITOR // RUNNING ON WINDOWS**
        CameraScanEngine = new ScanEngine();       // <-- 1
        await CameraScanEngine.Inititalize(this);  // <-- 2
        CameraScanEngine.StartPullCameraFrames();  // <-- 3
#else                          // RUNNING IN UNITY**
        ModifyOutputText("Sorry ;-( The app is not supported in the Unity player.");
#endif
	}



❗ It is now time to modify the UnityScanScene.cs accordingly in order to have the code above for the Start method.

I have to give you some explanations 😅.

 

    1. We create our Camera helper CameraScanEngine from the ScanEngine class.

 

    1. Calling CameraScanEngine.Inititalize(this) in the UnityScanScene.cs startup script gives the ability to call the public ModifyOutputText method of the IUnityScanScene interface from the CameraScanEngine object. Here is the proof:





Also, it really initializes the HoloLens camera for being able to capture the video frames. Under the hood, we use the MediaCapture class.

    1. The HoloLens camera is initialized and we can get the frames. The StartPullCameraFrames() call initiates an infinite loop for pulling for frames. We will replace the line // HERE, We will evaluate the model by the code for evaluating the model on the frame later.



For this camera helper code, I thank Etienne Margraff with his article ( Preview API - Experimenting with Windows Machine Learning and Mixed Reality - Feel free to read it for further details about this code).

Step 4. Integrate ⤵ the model in the app

 

Adding the file in the package 📥


Back to step 2, we saved the model as a ONNX 1.2 file on the disk. It is now time to add it to the Unity App:

Just name the model "ONNXModel.onnx" and drag & drop it to a new folder named StreamingAssets in the Assets folder.



This StreamingAssets folder is special for Unity: it will be copied to the Data folder inside the UWP application that will be deployed on the HoloLens. This way, we will be able to load the file by code from the package installation folder.

Note: It is also possible to add the ONNX file directly to the resulting C# UWP application. The Unity way of adding it is not mandatory.

 

Add a wrapper class 🔧 for the model


This was the tricky part of the job and the one that changed from the Preview APIs and the ones released. The long story is well detailed by Matteo Pagani in the two referenced articles ( Preview API - Add a bit of machine learning to your Windows application thanks to WinML and Upgrade your WinML application to the latest bits ).

For today, long story short: we do not use the generated class by Visual Studio for our model wrapper but the following one below. This class is 'generic' and works for your own custom vision trained model.

Here are the steps:

In Unity, add a new script named 'ONNXModel' in the Assets/UWP folder. This is our 'generic' model wrapper class.



Double click on ONNXModel.cs and replace the content of the script by the following code:

 

 

#if UNITY_WSA && !UNITY_EDITOR
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.AI.MachineLearning;
using Windows.Media;
using Windows.Storage;

public sealed class ONNXModelInput
{
    public VideoFrame Data { get; set; }
}

public sealed class ONNXModelOutput
{
    public TensorString ClassLabel = TensorString.Create(new long[] { 1, 1 });
    public IList<IDictionary<string, float>> Loss = new List<IDictionary<string, float>>();
}

/// <summary>
/// These classes ONNXModel, ONNXModelInput, ONNXModelOutput never change
/// We just load a different custom model
/// 
/// In order to evalutate a model:
/// 1. Call the static method ONNXModel.CreateOnnxModel(<<MyModelStorageFile>>)
/// 2. Call EvaluateAsync method on the created Model before
/// </summary>
public sealed class ONNXModel
{
    private LearningModel _learningModel = null;
    private LearningModelSession _session;

    public static async Task<ONNXModel> CreateOnnxModel(StorageFile file)
    {
        LearningModel learningModel = null;

        try
        {
            learningModel = await LearningModel.LoadFromStorageFileAsync(file);
        }
        catch (Exception e)
        {
            var exceptionStr = e.ToString();
            Debug.WriteLine(exceptionStr);
            throw e;
        }
        return new ONNXModel()
        {
            _learningModel = learningModel,
            _session = new LearningModelSession(learningModel)
        };
    }

    public async Task<ONNXModelOutput> EvaluateAsync(ONNXModelInput input)
    {
        var output = new ONNXModelOutput();
        var binding = new LearningModelBinding(_session);
        binding.Bind("data", input.Data);
        binding.Bind("classLabel", output.ClassLabel);
        binding.Bind("loss", output.Loss);
        LearningModelEvaluationResult evalResult = await _session.EvaluateAsync(binding, "0");

        return output;
    }
}
#endif

 

 

 

Note: All code dedicated to UWP is surrounded by #if UNITY_WSA && !UNITY_EDITOR . It allows us to be sure to run this code only on Windows.


The CreateOnnxModel() static method is in charge of loading the file. The EvaluateAsync() performs the model' evaluation.

Again, this code will not change if you create your own custom vision model (Classification / Multilabel / General Compact).

Let's add now a 'high level' model helper in order to put the glue between the captured frame and the model evaluation.

Load 📤 and evaluate ⚙ the model for each frame


In Unity, add a new script named 'ONNXModelHelper' in the Assets/UWP folder.



Use this code:

 

#if UNITY_WSA && !UNITY_EDITOR
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Windows.Media;
using Windows.Storage;

public class ONNXModelHelper
{
    private ONNXModel Model = null;
    private string ModelFilename = "ONNXModel.onnx";
    private Stopwatch TimeRecorder = new Stopwatch();
    private IUnityScanScene UnityApp;

    public ONNXModelHelper()
    {
        UnityApp = null;
    }

    public ONNXModelHelper(IUnityScanScene unityApp)
    {
        UnityApp = unityApp;
    }

    public async Task LoadModelAsync() // <-- 1
    {
        ModifyText($"Loading {ModelFilename}... Patience");

        try
        {
            TimeRecorder = Stopwatch.StartNew();

            var modelFile = await StorageFile.GetFileFromApplicationUriAsync(
                new Uri($"ms-appx:///Data/StreamingAssets/{ModelFilename}"));
            Model = await ONNXModel.CreateOnnxModel(modelFile);

            TimeRecorder.Stop();
            ModifyText($"Loaded {ModelFilename}: Elapsed time: {TimeRecorder.ElapsedMilliseconds} ms");
        }
        catch (Exception ex)
        {
            ModifyText($"error: {ex.Message}");
            Model = null;
        }
    }

    public async Task EvaluateVideoFrameAsync(VideoFrame frame) // <-- 2
    {
        if (frame != null)
        {
            try
            {
                TimeRecorder.Restart();
                ONNXModelInput inputData = new ONNXModelInput();
                inputData.Data = frame;
                var output = await Model.EvaluateAsync(inputData).ConfigureAwait(false); // <-- 3

                var product = output.ClassLabel.GetAsVectorView()[0]; // <-- 4 
                var loss = output.Loss[0][product]; // <-- 5
                TimeRecorder.Stop();

                var lossStr = string.Join(product, " " + (loss * 100.0f).ToString("#0.00") + "%");
                string message = $"({DateTime.Now.Hour}:{DateTime.Now.Minute}:{DateTime.Now.Second})" +
                    $" Evaluation took {TimeRecorder.ElapsedMilliseconds}ms\n";

                string prediction = $"Prediction: {product} {lossStr}";
                if (loss > 0.5f)
                {
                    message += prediction;
                }

                message = message.Replace("\\n", "\n");

                ModifyText(message); // <-- 6
            }
            catch (Exception ex)
            {
                var err_message = $"error: {ex.Message}";
                ModifyText(err_message);
            }
        }
    }

    private void ModifyText(string text)
    {
        System.Diagnostics.Debug.WriteLine(text);
        if (UnityApp != null)
        {
            UnityApp.ModifyOutputText(text);
        }
    }
}
#endif


Explanations 📚:

    1. The helper method effectively loads the ONNX Model using StorageFile.GetFileFromApplicationUriAsync() .

 

    1. EvaluateVideoFrameAsync() is called by the ScanEngine for every frame.



So, there is an action for you 😅: Please replace // HERE, We will evaluate the model by

await ModelHelper.EvaluateVideoFrameAsync(videoFrame).ConfigureAwait(false); .

    1. Model.EvaluateAsync() calls the wrapper method for the model's evaluation. We get the result in the output object.

 

    1. var product = output.ClassLabel.GetAsVectorView()[0] is the name of the most scored prediction.

 

    1. output.Loss[0][product] is the score of this prediction.

 

    1. We call the private method ModifyText to modify the text to display in HoloLens thanks to UnityApp.ModifyOutputText() . The display is about giving the predication and the score.



We should have all set 🤯😪🥳! You just have to build the Unity app; It generates the C# UWP Solution that you can compile in MASTER x86 and deploy to you HoloLens.

Here is what you can get 😂

Good prediction for Benoit !



A 'low' prediction for Florent (who is not me 😉 and who was not part of the Model's training)

Disclaimer ⚖: Again, this model was only trained with less than 20 pictures which is a way too low to pretend having a correct model for prediction. But you have the idea!


All updated and optimized source code is on GitHub - https://github.com/Microsoft/Windows-AppConsult-Samples-MixedReality/tree/master/HoloLensWinML .

Conclusion


Talking about performance: The app deployed on HoloLens loads the ~3Mb ONNX model in about 300ms. The model's evaluation is done in average in 250 to 400ms. So right now, we have a minimum of 2 frames analyzed by second; Based on the fact that only the HoloLens processor does the job, it is pretty good: We can imagine scenarios in factories for safety or monitoring, in maintenance or diagnostics operations or even in medical assistance.

The future? Who knows? Alex Kipman and his team for sure 😉

What I can say is that work is in progress a new Holographic Processing Unit (HPU) for HoloLens :

...the second version of the HPU, currently under development, will incorporate an AI coprocessor to natively and flexibly implement DNNs.


DNN stands for Deep Neural Networks which is what we are using 🎉. We can expect that this future AI chip would be dedicated for this kind of work and performance would be decoupled 💹!

Last word of this article is from the link above:


Mixed reality and artificial intelligence represent the future of computing, and we’re excited to be advancing this frontier.


Bye,

@sbovo for the 💻 🎮 Windows AppConsult team.

--

Credits


I would like to thank

 

 

    • Benoit my co-presenter on Mixed Reality events

 



References