├── .gitattributes ├── .github └── workflows │ └── build.yml ├── .gitignore ├── Directory.Build.props ├── Directory.Build.targets ├── EmotionRecognizer ├── EmotionRecognizer.cs ├── EmotionRecognizer.licenseheader ├── IntelligentAPI_EmotionRecognizer.csproj ├── Properties │ ├── AssemblyInfo.cs │ └── IntelligentAPI_EmotionRecognizer.rd.xml └── Scripts │ └── script.ps1 ├── ImageClassifier ├── Assets │ └── Labels.json ├── ImageClassifier.licenseheader ├── IntelligentAPI_ImageClassifier.csproj ├── Properties │ ├── AssemblyInfo.cs │ └── IntelligentAPI_ImageClassifier.rd.xml ├── Scripts │ └── script.ps1 ├── SqueezeNetImageClassifier.cs └── model.cs ├── IntelligentAPIs.sln ├── IntelligentAPIsTester ├── App.xaml ├── App.xaml.cs ├── Assets │ ├── LockScreenLogo.scale-200.png │ ├── SplashScreen.scale-200.png │ ├── Square150x150Logo.scale-200.png │ ├── Square44x44Logo.scale-200.png │ ├── Square44x44Logo.targetsize-24_altform-unplated.png │ ├── StoreLogo.png │ ├── Wide310x150Logo.scale-200.png │ └── background.jpg ├── IntelligentLabsTest.csproj ├── MainPage.xaml ├── MainPage.xaml.cs ├── Package.appxmanifest ├── Properties │ ├── AssemblyInfo.cs │ └── Default.rd.xml ├── ResultsPage.xaml ├── ResultsPage.xaml.cs └── Scripts │ └── script.ps1 ├── License.md ├── ObjectDetector ├── Assets │ └── Yolo.cs ├── IntelligentAPI_ObjectDetector.csproj ├── IntelligentAPI_ObjectDetector.pri ├── ObjectDetector.licenseheader ├── Properties │ ├── AssemblyInfo.cs │ └── IntelligentAPI_ObjectDetector.rd.xml ├── Scripts │ └── script.ps1 ├── YOLOObjectDetector.cs └── Yolo.cs ├── README.md ├── ThirdPartyNotices.txt ├── Windows.Toolkit.Common.props ├── global.json └── nuget.png /.gitattributes: -------------------------------------------------------------------------------- 1 | *.onnx filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | 2 | # This is a basic workflow to help you get started with Actions 3 | 4 | name: CI 5 | 6 | # Controls when the action will run. 7 | on: 8 | # Triggers the workflow on push or pull request events but only for the main branch 9 | push: 10 | branches: [ main ] 11 | pull_request: 12 | branches: [ main ] 13 | 14 | # Allows you to run this workflow manually from the Actions tab 15 | workflow_dispatch: 16 | 17 | 18 | # A workflow run is made up of one or more jobs that can run sequentially or in parallel 19 | jobs: 20 | # This workflow contains a single job called "build" 21 | build: 22 | # The type of runner that the job will run on 23 | runs-on: windows-latest 24 | 25 | # Steps represent a sequence of tasks that will be executed as part of the job 26 | steps: 27 | - name: Install .NET Core SDK 28 | uses: actions/setup-dotnet@v1 29 | with: 30 | dotnet-version: '5.0.302' 31 | 32 | # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it 33 | - uses: actions/checkout@v2 34 | # Runs a set of commands using the runners shell 35 | - name: Add msbuild to PATH 36 | uses: microsoft/setup-msbuild@v1.0.3 37 | 38 | - name: MSBuild 39 | # working-directory: ./ImageClassifier 40 | run: msbuild.exe IntelligentAPIs.sln /restore -p:Configuration=Packages 41 | 42 | - name: pack ImageClassifier 43 | working-directory: ./ImageClassifier 44 | run: msbuild -t:pack /p:Configuration=Release /p:DebugType=Portable 45 | 46 | - name: pack ObjectDetector 47 | working-directory: ./ObjectDetector 48 | run: msbuild -t:pack /p:Configuration=Release /p:DebugType=Portable 49 | 50 | - name: pack EmotionRecognizer 51 | working-directory: ./EmotionRecognizer 52 | run: msbuild -t:pack /p:Configuration=Release /p:DebugType=Portable 53 | 54 | - name: Add source 55 | run: dotnet nuget add source "https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-Labs/nuget/v3/index.json" --name LabsFeed --username dummy --password ${{ secrets.DEVOPS_PACKAGE_PUSH_TOKEN }} 56 | 57 | - name: Push packages 58 | if: ${{github.ref == 'refs/heads/main'}} 59 | run: dotnet nuget push "**/*.nupkg" --api-key dummy --source LabsFeed --skip-duplicate 60 | 61 | 62 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | 7 | 8 | 9 | # Ignore .onnx files 10 | **/*.onnx 11 | 12 | # User-specific files 13 | *.rsuser 14 | *.suo 15 | *.user 16 | *.userosscache 17 | *.sln.docstates 18 | 19 | # User-specific files (MonoDevelop/Xamarin Studio) 20 | *.userprefs 21 | 22 | # Mono auto generated files 23 | mono_crash.* 24 | 25 | # Build results 26 | [Dd]ebug/ 27 | [Dd]ebugPublic/ 28 | [Rr]elease/ 29 | [Rr]eleases/ 30 | x64/ 31 | x86/ 32 | [Aa][Rr][Mm]/ 33 | [Aa][Rr][Mm]64/ 34 | bld/ 35 | [Bb]in/ 36 | [Oo]bj/ 37 | [Ll]og/ 38 | [Ll]ogs/ 39 | 40 | # Visual Studio 2015/2017 cache/options directory 41 | .vs/ 42 | # Uncomment if you have tasks that create the project's static files in wwwroot 43 | #wwwroot/ 44 | 45 | # Visual Studio 2017 auto generated files 46 | Generated\ Files/ 47 | 48 | # MSTest test Results 49 | [Tt]est[Rr]esult*/ 50 | [Bb]uild[Ll]og.* 51 | 52 | # NUnit 53 | *.VisualState.xml 54 | TestResult.xml 55 | nunit-*.xml 56 | 57 | # Build Results of an ATL Project 58 | [Dd]ebugPS/ 59 | [Rr]eleasePS/ 60 | dlldata.c 61 | 62 | # Benchmark Results 63 | BenchmarkDotNet.Artifacts/ 64 | 65 | # .NET Core 66 | project.lock.json 67 | project.fragment.lock.json 68 | artifacts/ 69 | 70 | # StyleCop 71 | StyleCopReport.xml 72 | 73 | # Files built by Visual Studio 74 | *_i.c 75 | *_p.c 76 | *_h.h 77 | *.ilk 78 | *.meta 79 | *.obj 80 | *.iobj 81 | *.pch 82 | *.pdb 83 | *.ipdb 84 | *.pgc 85 | *.pgd 86 | *.rsp 87 | *.sbr 88 | *.tlb 89 | *.tli 90 | *.tlh 91 | *.tmp 92 | *.tmp_proj 93 | *_wpftmp.csproj 94 | *.log 95 | *.vspscc 96 | *.vssscc 97 | .builds 98 | *.pidb 99 | *.svclog 100 | *.scc 101 | 102 | # Chutzpah Test files 103 | _Chutzpah* 104 | 105 | # Visual C++ cache files 106 | ipch/ 107 | *.aps 108 | *.ncb 109 | *.opendb 110 | *.opensdf 111 | *.sdf 112 | *.cachefile 113 | *.VC.db 114 | *.VC.VC.opendb 115 | 116 | # Visual Studio profiler 117 | *.psess 118 | *.vsp 119 | *.vspx 120 | *.sap 121 | 122 | # Visual Studio Trace Files 123 | *.e2e 124 | 125 | # TFS 2012 Local Workspace 126 | $tf/ 127 | 128 | # Guidance Automation Toolkit 129 | *.gpState 130 | 131 | # ReSharper is a .NET coding add-in 132 | _ReSharper*/ 133 | *.[Rr]e[Ss]harper 134 | *.DotSettings.user 135 | 136 | # TeamCity is a build add-in 137 | _TeamCity* 138 | 139 | # DotCover is a Code Coverage Tool 140 | *.dotCover 141 | 142 | # AxoCover is a Code Coverage Tool 143 | .axoCover/* 144 | !.axoCover/settings.json 145 | 146 | # Visual Studio code coverage results 147 | *.coverage 148 | *.coveragexml 149 | 150 | # NCrunch 151 | _NCrunch_* 152 | .*crunch*.local.xml 153 | nCrunchTemp_* 154 | 155 | # MightyMoose 156 | *.mm.* 157 | AutoTest.Net/ 158 | 159 | # Web workbench (sass) 160 | .sass-cache/ 161 | 162 | # Installshield output folder 163 | [Ee]xpress/ 164 | 165 | # DocProject is a documentation generator add-in 166 | DocProject/buildhelp/ 167 | DocProject/Help/*.HxT 168 | DocProject/Help/*.HxC 169 | DocProject/Help/*.hhc 170 | DocProject/Help/*.hhk 171 | DocProject/Help/*.hhp 172 | DocProject/Help/Html2 173 | DocProject/Help/html 174 | 175 | # Click-Once directory 176 | publish/ 177 | 178 | # Publish Web Output 179 | *.[Pp]ublish.xml 180 | *.azurePubxml 181 | # Note: Comment the next line if you want to checkin your web deploy settings, 182 | # but database connection strings (with potential passwords) will be unencrypted 183 | *.pubxml 184 | *.publishproj 185 | 186 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 187 | # checkin your Azure Web App publish settings, but sensitive information contained 188 | # in these scripts will be unencrypted 189 | PublishScripts/ 190 | 191 | # NuGet Packages 192 | **/nuget.exe 193 | *.nupkg 194 | # NuGet Symbol Packages 195 | *.snupkg 196 | # The packages folder can be ignored because of Package Restore 197 | **/[Pp]ackages/* 198 | # except build/, which is used as an MSBuild target. 199 | !**/[Pp]ackages/build/ 200 | # Uncomment if necessary however generally it will be regenerated when needed 201 | #!**/[Pp]ackages/repositories.config 202 | # NuGet v3's project.json files produces more ignorable files 203 | *.nuget.props 204 | *.nuget.targets 205 | 206 | # Microsoft Azure Build Output 207 | csx/ 208 | *.build.csdef 209 | 210 | # Microsoft Azure Emulator 211 | ecf/ 212 | rcf/ 213 | 214 | # Windows Store app package directories and files 215 | AppPackages/ 216 | BundleArtifacts/ 217 | Package.StoreAssociation.xml 218 | _pkginfo.txt 219 | *.appx 220 | *.appxbundle 221 | *.appxupload 222 | 223 | # Visual Studio cache files 224 | # files ending in .cache can be ignored 225 | *.[Cc]ache 226 | # but keep track of directories ending in .cache 227 | !?*.[Cc]ache/ 228 | 229 | # Others 230 | ClientBin/ 231 | ~$* 232 | *~ 233 | *.dbmdl 234 | *.dbproj.schemaview 235 | *.jfm 236 | *.pfx 237 | *.publishsettings 238 | orleans.codegen.cs 239 | 240 | # Including strong name files can present a security risk 241 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 242 | #*.snk 243 | 244 | # Since there are multiple workflows, uncomment next line to ignore bower_components 245 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 246 | #bower_components/ 247 | 248 | # RIA/Silverlight projects 249 | Generated_Code/ 250 | 251 | # Backup & report files from converting an old project file 252 | # to a newer Visual Studio version. Backup files are not needed, 253 | # because we have git ;-) 254 | _UpgradeReport_Files/ 255 | Backup*/ 256 | UpgradeLog*.XML 257 | UpgradeLog*.htm 258 | ServiceFabricBackup/ 259 | *.rptproj.bak 260 | 261 | # SQL Server files 262 | *.mdf 263 | *.ldf 264 | *.ndf 265 | 266 | # Business Intelligence projects 267 | *.rdl.data 268 | *.bim.layout 269 | *.bim_*.settings 270 | *.rptproj.rsuser 271 | *- [Bb]ackup.rdl 272 | *- [Bb]ackup ([0-9]).rdl 273 | *- [Bb]ackup ([0-9][0-9]).rdl 274 | 275 | # Microsoft Fakes 276 | FakesAssemblies/ 277 | 278 | # GhostDoc plugin setting file 279 | *.GhostDoc.xml 280 | 281 | # Node.js Tools for Visual Studio 282 | .ntvs_analysis.dat 283 | node_modules/ 284 | 285 | # Visual Studio 6 build log 286 | *.plg 287 | 288 | # Visual Studio 6 workspace options file 289 | *.opt 290 | 291 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 292 | *.vbw 293 | 294 | # Visual Studio LightSwitch build output 295 | **/*.HTMLClient/GeneratedArtifacts 296 | **/*.DesktopClient/GeneratedArtifacts 297 | **/*.DesktopClient/ModelManifest.xml 298 | **/*.Server/GeneratedArtifacts 299 | **/*.Server/ModelManifest.xml 300 | _Pvt_Extensions 301 | 302 | # Paket dependency manager 303 | .paket/paket.exe 304 | paket-files/ 305 | 306 | # FAKE - F# Make 307 | .fake/ 308 | 309 | # CodeRush personal settings 310 | .cr/personal 311 | 312 | # Python Tools for Visual Studio (PTVS) 313 | __pycache__/ 314 | *.pyc 315 | 316 | # Cake - Uncomment if you are using it 317 | # tools/** 318 | # !tools/packages.config 319 | 320 | # Tabs Studio 321 | *.tss 322 | 323 | # Telerik's JustMock configuration file 324 | *.jmconfig 325 | 326 | # BizTalk build output 327 | *.btp.cs 328 | *.btm.cs 329 | *.odx.cs 330 | *.xsd.cs 331 | 332 | # OpenCover UI analysis results 333 | OpenCover/ 334 | 335 | # Azure Stream Analytics local run output 336 | ASALocalRun/ 337 | 338 | # MSBuild Binary and Structured Log 339 | *.binlog 340 | 341 | # NVidia Nsight GPU debugger configuration file 342 | *.nvuser 343 | 344 | # MFractors (Xamarin productivity tool) working folder 345 | .mfractor/ 346 | 347 | # Local History for Visual Studio 348 | .localhistory/ 349 | 350 | # BeatPulse healthcheck temp database 351 | healthchecksdb 352 | 353 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 354 | MigrationBackup/ 355 | 356 | # Ionide (cross platform F# VS Code tools) working folder 357 | .ionide/ 358 | /ObjectDetector/makepri.exe 359 | /ObjectDetector/resources.pri.xml 360 | -------------------------------------------------------------------------------- /Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $(MSBuildThisFileDirectory) 5 | 6 | 7 | 8 | 9 | 10 | 10.0.19041.0 11 | 10.0.17763.0 12 | false 13 | uap10.0.17763 14 | 15 | 16 | 17 | Embedded 18 | bin\Package 19 | .pdb 20 | true 21 | true 22 | 23 | 24 | -------------------------------------------------------------------------------- /Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | $(CommonTags);UWP;WinML;ML 10 | $(CommonTags);$(PackageTags) 11 | $(CommonTags) 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /EmotionRecognizer/EmotionRecognizer.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using Windows.AI.MachineLearning; 10 | using Windows.Foundation; 11 | using Windows.Graphics.Imaging; 12 | using Windows.Media; 13 | using Windows.Media.FaceAnalysis; 14 | using Windows.Storage; 15 | using Windows.Storage.Streams; 16 | 17 | namespace CommunityToolkit.Labs.Intelligent.EmotionRecognition 18 | { 19 | /// 20 | /// Detection result class that contains the index and emotion of a face in the input image. 21 | /// 22 | public class DetectedEmotion 23 | { 24 | /// 25 | /// Index of the result in the array ["Neutral","Happiness","Surprise","Sadness","Anger","Disgust","Fear","Contempt"] 26 | /// 27 | public int emotionIndex; 28 | 29 | /// 30 | /// Emotion result 31 | /// 32 | public string emotion; 33 | } 34 | 35 | /// 36 | /// EmotionRecognizer class 37 | /// 38 | public class EmotionRecognizer 39 | { 40 | /// 41 | /// Model file 42 | /// 43 | private LearningModel _model = null; 44 | 45 | /// 46 | /// Session instance 47 | /// 48 | private LearningModelSession _session = null; 49 | 50 | /// 51 | /// Binding 52 | /// 53 | private LearningModelBinding _binding = null; 54 | 55 | /// 56 | /// EmotionRecognizer instance 57 | /// 58 | private static EmotionRecognizer instance = null; 59 | 60 | /// 61 | /// List of labels 62 | /// 63 | private static List labels; 64 | 65 | 66 | private async Task InitModelAsync() 67 | { 68 | // load model file 69 | var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///IntelligentAPI_EmotionRecognizer/Assets/model_emotion.onnx")); 70 | 71 | //Loads the mdoel from the file 72 | _model = await LearningModel.LoadFromStorageFileAsync(file); 73 | 74 | //Creating a session that binds the model to the device running the model 75 | _session = new LearningModelSession(_model, new LearningModelDevice(GetDeviceKind())); 76 | } 77 | 78 | /// 79 | /// Load labels 80 | /// 81 | private void LoadLabels() 82 | { 83 | labels = new List() 84 | { 85 | "Neutral", 86 | "Happiness", 87 | "Surprise", 88 | "Sadness", 89 | "Anger", 90 | "Disgust", 91 | "Fear", 92 | "Contempt" 93 | }; 94 | } 95 | 96 | LearningModelDeviceKind GetDeviceKind() 97 | { 98 | return LearningModelDeviceKind.Cpu; 99 | } 100 | 101 | /// 102 | /// Detect Faces in image 103 | /// 104 | /// 105 | /// 106 | private async static Task> DetectFacesInImageAsync(SoftwareBitmap bitmap) 107 | { 108 | FaceDetector faceDetector = await FaceDetector.CreateAsync(); 109 | var convertedBitmap = SoftwareBitmap.Convert(bitmap, BitmapPixelFormat.Gray8); 110 | return await faceDetector.DetectFacesAsync(convertedBitmap); 111 | 112 | } 113 | 114 | /// 115 | /// Detect emotion on a face in an input image 116 | /// 117 | /// 118 | /// 119 | /// Returns detected emotion in DetectedEmotion object, null if no face was detected. 120 | /// 121 | public async static Task DetectEmotion(SoftwareBitmap bitmap) 122 | { 123 | if (instance == null) 124 | { 125 | instance = new EmotionRecognizer(); 126 | } 127 | 128 | return await instance.EvaluateFrame(bitmap); 129 | } 130 | 131 | /// 132 | /// Detect emotion on a face in an input image 133 | /// 134 | /// 135 | /// 136 | /// Returns detected emotion in DetectedEmotion object, null if no face was detected. 137 | /// 138 | public async static Task DetectEmotion(StorageFile storageFile) 139 | { 140 | SoftwareBitmap bitmap = await GenerateSoftwareBitmapFromStorageFile(storageFile); 141 | return await DetectEmotion(bitmap); 142 | } 143 | 144 | /// 145 | /// Evaluate frame 146 | /// 147 | /// 148 | /// 149 | private async Task EvaluateFrame(SoftwareBitmap softwareBitmap) 150 | { 151 | await InitModelAsync(); 152 | LoadLabels(); 153 | DetectedFace detectedFace = await DetectFace(softwareBitmap); 154 | if (detectedFace != null) 155 | { 156 | return await EvaluateEmotionInFace(detectedFace, softwareBitmap); 157 | } 158 | return null; 159 | } 160 | 161 | /// 162 | /// Evaluate emotion in face 163 | /// 164 | /// 165 | /// 166 | /// 167 | private async Task EvaluateEmotionInFace(DetectedFace detectedFace, SoftwareBitmap softwareBitmap) 168 | { 169 | 170 | var boundingBox = new Rect(detectedFace.FaceBox.X, 171 | detectedFace.FaceBox.Y, 172 | detectedFace.FaceBox.Width, 173 | detectedFace.FaceBox.Height); 174 | 175 | softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8); 176 | 177 | var croppedFace = await Crop(softwareBitmap, boundingBox); 178 | LearningModelEvaluationResult emotionResults = await BindAndEvaluateModelAsync(croppedFace); 179 | 180 | // to get percentages, you'd need to run the output through a softmax function 181 | // we don't need percentages, we just need max value 182 | TensorFloat emotionIndexTensor = emotionResults.Outputs["Plus692_Output_0"] as TensorFloat; 183 | 184 | var emotionList = emotionIndexTensor.GetAsVectorView().ToList(); 185 | var emotionIndex = emotionList.IndexOf(emotionList.Max()); 186 | 187 | return new DetectedEmotion() { emotionIndex = emotionIndex, emotion = labels[emotionIndex] }; 188 | 189 | 190 | } 191 | 192 | /// 193 | /// Detect face 194 | /// 195 | /// 196 | /// 197 | private static async Task DetectFace(SoftwareBitmap softwareBitmap) 198 | { 199 | var faces = await DetectFacesInImageAsync(softwareBitmap); 200 | 201 | // if there is a face in the frame, evaluate the emotion 202 | var detectedFace = faces.FirstOrDefault(); 203 | return detectedFace; 204 | } 205 | 206 | /// 207 | /// Converts object of type StorageFile to SoftwareBitmap 208 | /// 209 | /// 210 | /// 211 | private static async Task GenerateSoftwareBitmapFromStorageFile(StorageFile selectedStorageFile) 212 | { 213 | SoftwareBitmap softwareBitmap; 214 | using (IRandomAccessStream stream = await selectedStorageFile.OpenAsync(FileAccessMode.Read)) 215 | { 216 | // Create the decoder from the stream 217 | BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); 218 | 219 | // Get the SoftwareBitmap representation of the file in BGRA8 format 220 | softwareBitmap = await decoder.GetSoftwareBitmapAsync(); 221 | softwareBitmap = GetSoftwareBitmap(softwareBitmap); 222 | } 223 | 224 | return softwareBitmap; 225 | } 226 | 227 | /// 228 | /// Get Software Bitmap 229 | /// 230 | /// 231 | /// 232 | private static SoftwareBitmap GetSoftwareBitmap(SoftwareBitmap softwareBitmap) 233 | { 234 | if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || (softwareBitmap.BitmapAlphaMode != BitmapAlphaMode.Ignore && softwareBitmap.BitmapAlphaMode != BitmapAlphaMode.Premultiplied)) 235 | { 236 | softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); 237 | } 238 | return softwareBitmap; 239 | } 240 | 241 | private static async Task Crop(SoftwareBitmap softwareBitmap, Rect bounds) 242 | { 243 | VideoFrame vid = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap); 244 | vid = await Crop(vid, bounds); 245 | return vid.SoftwareBitmap; 246 | 247 | } 248 | private static async Task Crop(VideoFrame videoFrame, Rect bounds) 249 | { 250 | BitmapBounds cropBounds = new BitmapBounds() 251 | { 252 | Width = (uint)bounds.Width, 253 | Height = (uint)bounds.Height, 254 | X = (uint)bounds.X, 255 | Y = (uint)bounds.Y 256 | }; 257 | VideoFrame result = new VideoFrame(BitmapPixelFormat.Bgra8, 258 | (int)cropBounds.Width, 259 | (int)cropBounds.Height, 260 | BitmapAlphaMode.Premultiplied); 261 | 262 | await videoFrame.CopyToAsync(result, cropBounds, null); 263 | 264 | return result; 265 | } 266 | 267 | 268 | private async Task BindAndEvaluateModelAsync(SoftwareBitmap croppedFace) 269 | { 270 | //Create Learning model binding which binds 271 | _binding = new LearningModelBinding(_session); 272 | _binding.Bind("Input3", VideoFrame.CreateWithSoftwareBitmap(croppedFace)); 273 | var emotionResults = await _session.EvaluateAsync(_binding, "id"); 274 | return emotionResults; 275 | } 276 | 277 | } 278 | } 279 | -------------------------------------------------------------------------------- /EmotionRecognizer/EmotionRecognizer.licenseheader: -------------------------------------------------------------------------------- 1 | extensions: designer.cs generated.cs 2 | extensions: .cs 3 | // Licensed to the .NET Foundation under one or more agreements. 4 | // The .NET Foundation licenses this file to you under the MIT license. 5 | // See the LICENSE file in the project root for more information. -------------------------------------------------------------------------------- /EmotionRecognizer/IntelligentAPI_EmotionRecognizer.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | IntelligentAPI.EmotionRecognition 4 | 5 | 6 | CommunityToolkit.Labs.Intelligent.EmotionRecognition 7 | 8 | This package performs Emotion Recognition on an input image by using the Emotion FERPlus model. 9 | 10 | 0.0.2 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /EmotionRecognizer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | using System.Reflection; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | 8 | // General Information about an assembly is controlled through the following 9 | // set of attributes. Change these attribute values to modify the information 10 | // associated with an assembly. 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | // Version information for an assembly consists of the following four values: 15 | // 16 | // Major Version 17 | // Minor Version 18 | // Build Number 19 | // Revision 20 | // 21 | // You can specify all the values or you can default the Build and Revision Numbers 22 | // by using the '*' as shown below: 23 | // [assembly: AssemblyVersion("1.0.*")] 24 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /EmotionRecognizer/Properties/IntelligentAPI_EmotionRecognizer.rd.xml: -------------------------------------------------------------------------------- 1 | 2 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /EmotionRecognizer/Scripts/script.ps1: -------------------------------------------------------------------------------- 1 | $ProgressPreference = 'SilentlyContinue' 2 | 3 | $emotionferplusfile = "./Assets/model_emotion.onnx" 4 | $folderPath = "./Assets" 5 | 6 | if (-not(Test-Path -Path $emotionferplusfile -PathType Leaf)) { 7 | If(!(test-path $folderPath)) { 8 | New-Item -ItemType Directory -Force -Path $folderPath 9 | } 10 | try { 11 | Invoke-WebRequest -URI "https://github.com/onnx/models/raw/main/vision/body_analysis/emotion_ferplus/model/emotion-ferplus-8.onnx" -OutFile $emotionferplusfile 12 | Write-Host "The file [$emotionferplusfile] has been created." 13 | } 14 | catch { 15 | throw $_.Exception.Message 16 | } 17 | } 18 | else { 19 | Write-Host "The file [$emotionferplusfile] exists." 20 | } 21 | -------------------------------------------------------------------------------- /ImageClassifier/Assets/Labels.json: -------------------------------------------------------------------------------- 1 | { 2 | "0": "tench, Tinca tinca", 3 | "1": "goldfish, Carassius auratus", 4 | "2": "great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias", 5 | "3": "tiger shark, Galeocerdo cuvieri", 6 | "4": "hammerhead, hammerhead shark", 7 | "5": "electric ray, crampfish, numbfish, torpedo", 8 | "6": "stingray", 9 | "7": "cock", 10 | "8": "hen", 11 | "9": "ostrich, Struthio camelus", 12 | "10": "brambling, Fringilla montifringilla", 13 | "11": "goldfinch, Carduelis carduelis", 14 | "12": "house finch, linnet, Carpodacus mexicanus", 15 | "13": "junco, snowbird", 16 | "14": "indigo bunting, indigo finch, indigo bird, Passerina cyanea", 17 | "15": "robin, American robin, Turdus migratorius", 18 | "16": "bulbul", 19 | "17": "jay", 20 | "18": "magpie", 21 | "19": "chickadee", 22 | "20": "water ouzel, dipper", 23 | "21": "kite", 24 | "22": "bald eagle, American eagle, Haliaeetus leucocephalus", 25 | "23": "vulture", 26 | "24": "great grey owl, great gray owl, Strix nebulosa", 27 | "25": "European fire salamander, Salamandra salamandra", 28 | "26": "common newt, Triturus vulgaris", 29 | "27": "eft", 30 | "28": "spotted salamander, Ambystoma maculatum", 31 | "29": "axolotl, mud puppy, Ambystoma mexicanum", 32 | "30": "bullfrog, Rana catesbeiana", 33 | "31": "tree frog, tree-frog", 34 | "32": "tailed frog, bell toad, ribbed toad, tailed toad, Ascaphus trui", 35 | "33": "loggerhead, loggerhead turtle, Caretta caretta", 36 | "34": "leatherback turtle, leatherback, leathery turtle, Dermochelys coriacea", 37 | "35": "mud turtle", 38 | "36": "terrapin", 39 | "37": "box turtle, box tortoise", 40 | "38": "banded gecko", 41 | "39": "common iguana, iguana, Iguana iguana", 42 | "40": "American chameleon, anole, Anolis carolinensis", 43 | "41": "whiptail, whiptail lizard", 44 | "42": "agama", 45 | "43": "frilled lizard, Chlamydosaurus kingi", 46 | "44": "alligator lizard", 47 | "45": "Gila monster, Heloderma suspectum", 48 | "46": "green lizard, Lacerta viridis", 49 | "47": "African chameleon, Chamaeleo chamaeleon", 50 | "48": "Komodo dragon, Komodo lizard, dragon lizard, giant lizard, Varanus komodoensis", 51 | "49": "African crocodile, Nile crocodile, Crocodylus niloticus", 52 | "50": "American alligator, Alligator mississipiensis", 53 | "51": "triceratops", 54 | "52": "thunder snake, worm snake, Carphophis amoenus", 55 | "53": "ringneck snake, ring-necked snake, ring snake", 56 | "54": "hognose snake, puff adder, sand viper", 57 | "55": "green snake, grass snake", 58 | "56": "king snake, kingsnake", 59 | "57": "garter snake, grass snake", 60 | "58": "water snake", 61 | "59": "vine snake", 62 | "60": "night snake, Hypsiglena torquata", 63 | "61": "boa constrictor, Constrictor constrictor", 64 | "62": "rock python, rock snake, Python sebae", 65 | "63": "Indian cobra, Naja naja", 66 | "64": "green mamba", 67 | "65": "sea snake", 68 | "66": "horned viper, cerastes, sand viper, horned asp, Cerastes cornutus", 69 | "67": "diamondback, diamondback rattlesnake, Crotalus adamanteus", 70 | "68": "sidewinder, horned rattlesnake, Crotalus cerastes", 71 | "69": "trilobite", 72 | "70": "harvestman, daddy longlegs, Phalangium opilio", 73 | "71": "scorpion", 74 | "72": "black and gold garden spider, Argiope aurantia", 75 | "73": "barn spider, Araneus cavaticus", 76 | "74": "garden spider, Aranea diademata", 77 | "75": "black widow, Latrodectus mactans", 78 | "76": "tarantula", 79 | "77": "wolf spider, hunting spider", 80 | "78": "tick", 81 | "79": "centipede", 82 | "80": "black grouse", 83 | "81": "ptarmigan", 84 | "82": "ruffed grouse, partridge, Bonasa umbellus", 85 | "83": "prairie chicken, prairie grouse, prairie fowl", 86 | "84": "peacock", 87 | "85": "quail", 88 | "86": "partridge", 89 | "87": "African grey, African gray, Psittacus erithacus", 90 | "88": "macaw", 91 | "89": "sulphur-crested cockatoo, Kakatoe galerita, Cacatua galerita", 92 | "90": "lorikeet", 93 | "91": "coucal", 94 | "92": "bee eater", 95 | "93": "hornbill", 96 | "94": "hummingbird", 97 | "95": "jacamar", 98 | "96": "toucan", 99 | "97": "drake", 100 | "98": "red-breasted merganser, Mergus serrator", 101 | "99": "goose", 102 | "100": "black swan, Cygnus atratus", 103 | "101": "tusker", 104 | "102": "echidna, spiny anteater, anteater", 105 | "103": "platypus, duckbill, duckbilled platypus, duck-billed platypus, Ornithorhynchus anatinus", 106 | "104": "wallaby, brush kangaroo", 107 | "105": "koala, koala bear, kangaroo bear, native bear, Phascolarctos cinereus", 108 | "106": "wombat", 109 | "107": "jellyfish", 110 | "108": "sea anemone, anemone", 111 | "109": "brain coral", 112 | "110": "flatworm, platyhelminth", 113 | "111": "nematode, nematode worm, roundworm", 114 | "112": "conch", 115 | "113": "snail", 116 | "114": "slug", 117 | "115": "sea slug, nudibranch", 118 | "116": "chiton, coat-of-mail shell, sea cradle, polyplacophore", 119 | "117": "chambered nautilus, pearly nautilus, nautilus", 120 | "118": "Dungeness crab, Cancer magister", 121 | "119": "rock crab, Cancer irroratus", 122 | "120": "fiddler crab", 123 | "121": "king crab, Alaska crab, Alaskan king crab, Alaska king crab, Paralithodes camtschatica", 124 | "122": "American lobster, Northern lobster, Maine lobster, Homarus americanus", 125 | "123": "spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish", 126 | "124": "crayfish, crawfish, crawdad, crawdaddy", 127 | "125": "hermit crab", 128 | "126": "isopod", 129 | "127": "white stork, Ciconia ciconia", 130 | "128": "black stork, Ciconia nigra", 131 | "129": "spoonbill", 132 | "130": "flamingo", 133 | "131": "little blue heron, Egretta caerulea", 134 | "132": "American egret, great white heron, Egretta albus", 135 | "133": "bittern", 136 | "134": "crane", 137 | "135": "limpkin, Aramus pictus", 138 | "136": "European gallinule, Porphyrio porphyrio", 139 | "137": "American coot, marsh hen, mud hen, water hen, Fulica americana", 140 | "138": "bustard", 141 | "139": "ruddy turnstone, Arenaria interpres", 142 | "140": "red-backed sandpiper, dunlin, Erolia alpina", 143 | "141": "redshank, Tringa totanus", 144 | "142": "dowitcher", 145 | "143": "oystercatcher, oyster catcher", 146 | "144": "pelican", 147 | "145": "king penguin, Aptenodytes patagonica", 148 | "146": "albatross, mollymawk", 149 | "147": "grey whale, gray whale, devilfish, Eschrichtius gibbosus, Eschrichtius robustus", 150 | "148": "killer whale, killer, orca, grampus, sea wolf, Orcinus orca", 151 | "149": "dugong, Dugong dugon", 152 | "150": "sea lion", 153 | "151": "Chihuahua", 154 | "152": "Japanese spaniel", 155 | "153": "Maltese dog, Maltese terrier, Maltese", 156 | "154": "Pekinese, Pekingese, Peke", 157 | "155": "Shih-Tzu", 158 | "156": "Blenheim spaniel", 159 | "157": "papillon", 160 | "158": "toy terrier", 161 | "159": "Rhodesian ridgeback", 162 | "160": "Afghan hound, Afghan", 163 | "161": "basset, basset hound", 164 | "162": "beagle", 165 | "163": "bloodhound, sleuthhound", 166 | "164": "bluetick", 167 | "165": "black-and-tan coonhound", 168 | "166": "Walker hound, Walker foxhound", 169 | "167": "English foxhound", 170 | "168": "redbone", 171 | "169": "borzoi, Russian wolfhound", 172 | "170": "Irish wolfhound", 173 | "171": "Italian greyhound", 174 | "172": "whippet", 175 | "173": "Ibizan hound, Ibizan Podenco", 176 | "174": "Norwegian elkhound, elkhound", 177 | "175": "otterhound, otter hound", 178 | "176": "Saluki, gazelle hound", 179 | "177": "Scottish deerhound, deerhound", 180 | "178": "Weimaraner", 181 | "179": "Staffordshire bullterrier, Staffordshire bull terrier", 182 | "180": "American Staffordshire terrier, Staffordshire terrier, American pit bull terrier, pit bull terrier", 183 | "181": "Bedlington terrier", 184 | "182": "Border terrier", 185 | "183": "Kerry blue terrier", 186 | "184": "Irish terrier", 187 | "185": "Norfolk terrier", 188 | "186": "Norwich terrier", 189 | "187": "Yorkshire terrier", 190 | "188": "wire-haired fox terrier", 191 | "189": "Lakeland terrier", 192 | "190": "Sealyham terrier, Sealyham", 193 | "191": "Airedale, Airedale terrier", 194 | "192": "cairn, cairn terrier", 195 | "193": "Australian terrier", 196 | "194": "Dandie Dinmont, Dandie Dinmont terrier", 197 | "195": "Boston bull, Boston terrier", 198 | "196": "miniature schnauzer", 199 | "197": "giant schnauzer", 200 | "198": "standard schnauzer", 201 | "199": "Scotch terrier, Scottish terrier, Scottie", 202 | "200": "Tibetan terrier, chrysanthemum dog", 203 | "201": "silky terrier, Sydney silky", 204 | "202": "soft-coated wheaten terrier", 205 | "203": "West Highland white terrier", 206 | "204": "Lhasa, Lhasa apso", 207 | "205": "flat-coated retriever", 208 | "206": "curly-coated retriever", 209 | "207": "golden retriever", 210 | "208": "Labrador retriever", 211 | "209": "Chesapeake Bay retriever", 212 | "210": "German short-haired pointer", 213 | "211": "vizsla, Hungarian pointer", 214 | "212": "English setter", 215 | "213": "Irish setter, red setter", 216 | "214": "Gordon setter", 217 | "215": "Brittany spaniel", 218 | "216": "clumber, clumber spaniel", 219 | "217": "English springer, English springer spaniel", 220 | "218": "Welsh springer spaniel", 221 | "219": "cocker spaniel, English cocker spaniel, cocker", 222 | "220": "Sussex spaniel", 223 | "221": "Irish water spaniel", 224 | "222": "kuvasz", 225 | "223": "schipperke", 226 | "224": "groenendael", 227 | "225": "malinois", 228 | "226": "briard", 229 | "227": "kelpie", 230 | "228": "komondor", 231 | "229": "Old English sheepdog, bobtail", 232 | "230": "Shetland sheepdog, Shetland sheep dog, Shetland", 233 | "231": "collie", 234 | "232": "Border collie", 235 | "233": "Bouvier des Flandres, Bouviers des Flandres", 236 | "234": "Rottweiler", 237 | "235": "German shepherd, German shepherd dog, German police dog, alsatian", 238 | "236": "Doberman, Doberman pinscher", 239 | "237": "miniature pinscher", 240 | "238": "Greater Swiss Mountain dog", 241 | "239": "Bernese mountain dog", 242 | "240": "Appenzeller", 243 | "241": "EntleBucher", 244 | "242": "boxer", 245 | "243": "bull mastiff", 246 | "244": "Tibetan mastiff", 247 | "245": "French bulldog", 248 | "246": "Great Dane", 249 | "247": "Saint Bernard, St Bernard", 250 | "248": "Eskimo dog, husky", 251 | "249": "malamute, malemute, Alaskan malamute", 252 | "250": "Siberian husky", 253 | "251": "dalmatian, coach dog, carriage dog", 254 | "252": "affenpinscher, monkey pinscher, monkey dog", 255 | "253": "basenji", 256 | "254": "pug, pug-dog", 257 | "255": "Leonberg", 258 | "256": "Newfoundland, Newfoundland dog", 259 | "257": "Great Pyrenees", 260 | "258": "Samoyed, Samoyede", 261 | "259": "Pomeranian", 262 | "260": "chow, chow chow", 263 | "261": "keeshond", 264 | "262": "Brabancon griffon", 265 | "263": "Pembroke, Pembroke Welsh corgi", 266 | "264": "Cardigan, Cardigan Welsh corgi", 267 | "265": "toy poodle", 268 | "266": "miniature poodle", 269 | "267": "standard poodle", 270 | "268": "Mexican hairless", 271 | "269": "timber wolf, grey wolf, gray wolf, Canis lupus", 272 | "270": "white wolf, Arctic wolf, Canis lupus tundrarum", 273 | "271": "red wolf, maned wolf, Canis rufus, Canis niger", 274 | "272": "coyote, prairie wolf, brush wolf, Canis latrans", 275 | "273": "dingo, warrigal, warragal, Canis dingo", 276 | "274": "dhole, Cuon alpinus", 277 | "275": "African hunting dog, hyena dog, Cape hunting dog, Lycaon pictus", 278 | "276": "hyena, hyaena", 279 | "277": "red fox, Vulpes vulpes", 280 | "278": "kit fox, Vulpes macrotis", 281 | "279": "Arctic fox, white fox, Alopex lagopus", 282 | "280": "grey fox, gray fox, Urocyon cinereoargenteus", 283 | "281": "tabby, tabby cat", 284 | "282": "tiger cat", 285 | "283": "Persian cat", 286 | "284": "Siamese cat, Siamese", 287 | "285": "Egyptian cat", 288 | "286": "cougar, puma, catamount, mountain lion, painter, panther, Felis concolor", 289 | "287": "lynx, catamount", 290 | "288": "leopard, Panthera pardus", 291 | "289": "snow leopard, ounce, Panthera uncia", 292 | "290": "jaguar, panther, Panthera onca, Felis onca", 293 | "291": "lion, king of beasts, Panthera leo", 294 | "292": "tiger, Panthera tigris", 295 | "293": "cheetah, chetah, Acinonyx jubatus", 296 | "294": "brown bear, bruin, Ursus arctos", 297 | "295": "American black bear, black bear, Ursus americanus, Euarctos americanus", 298 | "296": "ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus", 299 | "297": "sloth bear, Melursus ursinus, Ursus ursinus", 300 | "298": "mongoose", 301 | "299": "meerkat, mierkat", 302 | "300": "tiger beetle", 303 | "301": "ladybug, ladybeetle, lady beetle, ladybird, ladybird beetle", 304 | "302": "ground beetle, carabid beetle", 305 | "303": "long-horned beetle, longicorn, longicorn beetle", 306 | "304": "leaf beetle, chrysomelid", 307 | "305": "dung beetle", 308 | "306": "rhinoceros beetle", 309 | "307": "weevil", 310 | "308": "fly", 311 | "309": "bee", 312 | "310": "ant, emmet, pismire", 313 | "311": "grasshopper, hopper", 314 | "312": "cricket", 315 | "313": "walking stick, walkingstick, stick insect", 316 | "314": "cockroach, roach", 317 | "315": "mantis, mantid", 318 | "316": "cicada, cicala", 319 | "317": "leafhopper", 320 | "318": "lacewing, lacewing fly", 321 | "319": "dragonfly, darning needle, devil's darning needle, sewing needle, snake feeder, snake doctor, mosquito hawk, skeeter hawk", 322 | "320": "damselfly", 323 | "321": "admiral", 324 | "322": "ringlet, ringlet butterfly", 325 | "323": "monarch, monarch butterfly, milkweed butterfly, Danaus plexippus", 326 | "324": "cabbage butterfly", 327 | "325": "sulphur butterfly, sulfur butterfly", 328 | "326": "lycaenid, lycaenid butterfly", 329 | "327": "starfish, sea star", 330 | "328": "sea urchin", 331 | "329": "sea cucumber, holothurian", 332 | "330": "wood rabbit, cottontail, cottontail rabbit", 333 | "331": "hare", 334 | "332": "Angora, Angora rabbit", 335 | "333": "hamster", 336 | "334": "porcupine, hedgehog", 337 | "335": "fox squirrel, eastern fox squirrel, Sciurus niger", 338 | "336": "marmot", 339 | "337": "beaver", 340 | "338": "guinea pig, Cavia cobaya", 341 | "339": "sorrel", 342 | "340": "zebra", 343 | "341": "hog, pig, grunter, squealer, Sus scrofa", 344 | "342": "wild boar, boar, Sus scrofa", 345 | "343": "warthog", 346 | "344": "hippopotamus, hippo, river horse, Hippopotamus amphibius", 347 | "345": "ox", 348 | "346": "water buffalo, water ox, Asiatic buffalo, Bubalus bubalis", 349 | "347": "bison", 350 | "348": "ram, tup", 351 | "349": "bighorn, bighorn sheep, cimarron, Rocky Mountain bighorn, Rocky Mountain sheep, Ovis canadensis", 352 | "350": "ibex, Capra ibex", 353 | "351": "hartebeest", 354 | "352": "impala, Aepyceros melampus", 355 | "353": "gazelle", 356 | "354": "Arabian camel, dromedary, Camelus dromedarius", 357 | "355": "llama", 358 | "356": "weasel", 359 | "357": "mink", 360 | "358": "polecat, fitch, foulmart, foumart, Mustela putorius", 361 | "359": "black-footed ferret, ferret, Mustela nigripes", 362 | "360": "otter", 363 | "361": "skunk, polecat, wood pussy", 364 | "362": "badger", 365 | "363": "armadillo", 366 | "364": "three-toed sloth, ai, Bradypus tridactylus", 367 | "365": "orangutan, orang, orangutang, Pongo pygmaeus", 368 | "366": "gorilla, Gorilla gorilla", 369 | "367": "chimpanzee, chimp, Pan troglodytes", 370 | "368": "gibbon, Hylobates lar", 371 | "369": "siamang, Hylobates syndactylus, Symphalangus syndactylus", 372 | "370": "guenon, guenon monkey", 373 | "371": "patas, hussar monkey, Erythrocebus patas", 374 | "372": "baboon", 375 | "373": "macaque", 376 | "374": "langur", 377 | "375": "colobus, colobus monkey", 378 | "376": "proboscis monkey, Nasalis larvatus", 379 | "377": "marmoset", 380 | "378": "capuchin, ringtail, Cebus capucinus", 381 | "379": "howler monkey, howler", 382 | "380": "titi, titi monkey", 383 | "381": "spider monkey, Ateles geoffroyi", 384 | "382": "squirrel monkey, Saimiri sciureus", 385 | "383": "Madagascar cat, ring-tailed lemur, Lemur catta", 386 | "384": "indri, indris, Indri indri, Indri brevicaudatus", 387 | "385": "Indian elephant, Elephas maximus", 388 | "386": "African elephant, Loxodonta africana", 389 | "387": "lesser panda, red panda, panda, bear cat, cat bear, Ailurus fulgens", 390 | "388": "giant panda, panda, panda bear, coon bear, Ailuropoda melanoleuca", 391 | "389": "barracouta, snoek", 392 | "390": "eel", 393 | "391": "coho, cohoe, coho salmon, blue jack, silver salmon, Oncorhynchus kisutch", 394 | "392": "rock beauty, Holocanthus tricolor", 395 | "393": "anemone fish", 396 | "394": "sturgeon", 397 | "395": "gar, garfish, garpike, billfish, Lepisosteus osseus", 398 | "396": "lionfish", 399 | "397": "puffer, pufferfish, blowfish, globefish", 400 | "398": "abacus", 401 | "399": "abaya", 402 | "400": "academic gown, academic robe, judge's robe", 403 | "401": "accordion, piano accordion, squeeze box", 404 | "402": "acoustic guitar", 405 | "403": "aircraft carrier, carrier, flattop, attack aircraft carrier", 406 | "404": "airliner", 407 | "405": "airship, dirigible", 408 | "406": "altar", 409 | "407": "ambulance", 410 | "408": "amphibian, amphibious vehicle", 411 | "409": "analog clock", 412 | "410": "apiary, bee house", 413 | "411": "apron", 414 | "412": "ashcan, trash can, garbage can, wastebin, ash bin, ash-bin, ashbin, dustbin, trash barrel, trash bin", 415 | "413": "assault rifle, assault gun", 416 | "414": "backpack, back pack, knapsack, packsack, rucksack, haversack", 417 | "415": "bakery, bakeshop, bakehouse", 418 | "416": "balance beam, beam", 419 | "417": "balloon", 420 | "418": "ballpoint, ballpoint pen, ballpen, Biro", 421 | "419": "Band Aid", 422 | "420": "banjo", 423 | "421": "bannister, banister, balustrade, balusters, handrail", 424 | "422": "barbell", 425 | "423": "barber chair", 426 | "424": "barbershop", 427 | "425": "barn", 428 | "426": "barometer", 429 | "427": "barrel, cask", 430 | "428": "barrow, garden cart, lawn cart, wheelbarrow", 431 | "429": "baseball", 432 | "430": "basketball", 433 | "431": "bassinet", 434 | "432": "bassoon", 435 | "433": "bathing cap, swimming cap", 436 | "434": "bath towel", 437 | "435": "bathtub, bathing tub, bath, tub", 438 | "436": "beach wagon, station wagon, wagon, estate car, beach waggon, station waggon, waggon", 439 | "437": "beacon, lighthouse, beacon light, pharos", 440 | "438": "beaker", 441 | "439": "bearskin, busby, shako", 442 | "440": "beer bottle", 443 | "441": "beer glass", 444 | "442": "bell cote, bell cot", 445 | "443": "bib", 446 | "444": "bicycle-built-for-two, tandem bicycle, tandem", 447 | "445": "bikini, two-piece", 448 | "446": "binder, ring-binder", 449 | "447": "binoculars, field glasses, opera glasses", 450 | "448": "birdhouse", 451 | "449": "boathouse", 452 | "450": "bobsled, bobsleigh, bob", 453 | "451": "bolo tie, bolo, bola tie, bola", 454 | "452": "bonnet, poke bonnet", 455 | "453": "bookcase", 456 | "454": "bookshop, bookstore, bookstall", 457 | "455": "bottlecap", 458 | "456": "bow", 459 | "457": "bow tie, bow-tie, bowtie", 460 | "458": "brass, memorial tablet, plaque", 461 | "459": "brassiere, bra, bandeau", 462 | "460": "breakwater, groin, groyne, mole, bulwark, seawall, jetty", 463 | "461": "breastplate, aegis, egis", 464 | "462": "broom", 465 | "463": "bucket, pail", 466 | "464": "buckle", 467 | "465": "bulletproof vest", 468 | "466": "bullet train, bullet", 469 | "467": "butcher shop, meat market", 470 | "468": "cab, hack, taxi, taxicab", 471 | "469": "caldron, cauldron", 472 | "470": "candle, taper, wax light", 473 | "471": "cannon", 474 | "472": "canoe", 475 | "473": "can opener, tin opener", 476 | "474": "cardigan", 477 | "475": "car mirror", 478 | "476": "carousel, carrousel, merry-go-round, roundabout, whirligig", 479 | "477": "carpenter's kit, tool kit", 480 | "478": "carton", 481 | "479": "car wheel", 482 | "480": "cash machine, cash dispenser, automated teller machine, automatic teller machine, automated teller, automatic teller, ATM", 483 | "481": "cassette", 484 | "482": "cassette player", 485 | "483": "castle", 486 | "484": "catamaran", 487 | "485": "CD player", 488 | "486": "cello, violoncello", 489 | "487": "cellular telephone, cellular phone, cellphone, cell, mobile phone", 490 | "488": "chain", 491 | "489": "chainlink fence", 492 | "490": "chain mail, ring mail, mail, chain armor, chain armour, ring armor, ring armour", 493 | "491": "chain saw, chainsaw", 494 | "492": "chest", 495 | "493": "chiffonier, commode", 496 | "494": "chime, bell, gong", 497 | "495": "china cabinet, china closet", 498 | "496": "Christmas stocking", 499 | "497": "church, church building", 500 | "498": "cinema, movie theater, movie theatre, movie house, picture palace", 501 | "499": "cleaver, meat cleaver, chopper", 502 | "500": "cliff dwelling", 503 | "501": "cloak", 504 | "502": "clog, geta, patten, sabot", 505 | "503": "cocktail shaker", 506 | "504": "coffee mug", 507 | "505": "coffeepot", 508 | "506": "coil, spiral, volute, whorl, helix", 509 | "507": "combination lock", 510 | "508": "computer keyboard, keypad", 511 | "509": "confectionery, confectionary, candy store", 512 | "510": "container ship, containership, container vessel", 513 | "511": "convertible", 514 | "512": "corkscrew, bottle screw", 515 | "513": "cornet, horn, trumpet, trump", 516 | "514": "cowboy boot", 517 | "515": "cowboy hat, ten-gallon hat", 518 | "516": "cradle", 519 | "517": "crane", 520 | "518": "crash helmet", 521 | "519": "crate", 522 | "520": "crib, cot", 523 | "521": "Crock Pot", 524 | "522": "croquet ball", 525 | "523": "crutch", 526 | "524": "cuirass", 527 | "525": "dam, dike, dyke", 528 | "526": "desk", 529 | "527": "desktop computer", 530 | "528": "dial telephone, dial phone", 531 | "529": "diaper, nappy, napkin", 532 | "530": "digital clock", 533 | "531": "digital watch", 534 | "532": "dining table, board", 535 | "533": "dishrag, dishcloth", 536 | "534": "dishwasher, dish washer, dishwashing machine", 537 | "535": "disk brake, disc brake", 538 | "536": "dock, dockage, docking facility", 539 | "537": "dogsled, dog sled, dog sleigh", 540 | "538": "dome", 541 | "539": "doormat, welcome mat", 542 | "540": "drilling platform, offshore rig", 543 | "541": "drum, membranophone, tympan", 544 | "542": "drumstick", 545 | "543": "dumbbell", 546 | "544": "Dutch oven", 547 | "545": "electric fan, blower", 548 | "546": "electric guitar", 549 | "547": "electric locomotive", 550 | "548": "entertainment center", 551 | "549": "envelope", 552 | "550": "espresso maker", 553 | "551": "face powder", 554 | "552": "feather boa, boa", 555 | "553": "file, file cabinet, filing cabinet", 556 | "554": "fireboat", 557 | "555": "fire engine, fire truck", 558 | "556": "fire screen, fireguard", 559 | "557": "flagpole, flagstaff", 560 | "558": "flute, transverse flute", 561 | "559": "folding chair", 562 | "560": "football helmet", 563 | "561": "forklift", 564 | "562": "fountain", 565 | "563": "fountain pen", 566 | "564": "four-poster", 567 | "565": "freight car", 568 | "566": "French horn, horn", 569 | "567": "frying pan, frypan, skillet", 570 | "568": "fur coat", 571 | "569": "garbage truck, dustcart", 572 | "570": "gasmask, respirator, gas helmet", 573 | "571": "gas pump, gasoline pump, petrol pump, island dispenser", 574 | "572": "goblet", 575 | "573": "go-kart", 576 | "574": "golf ball", 577 | "575": "golfcart, golf cart", 578 | "576": "gondola", 579 | "577": "gong, tam-tam", 580 | "578": "gown", 581 | "579": "grand piano, grand", 582 | "580": "greenhouse, nursery, glasshouse", 583 | "581": "grille, radiator grille", 584 | "582": "grocery store, grocery, food market, market", 585 | "583": "guillotine", 586 | "584": "hair slide", 587 | "585": "hair spray", 588 | "586": "half track", 589 | "587": "hammer", 590 | "588": "hamper", 591 | "589": "hand blower, blow dryer, blow drier, hair dryer, hair drier", 592 | "590": "hand-held computer, hand-held microcomputer", 593 | "591": "handkerchief, hankie, hanky, hankey", 594 | "592": "hard disc, hard disk, fixed disk", 595 | "593": "harmonica, mouth organ, harp, mouth harp", 596 | "594": "harp", 597 | "595": "harvester, reaper", 598 | "596": "hatchet", 599 | "597": "holster", 600 | "598": "home theater, home theatre", 601 | "599": "honeycomb", 602 | "600": "hook, claw", 603 | "601": "hoopskirt, crinoline", 604 | "602": "horizontal bar, high bar", 605 | "603": "horse cart, horse-cart", 606 | "604": "hourglass", 607 | "605": "iPod", 608 | "606": "iron, smoothing iron", 609 | "607": "jack-o'-lantern", 610 | "608": "jean, blue jean, denim", 611 | "609": "jeep, landrover", 612 | "610": "jersey, T-shirt, tee shirt", 613 | "611": "jigsaw puzzle", 614 | "612": "jinrikisha, ricksha, rickshaw", 615 | "613": "joystick", 616 | "614": "kimono", 617 | "615": "knee pad", 618 | "616": "knot", 619 | "617": "lab coat, laboratory coat", 620 | "618": "ladle", 621 | "619": "lampshade, lamp shade", 622 | "620": "laptop, laptop computer", 623 | "621": "lawn mower, mower", 624 | "622": "lens cap, lens cover", 625 | "623": "letter opener, paper knife, paperknife", 626 | "624": "library", 627 | "625": "lifeboat", 628 | "626": "lighter, light, igniter, ignitor", 629 | "627": "limousine, limo", 630 | "628": "liner, ocean liner", 631 | "629": "lipstick, lip rouge", 632 | "630": "Loafer", 633 | "631": "lotion", 634 | "632": "loudspeaker, speaker, speaker unit, loudspeaker system, speaker system", 635 | "633": "loupe, jeweler's loupe", 636 | "634": "lumbermill, sawmill", 637 | "635": "magnetic compass", 638 | "636": "mailbag, postbag", 639 | "637": "mailbox, letter box", 640 | "638": "maillot", 641 | "639": "maillot, tank suit", 642 | "640": "manhole cover", 643 | "641": "maraca", 644 | "642": "marimba, xylophone", 645 | "643": "mask", 646 | "644": "matchstick", 647 | "645": "maypole", 648 | "646": "maze, labyrinth", 649 | "647": "measuring cup", 650 | "648": "medicine chest, medicine cabinet", 651 | "649": "megalith, megalithic structure", 652 | "650": "microphone, mike", 653 | "651": "microwave, microwave oven", 654 | "652": "military uniform", 655 | "653": "milk can", 656 | "654": "minibus", 657 | "655": "miniskirt, mini", 658 | "656": "minivan", 659 | "657": "missile", 660 | "658": "mitten", 661 | "659": "mixing bowl", 662 | "660": "mobile home, manufactured home", 663 | "661": "Model T", 664 | "662": "modem", 665 | "663": "monastery", 666 | "664": "monitor", 667 | "665": "moped", 668 | "666": "mortar", 669 | "667": "mortarboard", 670 | "668": "mosque", 671 | "669": "mosquito net", 672 | "670": "motor scooter, scooter", 673 | "671": "mountain bike, all-terrain bike, off-roader", 674 | "672": "mountain tent", 675 | "673": "mouse, computer mouse", 676 | "674": "mousetrap", 677 | "675": "moving van", 678 | "676": "muzzle", 679 | "677": "nail", 680 | "678": "neck brace", 681 | "679": "necklace", 682 | "680": "nipple", 683 | "681": "notebook, notebook computer", 684 | "682": "obelisk", 685 | "683": "oboe, hautboy, hautbois", 686 | "684": "ocarina, sweet potato", 687 | "685": "odometer, hodometer, mileometer, milometer", 688 | "686": "oil filter", 689 | "687": "organ, pipe organ", 690 | "688": "oscilloscope, scope, cathode-ray oscilloscope, CRO", 691 | "689": "overskirt", 692 | "690": "oxcart", 693 | "691": "oxygen mask", 694 | "692": "packet", 695 | "693": "paddle, boat paddle", 696 | "694": "paddlewheel, paddle wheel", 697 | "695": "padlock", 698 | "696": "paintbrush", 699 | "697": "pajama, pyjama, pj's, jammies", 700 | "698": "palace", 701 | "699": "panpipe, pandean pipe, syrinx", 702 | "700": "paper towel", 703 | "701": "parachute, chute", 704 | "702": "parallel bars, bars", 705 | "703": "park bench", 706 | "704": "parking meter", 707 | "705": "passenger car, coach, carriage", 708 | "706": "patio, terrace", 709 | "707": "pay-phone, pay-station", 710 | "708": "pedestal, plinth, footstall", 711 | "709": "pencil box, pencil case", 712 | "710": "pencil sharpener", 713 | "711": "perfume, essence", 714 | "712": "Petri dish", 715 | "713": "photocopier", 716 | "714": "pick, plectrum, plectron", 717 | "715": "pickelhaube", 718 | "716": "picket fence, paling", 719 | "717": "pickup, pickup truck", 720 | "718": "pier", 721 | "719": "piggy bank, penny bank", 722 | "720": "pill bottle", 723 | "721": "pillow", 724 | "722": "ping-pong ball", 725 | "723": "pinwheel", 726 | "724": "pirate, pirate ship", 727 | "725": "pitcher, ewer", 728 | "726": "plane, carpenter's plane, woodworking plane", 729 | "727": "planetarium", 730 | "728": "plastic bag", 731 | "729": "plate rack", 732 | "730": "plow, plough", 733 | "731": "plunger, plumber's helper", 734 | "732": "Polaroid camera, Polaroid Land camera", 735 | "733": "pole", 736 | "734": "police van, police wagon, paddy wagon, patrol wagon, wagon, black Maria", 737 | "735": "poncho", 738 | "736": "pool table, billiard table, snooker table", 739 | "737": "pop bottle, soda bottle", 740 | "738": "pot, flowerpot", 741 | "739": "potter's wheel", 742 | "740": "power drill", 743 | "741": "prayer rug, prayer mat", 744 | "742": "printer", 745 | "743": "prison, prison house", 746 | "744": "projectile, missile", 747 | "745": "projector", 748 | "746": "puck, hockey puck", 749 | "747": "punching bag, punch bag, punching ball, punchball", 750 | "748": "purse", 751 | "749": "quill, quill pen", 752 | "750": "quilt, comforter, comfort, puff", 753 | "751": "racer, race car, racing car", 754 | "752": "racket, racquet", 755 | "753": "radiator", 756 | "754": "radio, wireless", 757 | "755": "radio telescope, radio reflector", 758 | "756": "rain barrel", 759 | "757": "recreational vehicle, RV, R.V.", 760 | "758": "reel", 761 | "759": "reflex camera", 762 | "760": "refrigerator, icebox", 763 | "761": "remote control, remote", 764 | "762": "restaurant, eating house, eating place, eatery", 765 | "763": "revolver, six-gun, six-shooter", 766 | "764": "rifle", 767 | "765": "rocking chair, rocker", 768 | "766": "rotisserie", 769 | "767": "rubber eraser, rubber, pencil eraser", 770 | "768": "rugby ball", 771 | "769": "rule, ruler", 772 | "770": "running shoe", 773 | "771": "safe", 774 | "772": "safety pin", 775 | "773": "saltshaker, salt shaker", 776 | "774": "sandal", 777 | "775": "sarong", 778 | "776": "sax, saxophone", 779 | "777": "scabbard", 780 | "778": "scale, weighing machine", 781 | "779": "school bus", 782 | "780": "schooner", 783 | "781": "scoreboard", 784 | "782": "screen, CRT screen", 785 | "783": "screw", 786 | "784": "screwdriver", 787 | "785": "seat belt, seatbelt", 788 | "786": "sewing machine", 789 | "787": "shield, buckler", 790 | "788": "shoe shop, shoe-shop, shoe store", 791 | "789": "shoji", 792 | "790": "shopping basket", 793 | "791": "shopping cart", 794 | "792": "shovel", 795 | "793": "shower cap", 796 | "794": "shower curtain", 797 | "795": "ski", 798 | "796": "ski mask", 799 | "797": "sleeping bag", 800 | "798": "slide rule, slipstick", 801 | "799": "sliding door", 802 | "800": "slot, one-armed bandit", 803 | "801": "snorkel", 804 | "802": "snowmobile", 805 | "803": "snowplow, snowplough", 806 | "804": "soap dispenser", 807 | "805": "soccer ball", 808 | "806": "sock", 809 | "807": "solar dish, solar collector, solar furnace", 810 | "808": "sombrero", 811 | "809": "soup bowl", 812 | "810": "space bar", 813 | "811": "space heater", 814 | "812": "space shuttle", 815 | "813": "spatula", 816 | "814": "speedboat", 817 | "815": "spider web, spider's web", 818 | "816": "spindle", 819 | "817": "sports car, sport car", 820 | "818": "spotlight, spot", 821 | "819": "stage", 822 | "820": "steam locomotive", 823 | "821": "steel arch bridge", 824 | "822": "steel drum", 825 | "823": "stethoscope", 826 | "824": "stole", 827 | "825": "stone wall", 828 | "826": "stopwatch, stop watch", 829 | "827": "stove", 830 | "828": "strainer", 831 | "829": "streetcar, tram, tramcar, trolley, trolley car", 832 | "830": "stretcher", 833 | "831": "studio couch, day bed", 834 | "832": "stupa, tope", 835 | "833": "submarine, pigboat, sub, U-boat", 836 | "834": "suit, suit of clothes", 837 | "835": "sundial", 838 | "836": "sunglass", 839 | "837": "sunglasses, dark glasses, shades", 840 | "838": "sunscreen, sunblock, sun blocker", 841 | "839": "suspension bridge", 842 | "840": "swab, swob, mop", 843 | "841": "sweatshirt", 844 | "842": "swimming trunks, bathing trunks", 845 | "843": "swing", 846 | "844": "switch, electric switch, electrical switch", 847 | "845": "syringe", 848 | "846": "table lamp", 849 | "847": "tank, army tank, armored combat vehicle, armoured combat vehicle", 850 | "848": "tape player", 851 | "849": "teapot", 852 | "850": "teddy, teddy bear", 853 | "851": "television, television system", 854 | "852": "tennis ball", 855 | "853": "thatch, thatched roof", 856 | "854": "theater curtain, theatre curtain", 857 | "855": "thimble", 858 | "856": "thresher, thrasher, threshing machine", 859 | "857": "throne", 860 | "858": "tile roof", 861 | "859": "toaster", 862 | "860": "tobacco shop, tobacconist shop, tobacconist", 863 | "861": "toilet seat", 864 | "862": "torch", 865 | "863": "totem pole", 866 | "864": "tow truck, tow car, wrecker", 867 | "865": "toyshop", 868 | "866": "tractor", 869 | "867": "trailer truck, tractor trailer, trucking rig, rig, articulated lorry, semi", 870 | "868": "tray", 871 | "869": "trench coat", 872 | "870": "tricycle, trike, velocipede", 873 | "871": "trimaran", 874 | "872": "tripod", 875 | "873": "triumphal arch", 876 | "874": "trolleybus, trolley coach, trackless trolley", 877 | "875": "trombone", 878 | "876": "tub, vat", 879 | "877": "turnstile", 880 | "878": "typewriter keyboard", 881 | "879": "umbrella", 882 | "880": "unicycle, monocycle", 883 | "881": "upright, upright piano", 884 | "882": "vacuum, vacuum cleaner", 885 | "883": "vase", 886 | "884": "vault", 887 | "885": "velvet", 888 | "886": "vending machine", 889 | "887": "vestment", 890 | "888": "viaduct", 891 | "889": "violin, fiddle", 892 | "890": "volleyball", 893 | "891": "waffle iron", 894 | "892": "wall clock", 895 | "893": "wallet, billfold, notecase, pocketbook", 896 | "894": "wardrobe, closet, press", 897 | "895": "warplane, military plane", 898 | "896": "washbasin, handbasin, washbowl, lavabo, wash-hand basin", 899 | "897": "washer, automatic washer, washing machine", 900 | "898": "water bottle", 901 | "899": "water jug", 902 | "900": "water tower", 903 | "901": "whiskey jug", 904 | "902": "whistle", 905 | "903": "wig", 906 | "904": "window screen", 907 | "905": "window shade", 908 | "906": "Windsor tie", 909 | "907": "wine bottle", 910 | "908": "wing", 911 | "909": "wok", 912 | "910": "wooden spoon", 913 | "911": "wool, woolen, woollen", 914 | "912": "worm fence, snake fence, snake-rail fence, Virginia fence", 915 | "913": "wreck", 916 | "914": "yawl", 917 | "915": "yurt", 918 | "916": "web site, website, internet site, site", 919 | "917": "comic book", 920 | "918": "crossword puzzle, crossword", 921 | "919": "street sign", 922 | "920": "traffic light, traffic signal, stoplight", 923 | "921": "book jacket, dust cover, dust jacket, dust wrapper", 924 | "922": "menu", 925 | "923": "plate", 926 | "924": "guacamole", 927 | "925": "consomme", 928 | "926": "hot pot, hotpot", 929 | "927": "trifle", 930 | "928": "ice cream, icecream", 931 | "929": "ice lolly, lolly, lollipop, popsicle", 932 | "930": "French loaf", 933 | "931": "bagel, beigel", 934 | "932": "pretzel", 935 | "933": "cheeseburger", 936 | "934": "hotdog, hot dog, red hot", 937 | "935": "mashed potato", 938 | "936": "head cabbage", 939 | "937": "broccoli", 940 | "938": "cauliflower", 941 | "939": "zucchini, courgette", 942 | "940": "spaghetti squash", 943 | "941": "acorn squash", 944 | "942": "butternut squash", 945 | "943": "cucumber, cuke", 946 | "944": "artichoke, globe artichoke", 947 | "945": "bell pepper", 948 | "946": "cardoon", 949 | "947": "mushroom", 950 | "948": "Granny Smith", 951 | "949": "strawberry", 952 | "950": "orange", 953 | "951": "lemon", 954 | "952": "fig", 955 | "953": "pineapple, ananas", 956 | "954": "banana", 957 | "955": "jackfruit, jak, jack", 958 | "956": "custard apple", 959 | "957": "pomegranate", 960 | "958": "hay", 961 | "959": "carbonara", 962 | "960": "chocolate sauce, chocolate syrup", 963 | "961": "dough", 964 | "962": "meat loaf, meatloaf", 965 | "963": "pizza, pizza pie", 966 | "964": "potpie", 967 | "965": "burrito", 968 | "966": "red wine", 969 | "967": "espresso", 970 | "968": "cup", 971 | "969": "eggnog", 972 | "970": "alp", 973 | "971": "bubble", 974 | "972": "cliff, drop, drop-off", 975 | "973": "coral reef", 976 | "974": "geyser", 977 | "975": "lakeside, lakeshore", 978 | "976": "promontory, headland, head, foreland", 979 | "977": "sandbar, sand bar", 980 | "978": "seashore, coast, seacoast, sea-coast", 981 | "979": "valley, vale", 982 | "980": "volcano", 983 | "981": "ballplayer, baseball player", 984 | "982": "groom, bridegroom", 985 | "983": "scuba diver", 986 | "984": "rapeseed", 987 | "985": "daisy", 988 | "986": "yellow lady's slipper, yellow lady-slipper, Cypripedium calceolus, Cypripedium parviflorum", 989 | "987": "corn", 990 | "988": "acorn", 991 | "989": "hip, rose hip, rosehip", 992 | "990": "buckeye, horse chestnut, conker", 993 | "991": "coral fungus", 994 | "992": "agaric", 995 | "993": "gyromitra", 996 | "994": "stinkhorn, carrion fungus", 997 | "995": "earthstar", 998 | "996": "hen-of-the-woods, hen of the woods, Polyporus frondosus, Grifola frondosa", 999 | "997": "bolete", 1000 | "998": "ear, spike, capitulum", 1001 | "999": "toilet tissue, toilet paper, bathroom tissue" 1002 | } -------------------------------------------------------------------------------- /ImageClassifier/ImageClassifier.licenseheader: -------------------------------------------------------------------------------- 1 | extensions: designer.cs generated.cs 2 | extensions: .cs 3 | // Licensed to the .NET Foundation under one or more agreements. 4 | // The .NET Foundation licenses this file to you under the MIT license. 5 | // See the LICENSE file in the project root for more information. 6 | -------------------------------------------------------------------------------- /ImageClassifier/IntelligentAPI_ImageClassifier.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | IntelligentAPI.ImageClassification 4 | 5 | 6 | CommunityToolkit.Labs.Intelligent.ImageClassification 7 | 8 | This package performs Image Classification on an input image by using the SqueezeNet Onnx model. 9 | 10 | 0.0.25 11 | 12 | 13 | 14 | 15 | 16 | 17 | 5.0.2 18 | 19 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /ImageClassifier/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Reflection; 6 | using System.Runtime.CompilerServices; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTrademark("")] 13 | [assembly: AssemblyCulture("")] 14 | 15 | // Version information for an assembly consists of the following four values: 16 | // 17 | // Major Version 18 | // Minor Version 19 | // Build Number 20 | // Revision 21 | // 22 | // You can specify all the values or you can default the Build and Revision Numbers 23 | // by using the '*' as shown below: 24 | // [assembly: AssemblyVersion("1.0.*")] 25 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /ImageClassifier/Properties/IntelligentAPI_ImageClassifier.rd.xml: -------------------------------------------------------------------------------- 1 | 2 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ImageClassifier/Scripts/script.ps1: -------------------------------------------------------------------------------- 1 | $ProgressPreference = 'SilentlyContinue' 2 | 3 | $squeezenetfile = "./Assets/model.onnx" 4 | if (-not(Test-Path -Path $squeezenetfile -PathType Leaf)) { 5 | try { 6 | Invoke-WebRequest -URI "https://github.com/microsoft/Windows-Machine-Learning/raw/master/Samples/SqueezeNetObjectDetection/UWP/cs/Assets/model.onnx" -OutFile $squeezenetfile 7 | Write-Host "The file [$squeezenetfile] has been created." 8 | } 9 | catch { 10 | throw $_.Exception.Message 11 | } 12 | } 13 | else { 14 | Write-Host "The file [$squeezenetfile] exists." 15 | } -------------------------------------------------------------------------------- /ImageClassifier/SqueezeNetImageClassifier.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Reflection; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | using Windows.AI.MachineLearning; 13 | using Windows.Graphics.Imaging; 14 | using Windows.Media; 15 | using Windows.Storage; 16 | using Windows.Storage.Streams; 17 | using Windows.UI.Xaml.Media.Imaging; 18 | using System.Text.Json; 19 | 20 | 21 | namespace CommunityToolkit.Labs.Intelligent.ImageClassification 22 | { 23 | /// 24 | /// SqueezeNetImageClassifier is used to perform image classification using the SqueezeNet model. 25 | /// 26 | public class SqueezeNetImageClassifier 27 | { 28 | /// 29 | /// Model file name 30 | /// 31 | private const string _modelFileName = "model.onnx"; 32 | 33 | /// 34 | /// Labels file name 35 | /// 36 | private const string _labelsFileName = "Labels.json"; 37 | 38 | /// 39 | /// Learning model instance 40 | /// 41 | private LearningModel _model = null; 42 | 43 | /// 44 | /// LearningModelSession instance 45 | /// 46 | private LearningModelSession _session; 47 | 48 | /// 49 | /// list of labels that YOLOv4 can detect 50 | /// 51 | private List _labels = new List(); 52 | 53 | /// 54 | /// Number of runs 55 | /// 56 | private int _runCount = 0; 57 | private static SqueezeNetImageClassifier instance; 58 | 59 | private SqueezeNetImageClassifier() 60 | { 61 | } 62 | 63 | /// 64 | /// Classifies image based on StorageFile input 65 | /// 66 | /// 67 | /// Top k results, accepts positive values up to 1000 68 | /// 69 | public static async Task> ClassifyImage(StorageFile selectedStorageFile, uint top=3) 70 | { 71 | CreateInstanceIfNone(); 72 | SoftwareBitmap softwareBitmap = await GenerateSoftwareBitmapFromStorageFile(selectedStorageFile); 73 | VideoFrame videoFrame = GenerateVideoFrameFromBitmap(softwareBitmap); 74 | return await instance.EvaluateModel(videoFrame, top); 75 | } 76 | 77 | /// 78 | /// Classifies image based on SoftwareBitmap input 79 | /// 80 | /// 81 | /// Top k results, accepts positive values up to 1000 82 | /// 83 | public static async Task> ClassifyImage(SoftwareBitmap softwareBitmap, uint top=3) 84 | { 85 | CreateInstanceIfNone(); 86 | softwareBitmap = GetSoftwareBitmap(softwareBitmap); 87 | VideoFrame videoFrame = GenerateVideoFrameFromBitmap(softwareBitmap); 88 | return await instance.EvaluateModel(videoFrame, top); 89 | } 90 | 91 | /// 92 | /// Classifies image based on VideoFrame input 93 | /// 94 | /// 95 | /// Top k results, accepts positive values up to 1000 96 | /// 97 | public static async Task> ClassifyImage(VideoFrame videoFrame, uint top=3) 98 | { 99 | CreateInstanceIfNone(); 100 | return await instance.EvaluateModel(videoFrame, top); 101 | } 102 | 103 | 104 | /// 105 | /// Creates a new instance of SqueezeNetImageClassifier if it does not exist 106 | /// 107 | private static void CreateInstanceIfNone() 108 | { 109 | if (instance == null) 110 | { 111 | instance = new SqueezeNetImageClassifier(); 112 | } 113 | } 114 | 115 | /// 116 | /// Evaluates the input image which is a VideoFrame instance 117 | /// 118 | /// 119 | /// 120 | /// 121 | public async Task> EvaluateModel(VideoFrame inputImage, uint top) 122 | { 123 | await LoadModelAsync(); 124 | return await EvaluateVideoFrameAsync(inputImage, top); 125 | } 126 | 127 | /// 128 | /// Converts object of type SoftwareBitmap to VideoFrame 129 | /// 130 | /// 131 | /// 132 | private static VideoFrame GenerateVideoFrameFromBitmap(SoftwareBitmap softwareBitmap) 133 | { 134 | // Encapsulate the image within a VideoFrame to be bound and evaluated 135 | VideoFrame videoFrame = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap); 136 | return videoFrame; 137 | } 138 | 139 | 140 | /// 141 | /// Converts object of type StorageFile to SoftwareBitmap 142 | /// 143 | /// 144 | /// 145 | private static async Task GenerateSoftwareBitmapFromStorageFile(StorageFile selectedStorageFile) 146 | { 147 | SoftwareBitmap softwareBitmap; 148 | using (IRandomAccessStream stream = await selectedStorageFile.OpenAsync(FileAccessMode.Read)) 149 | { 150 | // Create the decoder from the stream 151 | BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); 152 | 153 | // Get the SoftwareBitmap representation of the file in BGRA8 format 154 | softwareBitmap = await decoder.GetSoftwareBitmapAsync(); 155 | softwareBitmap = GetSoftwareBitmap(softwareBitmap); 156 | } 157 | 158 | return softwareBitmap; 159 | } 160 | 161 | 162 | 163 | /// 164 | /// Get Software Bitmap 165 | /// 166 | /// 167 | /// 168 | private static SoftwareBitmap GetSoftwareBitmap(SoftwareBitmap softwareBitmap) 169 | { 170 | if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || (softwareBitmap.BitmapAlphaMode != BitmapAlphaMode.Ignore && softwareBitmap.BitmapAlphaMode != BitmapAlphaMode.Premultiplied)) 171 | { 172 | softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); 173 | } 174 | return softwareBitmap; 175 | } 176 | 177 | 178 | /// 179 | /// Loads an onnx model from file and deserializes the JSON file containing the labels 180 | /// 181 | /// 182 | private async Task LoadModelAsync() 183 | { 184 | // just load the model one time. 185 | if (_model != null) return; 186 | 187 | try 188 | { 189 | // Parse labels from label json file. We know the file's 190 | // entries are already sorted in order. 191 | var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///IntelligentAPI_ImageClassifier/Assets/" + _labelsFileName)); 192 | 193 | var fileString = await FileIO.ReadTextAsync(file); 194 | 195 | var fileDict = JsonSerializer.Deserialize>(fileString); 196 | 197 | foreach (var kvp in fileDict) 198 | { 199 | _labels.Add(kvp.Value); 200 | } 201 | 202 | 203 | var modelFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///IntelligentAPI_ImageClassifier/Assets/" + _modelFileName)); 204 | _model = await LearningModel.LoadFromStorageFileAsync(modelFile); 205 | 206 | // Create the evaluation session with the model and device 207 | _session = new LearningModelSession(_model, new LearningModelDevice(GetDeviceKind())); 208 | 209 | 210 | } 211 | catch (Exception ex) 212 | { 213 | _model = null; 214 | throw ex; 215 | } 216 | } 217 | 218 | /// 219 | /// Gets type of device to evaluate the model on 220 | /// 221 | /// 222 | LearningModelDeviceKind GetDeviceKind() 223 | { 224 | 225 | return LearningModelDeviceKind.Default; 226 | } 227 | 228 | /// 229 | /// Evaluate the SqueezeNet model 230 | /// 231 | /// 232 | /// 233 | /// 234 | private async Task> EvaluateVideoFrameAsync(VideoFrame inputFrame, uint top) 235 | { 236 | List result = new List(); 237 | if (inputFrame != null) 238 | { 239 | try 240 | { 241 | // create a binding object from the session 242 | LearningModelBinding binding = new LearningModelBinding(_session); 243 | 244 | // bind the input image 245 | ImageFeatureValue imageTensor = ImageFeatureValue.CreateFromVideoFrame(inputFrame); 246 | binding.Bind("data_0", imageTensor); 247 | 248 | // Process the frame with the model 249 | var results = await _session.EvaluateAsync(binding, $"Run { ++_runCount } "); 250 | 251 | // retrieve results from evaluation 252 | var resultTensor = results.Outputs["softmaxout_1"] as TensorFloat; 253 | var resultVector = resultTensor.GetAsVectorView(); 254 | 255 | // Find the top 3 probabilities 256 | List<(int index, float probability)> indexedResults = new List<(int, float)>(); 257 | for (int i = 0; i < resultVector.Count; i++) 258 | { 259 | indexedResults.Add((index: i, probability: resultVector.ElementAt(i))); 260 | } 261 | indexedResults.Sort((a, b) => 262 | { 263 | if (a.probability < b.probability) 264 | { 265 | return 1; 266 | } 267 | else if (a.probability > b.probability) 268 | { 269 | return -1; 270 | } 271 | else 272 | { 273 | return 0; 274 | } 275 | }); 276 | 277 | if(top < 0 || top > 1000) 278 | { 279 | throw new ArgumentOutOfRangeException("top", "Value is out of range, expected to be between 0 and 1000"); 280 | } 281 | for (int i = 0; i < top; i++) 282 | { 283 | result.Add(new ClassificationResult(_labels[indexedResults[i].index], indexedResults[i].probability)); 284 | } 285 | 286 | 287 | } 288 | catch (Exception ex) 289 | { 290 | throw ex; 291 | } 292 | 293 | } 294 | 295 | return result; 296 | } 297 | } 298 | 299 | /// 300 | /// Result of Image Classification model evaluation. 301 | /// 302 | public class ClassificationResult 303 | { 304 | /// 305 | /// Category that the image belongs to 306 | /// 307 | public string category; 308 | 309 | /// 310 | /// Confidence value of the predicted category. 311 | /// 312 | public float confidence; 313 | public ClassificationResult(string category, float confidence) 314 | { 315 | this.category = category; 316 | this.confidence = confidence; 317 | } 318 | } 319 | 320 | } 321 | 322 | 323 | 324 | 325 | 326 | -------------------------------------------------------------------------------- /ImageClassifier/model.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | // This file was automatically generated by VS extension Windows Machine Learning Code Generator v3 6 | // from model file model.onnx 7 | // Warning: This file may get overwritten if you add add an onnx file with the same name 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Threading.Tasks; 11 | using Windows.Media; 12 | using Windows.Storage; 13 | using Windows.Storage.Streams; 14 | using Windows.AI.MachineLearning; 15 | 16 | namespace CommunityToolkit.Labs.Intelligent.ImageClassification 17 | { 18 | /// 19 | /// Input for the SqueezeNet model 20 | /// 21 | public sealed class Input 22 | { 23 | public TensorFloat data_0; // shape(1,3,224,224) 24 | } 25 | 26 | /// 27 | /// Output of the SqueezeNet model 28 | /// 29 | public sealed class Output 30 | { 31 | public TensorFloat softmaxout_1; // shape(1,1000,1,1) 32 | } 33 | 34 | /// 35 | /// SqueezeNet Model 36 | /// 37 | public sealed class Model 38 | { 39 | /// 40 | /// LearningModel instance for the trained SqueezeNet model 41 | /// 42 | private LearningModel model; 43 | 44 | /// 45 | /// LearningModelSession instance that will be used to evaluate the model 46 | /// 47 | private LearningModelSession session; 48 | 49 | /// 50 | /// Bindings that will bind values to named input and output features. 51 | /// 52 | private LearningModelBinding binding; 53 | 54 | /// 55 | /// Loads the model, creates a session and binding instance. 56 | /// 57 | /// 58 | /// 59 | public static async Task CreateFromStreamAsync(IRandomAccessStreamReference stream) 60 | { 61 | Model learningModel = new Model(); 62 | learningModel.model = await LearningModel.LoadFromStreamAsync(stream); 63 | learningModel.session = new LearningModelSession(learningModel.model); 64 | learningModel.binding = new LearningModelBinding(learningModel.session); 65 | return learningModel; 66 | } 67 | 68 | /// 69 | /// Asynchronously evaluate SqueezeNet model 70 | /// 71 | /// 72 | /// 73 | public async Task EvaluateAsync(Input input) 74 | { 75 | binding.Bind("data_0", input.data_0); 76 | var result = await session.EvaluateAsync(binding, "0"); 77 | var output = new Output(); 78 | output.softmaxout_1 = result.Outputs["softmaxout_1"] as TensorFloat; 79 | return output; 80 | } 81 | } 82 | } 83 | 84 | -------------------------------------------------------------------------------- /IntelligentAPIs.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31410.357 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntelligentAPI_ObjectDetector", "ObjectDetector\IntelligentAPI_ObjectDetector.csproj", "{6F985DC2-DB68-49E5-ADD8-6D11F35E552E}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntelligentAPI_ImageClassifier", "ImageClassifier\IntelligentAPI_ImageClassifier.csproj", "{F705B499-D0B5-408C-B1D1-D3F379D0FCD6}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IntelligentLabsTest", "IntelligentAPIsTester\IntelligentLabsTest.csproj", "{47D87733-B357-4706-88BD-211FB7D8679D}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IntelligentAPI_EmotionRecognizer", "EmotionRecognizer\IntelligentAPI_EmotionRecognizer.csproj", "{784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}" 13 | EndProject 14 | Global 15 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 16 | Debug|Any CPU = Debug|Any CPU 17 | Debug|ARM = Debug|ARM 18 | Debug|ARM64 = Debug|ARM64 19 | Debug|x64 = Debug|x64 20 | Debug|x86 = Debug|x86 21 | Packages|Any CPU = Packages|Any CPU 22 | Packages|ARM = Packages|ARM 23 | Packages|ARM64 = Packages|ARM64 24 | Packages|x64 = Packages|x64 25 | Packages|x86 = Packages|x86 26 | Release|Any CPU = Release|Any CPU 27 | Release|ARM = Release|ARM 28 | Release|ARM64 = Release|ARM64 29 | Release|x64 = Release|x64 30 | Release|x86 = Release|x86 31 | EndGlobalSection 32 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 33 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 34 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Debug|Any CPU.Build.0 = Debug|Any CPU 35 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Debug|ARM.ActiveCfg = Debug|ARM 36 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Debug|ARM.Build.0 = Debug|ARM 37 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Debug|ARM64.ActiveCfg = Debug|ARM64 38 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Debug|ARM64.Build.0 = Debug|ARM64 39 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Debug|x64.ActiveCfg = Debug|x64 40 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Debug|x64.Build.0 = Debug|x64 41 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Debug|x86.ActiveCfg = Debug|x86 42 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Debug|x86.Build.0 = Debug|x86 43 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Packages|Any CPU.ActiveCfg = Release|Any CPU 44 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Packages|Any CPU.Build.0 = Release|Any CPU 45 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Packages|ARM.ActiveCfg = Release|ARM 46 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Packages|ARM.Build.0 = Release|ARM 47 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Packages|ARM64.ActiveCfg = Release|ARM64 48 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Packages|ARM64.Build.0 = Release|ARM64 49 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Packages|x64.ActiveCfg = Release|x64 50 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Packages|x64.Build.0 = Release|x64 51 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Packages|x86.ActiveCfg = Release|x86 52 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Packages|x86.Build.0 = Release|x86 53 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Release|Any CPU.ActiveCfg = Release|Any CPU 54 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Release|Any CPU.Build.0 = Release|Any CPU 55 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Release|ARM.ActiveCfg = Release|ARM 56 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Release|ARM.Build.0 = Release|ARM 57 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Release|ARM64.ActiveCfg = Release|ARM64 58 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Release|ARM64.Build.0 = Release|ARM64 59 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Release|x64.ActiveCfg = Release|x64 60 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Release|x64.Build.0 = Release|x64 61 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Release|x86.ActiveCfg = Release|x86 62 | {6F985DC2-DB68-49E5-ADD8-6D11F35E552E}.Release|x86.Build.0 = Release|x86 63 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 64 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Debug|Any CPU.Build.0 = Debug|Any CPU 65 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Debug|ARM.ActiveCfg = Debug|ARM 66 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Debug|ARM.Build.0 = Debug|ARM 67 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Debug|ARM64.ActiveCfg = Debug|ARM64 68 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Debug|ARM64.Build.0 = Debug|ARM64 69 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Debug|x64.ActiveCfg = Debug|x64 70 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Debug|x64.Build.0 = Debug|x64 71 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Debug|x86.ActiveCfg = Debug|x86 72 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Debug|x86.Build.0 = Debug|x86 73 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Packages|Any CPU.ActiveCfg = Release|Any CPU 74 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Packages|Any CPU.Build.0 = Release|Any CPU 75 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Packages|ARM.ActiveCfg = Release|ARM 76 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Packages|ARM.Build.0 = Release|ARM 77 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Packages|ARM64.ActiveCfg = Release|ARM64 78 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Packages|ARM64.Build.0 = Release|ARM64 79 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Packages|x64.ActiveCfg = Release|x64 80 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Packages|x64.Build.0 = Release|x64 81 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Packages|x86.ActiveCfg = Release|x86 82 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Packages|x86.Build.0 = Release|x86 83 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Release|Any CPU.ActiveCfg = Release|Any CPU 84 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Release|Any CPU.Build.0 = Release|Any CPU 85 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Release|ARM.ActiveCfg = Release|ARM 86 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Release|ARM.Build.0 = Release|ARM 87 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Release|ARM64.ActiveCfg = Release|ARM64 88 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Release|ARM64.Build.0 = Release|ARM64 89 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Release|x64.ActiveCfg = Release|x64 90 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Release|x64.Build.0 = Release|x64 91 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Release|x86.ActiveCfg = Release|x86 92 | {F705B499-D0B5-408C-B1D1-D3F379D0FCD6}.Release|x86.Build.0 = Release|x86 93 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|Any CPU.ActiveCfg = Debug|x86 94 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|Any CPU.Build.0 = Debug|x86 95 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|Any CPU.Deploy.0 = Debug|x86 96 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|ARM.ActiveCfg = Debug|ARM 97 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|ARM.Build.0 = Debug|ARM 98 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|ARM.Deploy.0 = Debug|ARM 99 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|ARM64.ActiveCfg = Debug|ARM64 100 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|ARM64.Build.0 = Debug|ARM64 101 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|ARM64.Deploy.0 = Debug|ARM64 102 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|x64.ActiveCfg = Debug|x64 103 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|x64.Build.0 = Debug|x64 104 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|x64.Deploy.0 = Debug|x64 105 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|x86.ActiveCfg = Debug|x86 106 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|x86.Build.0 = Debug|x86 107 | {47D87733-B357-4706-88BD-211FB7D8679D}.Debug|x86.Deploy.0 = Debug|x86 108 | {47D87733-B357-4706-88BD-211FB7D8679D}.Packages|Any CPU.ActiveCfg = Release|x86 109 | {47D87733-B357-4706-88BD-211FB7D8679D}.Packages|ARM.ActiveCfg = Release|ARM 110 | {47D87733-B357-4706-88BD-211FB7D8679D}.Packages|ARM64.ActiveCfg = Release|ARM64 111 | {47D87733-B357-4706-88BD-211FB7D8679D}.Packages|x64.ActiveCfg = Release|x64 112 | {47D87733-B357-4706-88BD-211FB7D8679D}.Packages|x86.ActiveCfg = Release|x86 113 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|Any CPU.ActiveCfg = Release|x86 114 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|Any CPU.Build.0 = Release|x86 115 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|Any CPU.Deploy.0 = Release|x86 116 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|ARM.ActiveCfg = Release|ARM 117 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|ARM.Build.0 = Release|ARM 118 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|ARM.Deploy.0 = Release|ARM 119 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|ARM64.ActiveCfg = Release|ARM64 120 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|ARM64.Build.0 = Release|ARM64 121 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|ARM64.Deploy.0 = Release|ARM64 122 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|x64.ActiveCfg = Release|x64 123 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|x64.Build.0 = Release|x64 124 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|x64.Deploy.0 = Release|x64 125 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|x86.ActiveCfg = Release|x86 126 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|x86.Build.0 = Release|x86 127 | {47D87733-B357-4706-88BD-211FB7D8679D}.Release|x86.Deploy.0 = Release|x86 128 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 129 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Debug|Any CPU.Build.0 = Debug|Any CPU 130 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Debug|ARM.ActiveCfg = Debug|Any CPU 131 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Debug|ARM.Build.0 = Debug|Any CPU 132 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Debug|ARM64.ActiveCfg = Debug|Any CPU 133 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Debug|ARM64.Build.0 = Debug|Any CPU 134 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Debug|x64.ActiveCfg = Debug|Any CPU 135 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Debug|x64.Build.0 = Debug|Any CPU 136 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Debug|x86.ActiveCfg = Debug|Any CPU 137 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Debug|x86.Build.0 = Debug|Any CPU 138 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Packages|Any CPU.ActiveCfg = Debug|Any CPU 139 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Packages|Any CPU.Build.0 = Debug|Any CPU 140 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Packages|ARM.ActiveCfg = Debug|Any CPU 141 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Packages|ARM.Build.0 = Debug|Any CPU 142 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Packages|ARM64.ActiveCfg = Debug|Any CPU 143 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Packages|ARM64.Build.0 = Debug|Any CPU 144 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Packages|x64.ActiveCfg = Debug|Any CPU 145 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Packages|x64.Build.0 = Debug|Any CPU 146 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Packages|x86.ActiveCfg = Debug|Any CPU 147 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Packages|x86.Build.0 = Debug|Any CPU 148 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Release|Any CPU.ActiveCfg = Release|Any CPU 149 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Release|Any CPU.Build.0 = Release|Any CPU 150 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Release|ARM.ActiveCfg = Release|Any CPU 151 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Release|ARM.Build.0 = Release|Any CPU 152 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Release|ARM64.ActiveCfg = Release|Any CPU 153 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Release|ARM64.Build.0 = Release|Any CPU 154 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Release|x64.ActiveCfg = Release|Any CPU 155 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Release|x64.Build.0 = Release|Any CPU 156 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Release|x86.ActiveCfg = Release|Any CPU 157 | {784A3C01-BD0B-4DB9-B1FF-2A16E2B03A65}.Release|x86.Build.0 = Release|Any CPU 158 | EndGlobalSection 159 | GlobalSection(SolutionProperties) = preSolution 160 | HideSolutionNode = FALSE 161 | EndGlobalSection 162 | GlobalSection(ExtensibilityGlobals) = postSolution 163 | SolutionGuid = {BB3C9207-5887-4BFC-8FBE-FD4576189591} 164 | EndGlobalSection 165 | EndGlobal 166 | -------------------------------------------------------------------------------- /IntelligentAPIsTester/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | -------------------------------------------------------------------------------- /IntelligentAPIsTester/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Runtime.InteropServices.WindowsRuntime; 6 | using Windows.ApplicationModel; 7 | using Windows.ApplicationModel.Activation; 8 | using Windows.Foundation; 9 | using Windows.Foundation.Collections; 10 | using Windows.UI.Xaml; 11 | using Windows.UI.Xaml.Controls; 12 | using Windows.UI.Xaml.Controls.Primitives; 13 | using Windows.UI.Xaml.Data; 14 | using Windows.UI.Xaml.Input; 15 | using Windows.UI.Xaml.Media; 16 | using Windows.UI.Xaml.Navigation; 17 | 18 | namespace IntelligentLabsTest 19 | { 20 | /// 21 | /// Provides application-specific behavior to supplement the default Application class. 22 | /// 23 | sealed partial class App : Application 24 | { 25 | /// 26 | /// Initializes the singleton application object. This is the first line of authored code 27 | /// executed, and as such is the logical equivalent of main() or WinMain(). 28 | /// 29 | public App() 30 | { 31 | this.InitializeComponent(); 32 | this.Suspending += OnSuspending; 33 | } 34 | 35 | /// 36 | /// Invoked when the application is launched normally by the end user. Other entry points 37 | /// will be used such as when the application is launched to open a specific file. 38 | /// 39 | /// Details about the launch request and process. 40 | protected override void OnLaunched(LaunchActivatedEventArgs e) 41 | { 42 | Frame rootFrame = Window.Current.Content as Frame; 43 | 44 | // Do not repeat app initialization when the Window already has content, 45 | // just ensure that the window is active 46 | if (rootFrame == null) 47 | { 48 | // Create a Frame to act as the navigation context and navigate to the first page 49 | rootFrame = new Frame(); 50 | 51 | rootFrame.NavigationFailed += OnNavigationFailed; 52 | 53 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) 54 | { 55 | //TODO: Load state from previously suspended application 56 | } 57 | 58 | // Place the frame in the current Window 59 | Window.Current.Content = rootFrame; 60 | } 61 | 62 | if (e.PrelaunchActivated == false) 63 | { 64 | if (rootFrame.Content == null) 65 | { 66 | // When the navigation stack isn't restored navigate to the first page, 67 | // configuring the new page by passing required information as a navigation 68 | // parameter 69 | rootFrame.Navigate(typeof(MainPage), e.Arguments); 70 | } 71 | // Ensure the current window is active 72 | Window.Current.Activate(); 73 | } 74 | } 75 | 76 | /// 77 | /// Invoked when Navigation to a certain page fails 78 | /// 79 | /// The Frame which failed navigation 80 | /// Details about the navigation failure 81 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e) 82 | { 83 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName); 84 | } 85 | 86 | /// 87 | /// Invoked when application execution is being suspended. Application state is saved 88 | /// without knowing whether the application will be terminated or resumed with the contents 89 | /// of memory still intact. 90 | /// 91 | /// The source of the suspend request. 92 | /// Details about the suspend request. 93 | private void OnSuspending(object sender, SuspendingEventArgs e) 94 | { 95 | var deferral = e.SuspendingOperation.GetDeferral(); 96 | //TODO: Save application state and stop any background activity 97 | deferral.Complete(); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /IntelligentAPIsTester/Assets/LockScreenLogo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/2ae6217be93b9df825c12dddddc5ba957604440e/IntelligentAPIsTester/Assets/LockScreenLogo.scale-200.png -------------------------------------------------------------------------------- /IntelligentAPIsTester/Assets/SplashScreen.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/2ae6217be93b9df825c12dddddc5ba957604440e/IntelligentAPIsTester/Assets/SplashScreen.scale-200.png -------------------------------------------------------------------------------- /IntelligentAPIsTester/Assets/Square150x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/2ae6217be93b9df825c12dddddc5ba957604440e/IntelligentAPIsTester/Assets/Square150x150Logo.scale-200.png -------------------------------------------------------------------------------- /IntelligentAPIsTester/Assets/Square44x44Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/2ae6217be93b9df825c12dddddc5ba957604440e/IntelligentAPIsTester/Assets/Square44x44Logo.scale-200.png -------------------------------------------------------------------------------- /IntelligentAPIsTester/Assets/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/2ae6217be93b9df825c12dddddc5ba957604440e/IntelligentAPIsTester/Assets/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /IntelligentAPIsTester/Assets/StoreLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/2ae6217be93b9df825c12dddddc5ba957604440e/IntelligentAPIsTester/Assets/StoreLogo.png -------------------------------------------------------------------------------- /IntelligentAPIsTester/Assets/Wide310x150Logo.scale-200.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/2ae6217be93b9df825c12dddddc5ba957604440e/IntelligentAPIsTester/Assets/Wide310x150Logo.scale-200.png -------------------------------------------------------------------------------- /IntelligentAPIsTester/Assets/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/2ae6217be93b9df825c12dddddc5ba957604440e/IntelligentAPIsTester/Assets/background.jpg -------------------------------------------------------------------------------- /IntelligentAPIsTester/IntelligentLabsTest.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | x86 7 | {47D87733-B357-4706-88BD-211FB7D8679D} 8 | AppContainerExe 9 | Properties 10 | IntelligentLabsTest 11 | IntelligentLabsTest 12 | en-US 13 | UAP 14 | 10.0.19041.0 15 | 10.0.17763.0 16 | 14 17 | 512 18 | {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 19 | true 20 | false 21 | 22 | 23 | true 24 | bin\x86\Debug\ 25 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 26 | ;2008 27 | full 28 | x86 29 | false 30 | prompt 31 | true 32 | 33 | 34 | bin\x86\Release\ 35 | TRACE;NETFX_CORE;WINDOWS_UWP 36 | true 37 | ;2008 38 | pdbonly 39 | x86 40 | false 41 | prompt 42 | true 43 | true 44 | 45 | 46 | true 47 | bin\ARM\Debug\ 48 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 49 | ;2008 50 | full 51 | ARM 52 | false 53 | prompt 54 | true 55 | 56 | 57 | bin\ARM\Release\ 58 | TRACE;NETFX_CORE;WINDOWS_UWP 59 | true 60 | ;2008 61 | pdbonly 62 | ARM 63 | false 64 | prompt 65 | true 66 | true 67 | 68 | 69 | true 70 | bin\ARM64\Debug\ 71 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 72 | ;2008 73 | full 74 | ARM64 75 | false 76 | prompt 77 | true 78 | true 79 | 80 | 81 | bin\ARM64\Release\ 82 | TRACE;NETFX_CORE;WINDOWS_UWP 83 | true 84 | ;2008 85 | pdbonly 86 | ARM64 87 | false 88 | prompt 89 | true 90 | true 91 | 92 | 93 | true 94 | bin\x64\Debug\ 95 | DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP 96 | ;2008 97 | full 98 | x64 99 | false 100 | prompt 101 | true 102 | 103 | 104 | bin\x64\Release\ 105 | TRACE;NETFX_CORE;WINDOWS_UWP 106 | true 107 | ;2008 108 | pdbonly 109 | x64 110 | false 111 | prompt 112 | true 113 | true 114 | 115 | 116 | PackageReference 117 | 118 | 119 | 120 | App.xaml 121 | 122 | 123 | MainPage.xaml 124 | 125 | 126 | 127 | ResultsPage.xaml 128 | 129 | 130 | 131 | 132 | Designer 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | MSBuild:Compile 149 | Designer 150 | 151 | 152 | MSBuild:Compile 153 | Designer 154 | 155 | 156 | Designer 157 | MSBuild:Compile 158 | 159 | 160 | 161 | 162 | 6.2.11 163 | 164 | 165 | 7.0.2 166 | 167 | 168 | 169 | 170 | {784a3c01-bd0b-4db9-b1ff-2a16e2b03a65} 171 | IntelligentAPI_EmotionRecognizer 172 | 173 | 174 | {f705b499-d0b5-408c-b1d1-d3f379d0fcd6} 175 | IntelligentAPI_ImageClassifier 176 | 177 | 178 | {6f985dc2-db68-49e5-add8-6d11f35e552e} 179 | IntelligentAPI_ObjectDetector 180 | 181 | 182 | 183 | 14.0 184 | 185 | 186 | 188 | 191 | 193 | -------------------------------------------------------------------------------- /IntelligentAPIsTester/MainPage.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | 15 | 16 | 17 | Welcome to IntelligentAPIs Test Project! Pick an image to try Image Classification and Object Detection. 18 | 29 | Capture an image on your webcam to try Emotion Detection. 30 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /IntelligentAPIsTester/MainPage.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Threading.Tasks; 4 | using Windows.UI.Xaml; 5 | using Windows.UI.Xaml.Controls; 6 | using Windows.UI.Xaml.Media; 7 | using Windows.Storage.Pickers; 8 | using Windows.Storage; 9 | using Windows.Graphics.Imaging; 10 | using Windows.Storage.Streams; 11 | using Windows.UI.Xaml.Media.Imaging; 12 | using CommunityToolkit.Labs.Intelligent.ImageClassification; 13 | using CommunityToolkit.Labs.Intelligent.ObjectDetection; 14 | using Windows.UI.Xaml.Shapes; 15 | using Windows.UI; 16 | using Windows.Media.Capture; 17 | using Windows.Foundation; 18 | namespace IntelligentLabsTest 19 | { 20 | /// 21 | /// MainPage of the test project 22 | /// 23 | public sealed partial class MainPage : Page 24 | { 25 | public MainPage() 26 | { 27 | this.InitializeComponent(); 28 | 29 | } 30 | 31 | /// 32 | /// Called on click of "Pick Image" button 33 | /// 34 | /// 35 | /// 36 | private async void Button_Click(object sender, RoutedEventArgs e) 37 | { 38 | FilePickerButton.IsEnabled = false; 39 | FilePickerProgressRing.IsActive = true; 40 | FileOpenPicker fileOpenPicker = new FileOpenPicker(); 41 | fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; 42 | fileOpenPicker.FileTypeFilter.Add(".jpg"); 43 | fileOpenPicker.FileTypeFilter.Add(".png"); 44 | fileOpenPicker.ViewMode = PickerViewMode.Thumbnail; 45 | StorageFile selectedStorageFile = await fileOpenPicker.PickSingleFileAsync(); 46 | if (selectedStorageFile != null) 47 | { 48 | Frame rootFrame = Window.Current.Content as Frame; 49 | Input input = new Input() { file = selectedStorageFile, typeOfInput = TypeOfInput.File }; 50 | rootFrame.Navigate(typeof(ResultsPage), input); 51 | } 52 | else 53 | { 54 | FilePickerButton.IsEnabled = true; 55 | FilePickerProgressRing.IsActive = false; 56 | } 57 | } 58 | 59 | private async void CaptureImageButton_Click(object sender, RoutedEventArgs e) 60 | { 61 | CameraCaptureUI dialog = new CameraCaptureUI(); 62 | Size aspectRatio = new Size(16, 9); 63 | dialog.PhotoSettings.CroppedAspectRatio = aspectRatio; 64 | 65 | StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo); 66 | 67 | if(file != null) 68 | { 69 | Frame rootFrame = Window.Current.Content as Frame; 70 | Input input = new Input() { file = file, typeOfInput = TypeOfInput.Camera }; 71 | rootFrame.Navigate(typeof(ResultsPage), input); 72 | } 73 | } 74 | 75 | public enum TypeOfInput 76 | { 77 | Camera, 78 | File 79 | } 80 | 81 | public class Input 82 | { 83 | public StorageFile file; 84 | public TypeOfInput typeOfInput; 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /IntelligentAPIsTester/Package.appxmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 8 | 9 | 13 | 14 | 15 | 16 | 17 | ProjectBangaloreTest 18 | amsrin 19 | Assets\StoreLogo.png 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /IntelligentAPIsTester/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("IntelligentLabsTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("IntelligentLabsTest")] 13 | [assembly: AssemblyCopyright("Copyright © 2021")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Version information for an assembly consists of the following four values: 18 | // 19 | // Major Version 20 | // Minor Version 21 | // Build Number 22 | // Revision 23 | // 24 | // You can specify all the values or you can default the Build and Revision Numbers 25 | // by using the '*' as shown below: 26 | // [assembly: AssemblyVersion("1.0.*")] 27 | [assembly: AssemblyVersion("1.0.0.0")] 28 | [assembly: AssemblyFileVersion("1.0.0.0")] 29 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /IntelligentAPIsTester/Properties/Default.rd.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /IntelligentAPIsTester/ResultsPage.xaml: -------------------------------------------------------------------------------- 1 |  11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /IntelligentAPIsTester/ResultsPage.xaml.cs: -------------------------------------------------------------------------------- 1 |  2 | using CommunityToolkit.Labs.Intelligent.ImageClassification; 3 | using CommunityToolkit.Labs.Intelligent.ObjectDetection; 4 | using CommunityToolkit.Labs.Intelligent.EmotionRecognition; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Runtime.InteropServices.WindowsRuntime; 10 | using System.Threading.Tasks; 11 | using Windows.Foundation; 12 | using Windows.Foundation.Collections; 13 | using Windows.Graphics.Imaging; 14 | using Windows.Media.Capture; 15 | using Windows.Storage; 16 | using Windows.Storage.Streams; 17 | using Windows.System.Profile; 18 | using Windows.UI; 19 | using Windows.UI.Xaml; 20 | using Windows.UI.Xaml.Controls; 21 | using Windows.UI.Xaml.Controls.Primitives; 22 | using Windows.UI.Xaml.Data; 23 | using Windows.UI.Xaml.Input; 24 | using Windows.UI.Xaml.Media; 25 | using Windows.UI.Xaml.Media.Imaging; 26 | using Windows.UI.Xaml.Navigation; 27 | using Windows.UI.Xaml.Shapes; 28 | 29 | // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 30 | 31 | namespace IntelligentLabsTest 32 | { 33 | /// 34 | /// An empty page that can be used on its own or navigated to within a Frame. 35 | /// 36 | public sealed partial class ResultsPage : Page 37 | { 38 | /// 39 | /// Transparent fill inside bounding box 40 | /// 41 | private readonly SolidColorBrush _fill_brush = new SolidColorBrush(Colors.Transparent); 42 | 43 | /// 44 | /// Green brush for bounding box borders 45 | /// 46 | private readonly SolidColorBrush _line_brush = new SolidColorBrush(Colors.DarkGreen); 47 | 48 | /// 49 | /// Line thickness of bounding box 50 | /// 51 | private readonly double _line_thickness = 5.0; 52 | 53 | public ResultsPage() 54 | { 55 | this.InitializeComponent(); 56 | } 57 | 58 | /// 59 | /// Calls Classification and Object Detection APIs when a file is selected. 60 | /// 61 | /// 62 | protected async override void OnNavigatedTo(NavigationEventArgs e) 63 | { 64 | Frame rootFrame = Window.Current.Content as Frame; 65 | if (!(e.Parameter is MainPage.Input input)) 66 | { 67 | rootFrame.GoBack(); 68 | return; 69 | } 70 | 71 | await DisplayImage(input.file); 72 | 73 | if (input.typeOfInput.Equals(MainPage.TypeOfInput.File)) 74 | { 75 | try 76 | { 77 | //Use Squeezenet model to classify image 78 | List imageClasses = await SqueezeNetImageClassifier.ClassifyImage(input.file, 3); 79 | UpdateTextBoxForImageClassification(imageClasses); 80 | 81 | 82 | } 83 | catch (Exception exc) 84 | { 85 | 86 | if (exc is ArgumentOutOfRangeException) 87 | { 88 | ResultsBlock.Text = exc.Message; 89 | } 90 | } 91 | 92 | 93 | //Use YOLOv4 to detect objects. WORKS ONLY IF YOU ARE RUNNING WINDOWS 11!! 94 | if (CheckWindowsBuildNumber()) 95 | { 96 | List listOfObjects = await YOLOObjectDetector.DetectObjects(input.file); 97 | DrawBoxes(listOfObjects); 98 | } 99 | 100 | } 101 | else 102 | { 103 | DetectedEmotion detectedEmotion = await EmotionRecognizer.DetectEmotion(input.file); 104 | UpdateTextBoxForEmotionRecognition(detectedEmotion); 105 | 106 | } 107 | 108 | ProgressRing.IsActive = false; 109 | Dimmer.Visibility = Visibility.Collapsed; 110 | 111 | } 112 | 113 | /// 114 | /// Checks if Windows version is 11 115 | /// 116 | /// 117 | private bool CheckWindowsBuildNumber() 118 | { 119 | string deviceFamilyVersion = AnalyticsInfo.VersionInfo.DeviceFamilyVersion; 120 | ulong version = ulong.Parse(deviceFamilyVersion); 121 | ulong build = (version & 0x00000000FFFF0000L) >> 16; 122 | return build >= 22000; 123 | } 124 | 125 | /// 126 | /// Displays the image uploaded 127 | /// 128 | /// 129 | /// 130 | private async Task DisplayImage(StorageFile selectedStorageFile) 131 | { 132 | SoftwareBitmap softwareBitmap; 133 | OverlayCanvas.Children.Clear(); 134 | using (IRandomAccessStream stream = await selectedStorageFile.OpenAsync(FileAccessMode.Read)) 135 | { 136 | // Create the decoder from the stream 137 | BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); 138 | // Get the SoftwareBitmap representation of the file in BGRA8 format 139 | softwareBitmap = await decoder.GetSoftwareBitmapAsync(); 140 | softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); 141 | } 142 | // Display the image 143 | SoftwareBitmapSource imageSource = new SoftwareBitmapSource(); 144 | await imageSource.SetBitmapAsync(softwareBitmap); 145 | UIPreviewImage.Source = imageSource; 146 | } 147 | 148 | /// 149 | /// Updates the text box with results from image classification and object detection 150 | /// 151 | /// 152 | /// 153 | /// 154 | private void UpdateTextBoxForImageClassification(List imageClasses) 155 | { 156 | ResultsBlock.Text = ""; 157 | 158 | if(imageClasses.Count == 0) 159 | { 160 | ResultsBlock.Text = "No results"; 161 | return; 162 | } 163 | 164 | for (int i = 0; i < imageClasses.Count; ++i) 165 | { 166 | if (i == 0) 167 | { 168 | ResultsBlock.Text = "Image classification Results: \n"; ; 169 | } 170 | 171 | ResultsBlock.Text += imageClasses[i].category + " (" + Math.Round(imageClasses[i].confidence, 2) + ")\n"; 172 | 173 | } 174 | 175 | } 176 | 177 | /// 178 | /// Updates the text box with results from image classification and object detection 179 | /// 180 | /// 181 | /// 182 | /// 183 | private void UpdateTextBoxForEmotionRecognition(DetectedEmotion detectedEmotion) 184 | { 185 | ResultsBlock.Text = ""; 186 | 187 | if (detectedEmotion == null) 188 | { 189 | ResultsBlock.Text = "No face detected"; 190 | return; 191 | } 192 | 193 | 194 | ResultsBlock.Text += "Detected Emotion: " + detectedEmotion.emotion; 195 | 196 | } 197 | 198 | /// 199 | /// Draws bounding boxes on the output frame based on evaluation result 200 | /// 201 | private void DrawBoxes(List results) 202 | { 203 | OverlayCanvas.Height = UIPreviewImage.ActualHeight; 204 | OverlayCanvas.Width = UIPreviewImage.Width; 205 | 206 | for (int i = 0; i < results.Count; ++i) 207 | { 208 | int top = (int)(results[i].bbox[0] * UIPreviewImage.ActualHeight); 209 | int left = (int)(results[i].bbox[1] * UIPreviewImage.Width); 210 | int bottom = (int)(results[i].bbox[2] * UIPreviewImage.ActualHeight); 211 | int right = (int)(results[i].bbox[3] * UIPreviewImage.Width); 212 | 213 | var r = new Rectangle(); 214 | r.Width = right - left; 215 | r.Height = bottom - top; 216 | r.Fill = this._fill_brush; 217 | r.Stroke = this._line_brush; 218 | r.StrokeThickness = this._line_thickness; 219 | r.Margin = new Thickness(left, top, 0, 0); 220 | r.Visibility = Visibility.Visible; 221 | this.OverlayCanvas.Children.Add(r); 222 | 223 | 224 | var border = new Border(); 225 | var backgroundColorBrush = new SolidColorBrush(Colors.Black); 226 | var foregroundColorBrush = new SolidColorBrush(Colors.SpringGreen); 227 | var textBlock = new TextBlock(); 228 | textBlock.Foreground = foregroundColorBrush; 229 | textBlock.FontSize = 18; 230 | 231 | textBlock.Text = results[i].label; 232 | // Hide 233 | textBlock.Visibility = Visibility.Collapsed; 234 | border.Background = backgroundColorBrush; 235 | border.Child = textBlock; 236 | 237 | Canvas.SetLeft(border, results[i].bbox[1] * UIPreviewImage.Width + 2); 238 | Canvas.SetTop(border, results[i].bbox[0] * UIPreviewImage.ActualHeight); 239 | textBlock.Visibility = Visibility.Visible; 240 | // Add to canvas 241 | this.OverlayCanvas.Children.Add(border); 242 | } 243 | } 244 | 245 | /// 246 | /// Click event for back button 247 | /// 248 | /// 249 | /// 250 | private void BackButton_Click(object sender, RoutedEventArgs e) 251 | { 252 | Frame rootFrame = Window.Current.Content as Frame; 253 | rootFrame.GoBack(); 254 | } 255 | } 256 | } 257 | -------------------------------------------------------------------------------- /IntelligentAPIsTester/Scripts/script.ps1: -------------------------------------------------------------------------------- 1 | $ProgressPreference = 'SilentlyContinue' 2 | 3 | Invoke-WebRequest -URI "https://github.com/onnx/models/raw/master/vision/classification/squeezenet/model/squeezenet1.1-7.onnx" -OutFile "../ProjectBangalore/Assets/model.onnx" 4 | Invoke-WebRequest -URI "https://github.com/onnx/models/raw/master/vision/object_detection_segmentation/yolov4/model/yolov4.onnx" -OutFile "../ProjectYOLO/Assets/Yolo.onnx" -------------------------------------------------------------------------------- /License.md: -------------------------------------------------------------------------------- 1 | # Intelligent Labs 2 | 3 | Copyright (c) .NET Foundation and Contributors 4 | 5 | All rights reserved. 6 | 7 | # MIT License (MIT) 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 14 | -------------------------------------------------------------------------------- /ObjectDetector/Assets/Yolo.cs: -------------------------------------------------------------------------------- 1 | // This file was automatically generated by VS extension Windows Machine Learning Code Generator v3 2 | // from model file Yolo.onnx 3 | // Warning: This file may get overwritten if you add add an onnx file with the same name 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Threading.Tasks; 7 | using Windows.Media; 8 | using Windows.Storage; 9 | using Windows.Storage.Streams; 10 | using Windows.AI.MachineLearning; 11 | namespace ProjectYOLO 12 | { 13 | 14 | public sealed class YoloInput 15 | { 16 | public ImageFeatureValue input_100; // BitmapPixelFormat: Bgra8, BitmapAlphaMode: Premultiplied, width: 416, height: 416 17 | } 18 | 19 | public sealed class YoloOutput 20 | { 21 | public TensorFloat Identity00; // shape(-1,-1,-1) 22 | } 23 | 24 | public sealed class YoloModel 25 | { 26 | private LearningModel model; 27 | private LearningModelSession session; 28 | private LearningModelBinding binding; 29 | public static async Task CreateFromStreamAsync(IRandomAccessStreamReference stream) 30 | { 31 | YoloModel learningModel = new YoloModel(); 32 | learningModel.model = await LearningModel.LoadFromStreamAsync(stream); 33 | learningModel.session = new LearningModelSession(learningModel.model); 34 | learningModel.binding = new LearningModelBinding(learningModel.session); 35 | return learningModel; 36 | } 37 | public async Task EvaluateAsync(YoloInput input) 38 | { 39 | binding.Bind("input_1:0", input.input_100); 40 | var result = await session.EvaluateAsync(binding, "0"); 41 | var output = new YoloOutput(); 42 | output.Identity00 = result.Outputs["Identity:0"] as TensorFloat; 43 | return output; 44 | } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /ObjectDetector/IntelligentAPI_ObjectDetector.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | IntelligentAPI.ObjectDetection 4 | 5 | 6 | CommunityToolkit.Labs.Intelligent.ObjectDetection 7 | 8 | This package performs Object Detection on an input image by using the YOLOv4 Onnx model. 9 | 10 | 0.0.11 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /ObjectDetector/IntelligentAPI_ObjectDetector.pri: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/2ae6217be93b9df825c12dddddc5ba957604440e/ObjectDetector/IntelligentAPI_ObjectDetector.pri -------------------------------------------------------------------------------- /ObjectDetector/ObjectDetector.licenseheader: -------------------------------------------------------------------------------- 1 | extensions: designer.cs generated.cs 2 | extensions: .cs 3 | // Licensed to the .NET Foundation under one or more agreements. 4 | // The .NET Foundation licenses this file to you under the MIT license. 5 | // See the LICENSE file in the project root for more information. 6 | -------------------------------------------------------------------------------- /ObjectDetector/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System.Reflection; 6 | using System.Runtime.CompilerServices; 7 | using System.Runtime.InteropServices; 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTrademark("")] 13 | [assembly: AssemblyCulture("")] 14 | 15 | // Version information for an assembly consists of the following four values: 16 | // 17 | // Major Version 18 | // Minor Version 19 | // Build Number 20 | // Revision 21 | // 22 | // You can specify all the values or you can default the Build and Revision Numbers 23 | // by using the '*' as shown below: 24 | // [assembly: AssemblyVersion("1.0.*")] 25 | [assembly: ComVisible(false)] -------------------------------------------------------------------------------- /ObjectDetector/Properties/IntelligentAPI_ObjectDetector.rd.xml: -------------------------------------------------------------------------------- 1 | 2 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /ObjectDetector/Scripts/script.ps1: -------------------------------------------------------------------------------- 1 | $ProgressPreference = 'SilentlyContinue' 2 | 3 | $yolofile = "./Assets/Yolo.onnx" 4 | 5 | 6 | if (-not(Test-Path -Path $yolofile -PathType Leaf)) { 7 | try { 8 | Invoke-WebRequest -URI "https://github.com/microsoft/Windows-Machine-Learning/raw/master/Samples/Tutorial%20Samples/YOLOv4ObjectDetection/YOLOv4ObjectDetection/Assets/Yolo.onnx" -OutFile $yolofile 9 | Write-Host "The file [$yolofile] has been created." 10 | } 11 | catch { 12 | throw $_.Exception.Message 13 | } 14 | } 15 | else { 16 | Write-Host "The file [$yolofile] exists." 17 | } 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /ObjectDetector/YOLOObjectDetector.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Diagnostics; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using Windows.AI.MachineLearning; 12 | using Windows.Graphics.Imaging; 13 | using Windows.Media; 14 | using Windows.Storage; 15 | using Windows.Storage.Streams; 16 | using Windows.UI.Xaml.Media.Imaging; 17 | 18 | namespace CommunityToolkit.Labs.Intelligent.ObjectDetection 19 | { 20 | /// 21 | /// YOLOObjectDetector is used to perform object detection using the YOLOv4 model. 22 | /// 23 | public class YOLOObjectDetector 24 | { 25 | /// 26 | /// LearningModel instance 27 | /// 28 | private LearningModel _model = null; 29 | 30 | /// 31 | /// LearningModelSession instance 32 | /// 33 | private LearningModelSession _session; 34 | 35 | /// 36 | /// LearningModelBinding instance 37 | /// 38 | private LearningModelBinding _binding; 39 | 40 | /// 41 | /// YOLOObjectDetector instance 42 | /// 43 | private static YOLOObjectDetector instance; 44 | 45 | /// 46 | /// List of labels 47 | /// 48 | private readonly string[] _labels = 49 | { 50 | "person", 51 | "bicycle", 52 | "car", 53 | "motorbike", 54 | "aeroplane", 55 | "bus", 56 | "train", 57 | "truck", 58 | "boat", 59 | "traffic light", 60 | "fire hydrant", 61 | "stop sign", 62 | "parking meter", 63 | "bench", 64 | "bird", 65 | "cat", 66 | "dog", 67 | "horse", 68 | "sheep", 69 | "cow", 70 | "elephant", 71 | "bear", 72 | "zebra", 73 | "giraffe", 74 | "backpack", 75 | "umbrella", 76 | "handbag", 77 | "tie", 78 | "suitcase", 79 | "frisbee", 80 | "skis", 81 | "snowboard", 82 | "sports ball", 83 | "kite", 84 | "baseball bat", 85 | "baseball glove", 86 | "skateboard", 87 | "surfboard", 88 | "tennis racket", 89 | "bottle", 90 | "wine glass", 91 | "cup", 92 | "fork", 93 | "knife", 94 | "spoon", 95 | "bowl", 96 | "banana", 97 | "apple", 98 | "sandwich", 99 | "orange", 100 | "broccoli", 101 | "carrot", 102 | "hot dog", 103 | "pizza", 104 | "donut", 105 | "cake", 106 | "chair", 107 | "sofa", 108 | "pottedplant", 109 | "bed", 110 | "diningtable", 111 | "toilet", 112 | "tvmonitor", 113 | "laptop", 114 | "mouse", 115 | "remote", 116 | "keyboard", 117 | "cell phone", 118 | "microwave", 119 | "oven", 120 | "toaster", 121 | "sink", 122 | "refrigerator", 123 | "book", 124 | "clock", 125 | "vase", 126 | "scissors", 127 | "teddy bear", 128 | "hair drier", 129 | "toothbrush" 130 | }; 131 | 132 | private YOLOObjectDetector() 133 | { 134 | 135 | } 136 | 137 | /// 138 | /// Detects objects in a StorageFile input 139 | /// 140 | /// 141 | /// 142 | public static async Task> DetectObjects(StorageFile file) 143 | { 144 | SoftwareBitmap bitmap = await GenerateSoftwareBitmapFromStorageFile(file); 145 | VideoFrame videoFrame = await GenerateVideoFrameFromBitmap(bitmap); 146 | return await DetectObjects(videoFrame); 147 | } 148 | 149 | 150 | /// 151 | /// Detects Objects in a SoftwareBitmap input 152 | /// 153 | /// 154 | /// 155 | public static async Task> DetectObjects(SoftwareBitmap bitmap) 156 | { 157 | VideoFrame videoFrame = await GenerateVideoFrameFromBitmap(bitmap); 158 | return await DetectObjects(videoFrame); 159 | } 160 | 161 | /// 162 | /// Detects objects in a VideoFrame input 163 | /// 164 | /// 165 | /// 166 | public static async Task> DetectObjects(VideoFrame videoFrame) 167 | { 168 | if (instance == null) 169 | { 170 | instance = new YOLOObjectDetector(); 171 | } 172 | 173 | return await instance.EvaluateFrame(videoFrame); 174 | } 175 | 176 | /// 177 | /// Load YOLOv4 model, creates LearningModelSession and LearningModelBinding instances 178 | /// 179 | /// 180 | private async Task InitModelAsync() 181 | { 182 | if(_model != null) 183 | { 184 | return; 185 | } 186 | try 187 | { 188 | var model_file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///IntelligentAPI_ObjectDetector/Assets//Yolo.onnx")); 189 | _model = await LearningModel.LoadFromStorageFileAsync(model_file); 190 | var device = new LearningModelDevice(LearningModelDeviceKind.Default); 191 | _session = new LearningModelSession(_model, device); 192 | _binding = new LearningModelBinding(_session); 193 | } 194 | catch (Exception ex) 195 | { 196 | _model = null; 197 | throw ex; 198 | } 199 | } 200 | 201 | /// 202 | /// Evaluate YOLOv4 model to detect objects in a single VideoFrame 203 | /// 204 | /// 205 | /// 206 | public async Task> EvaluateFrame(VideoFrame inputImage) 207 | { 208 | await InitModelAsync(); 209 | SoftwareBitmap bitmap = inputImage.SoftwareBitmap; 210 | inputImage = await ResizeImage(inputImage, bitmap); 211 | _binding.Clear(); 212 | _binding.Bind("input_1:0", inputImage); 213 | var results = await _session.EvaluateAsync(_binding, ""); 214 | 215 | TensorFloat result = results.Outputs["Identity:0"] as TensorFloat; 216 | var data = result.GetAsVectorView(); 217 | 218 | List detections = ParseResult(data.ToList().ToArray()); 219 | Comparer cp = new Comparer(); 220 | detections.Sort(cp); 221 | List final_detections = NMS(detections); 222 | 223 | return final_detections; 224 | } 225 | 226 | /// 227 | /// Helper function to resize image 228 | /// 229 | /// 230 | /// 231 | /// 232 | private static async Task ResizeImage(VideoFrame inputImage, SoftwareBitmap bitmap) 233 | { 234 | using (InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream()) 235 | { 236 | BitmapEncoder encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, stream); 237 | 238 | encoder.SetSoftwareBitmap(bitmap); 239 | 240 | encoder.BitmapTransform.ScaledWidth = 416; 241 | encoder.BitmapTransform.ScaledHeight = 416; 242 | encoder.BitmapTransform.InterpolationMode = BitmapInterpolationMode.NearestNeighbor; 243 | 244 | await encoder.FlushAsync(); 245 | 246 | BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); 247 | 248 | SoftwareBitmap newBitmap = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, bitmap.BitmapAlphaMode); 249 | inputImage = VideoFrame.CreateWithSoftwareBitmap(newBitmap); 250 | } 251 | 252 | return inputImage; 253 | } 254 | 255 | /// 256 | /// Helper function to generate VideoFrame from SoftwareBitmap 257 | /// 258 | /// 259 | /// 260 | private static async Task GenerateVideoFrameFromBitmap(SoftwareBitmap softwareBitmap) 261 | { 262 | softwareBitmap = GetSoftwareBitmap(softwareBitmap); 263 | 264 | // Encapsulate the image within a VideoFrame to be bound and evaluated 265 | VideoFrame videoFrame = VideoFrame.CreateWithSoftwareBitmap(softwareBitmap); 266 | return videoFrame; 267 | } 268 | 269 | /// 270 | /// Get Software Bitmap 271 | /// 272 | /// 273 | /// 274 | private static SoftwareBitmap GetSoftwareBitmap(SoftwareBitmap softwareBitmap) 275 | { 276 | if (softwareBitmap.BitmapPixelFormat != BitmapPixelFormat.Bgra8 || (softwareBitmap.BitmapAlphaMode != BitmapAlphaMode.Ignore && softwareBitmap.BitmapAlphaMode != BitmapAlphaMode.Premultiplied)) 277 | { 278 | softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied); 279 | } 280 | return softwareBitmap; 281 | } 282 | 283 | /// 284 | /// Helper function to generate SoftwareBitmap from StorageFile 285 | /// 286 | /// 287 | /// 288 | private static async Task GenerateSoftwareBitmapFromStorageFile(StorageFile selectedStorageFile) 289 | { 290 | SoftwareBitmap softwareBitmap; 291 | using (IRandomAccessStream stream = await selectedStorageFile.OpenAsync(FileAccessMode.Read)) 292 | { 293 | // Create the decoder from the stream 294 | BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream); 295 | 296 | // Get the SoftwareBitmap representation of the file in BGRA8 format 297 | softwareBitmap = await decoder.GetSoftwareBitmapAsync(); 298 | softwareBitmap = GetSoftwareBitmap(softwareBitmap); 299 | } 300 | 301 | return softwareBitmap; 302 | } 303 | 304 | /// 305 | /// Compare function 306 | /// 307 | class Comparer : IComparer 308 | { 309 | public int Compare(DetectionResult x, DetectionResult y) 310 | { 311 | return y.prob.CompareTo(x.prob); 312 | } 313 | } 314 | 315 | /// 316 | /// Compute intersection over union 317 | /// 318 | /// 319 | /// 320 | /// 321 | private float ComputeIOU(DetectionResult DRa, DetectionResult DRb) 322 | { 323 | float ay1 = DRa.bbox[0]; 324 | float ax1 = DRa.bbox[1]; 325 | float ay2 = DRa.bbox[2]; 326 | float ax2 = DRa.bbox[3]; 327 | float by1 = DRb.bbox[0]; 328 | float bx1 = DRb.bbox[1]; 329 | float by2 = DRb.bbox[2]; 330 | float bx2 = DRb.bbox[3]; 331 | 332 | Debug.Assert(ay1 < ay2); 333 | Debug.Assert(ax1 < ax2); 334 | Debug.Assert(by1 < by2); 335 | Debug.Assert(bx1 < bx2); 336 | 337 | // determine the coordinates of the intersection rectangle 338 | float x_left = Math.Max(ax1, bx1); 339 | float y_top = Math.Max(ay1, by1); 340 | float x_right = Math.Min(ax2, bx2); 341 | float y_bottom = Math.Min(ay2, by2); 342 | 343 | if (x_right < x_left || y_bottom < y_top) 344 | return 0; 345 | float intersection_area = (x_right - x_left) * (y_bottom - y_top); 346 | float bb1_area = (ax2 - ax1) * (ay2 - ay1); 347 | float bb2_area = (bx2 - bx1) * (by2 - by1); 348 | float iou = intersection_area / (bb1_area + bb2_area - intersection_area); 349 | 350 | Debug.Assert(iou >= 0 && iou <= 1); 351 | return iou; 352 | } 353 | 354 | // Non-maximum Suppression(NMS), a technique which filters the proposals 355 | // based on Intersection over Union(IOU) 356 | private List NMS(IReadOnlyList detections, 357 | float IOU_threshold = 0.45f, 358 | float score_threshold = 0.3f) 359 | { 360 | List final_detections = new List(); 361 | for (int i = 0; i < detections.Count; i++) 362 | { 363 | int j = 0; 364 | for (j = 0; j < final_detections.Count; j++) 365 | { 366 | if (ComputeIOU(final_detections[j], detections[i]) > IOU_threshold) 367 | { 368 | break; 369 | } 370 | } 371 | if (j == final_detections.Count) 372 | { 373 | final_detections.Add(detections[i]); 374 | } 375 | } 376 | return final_detections; 377 | } 378 | 379 | /// 380 | /// Parse the result from WinML evaluation results to self defined object struct 381 | /// 382 | /// 383 | /// 384 | private List ParseResult(float[] results) 385 | { 386 | int c_values = 84; 387 | int c_boxes = results.Length / c_values; 388 | float confidence_threshold = 0.5f; 389 | List detections = new List(); 390 | for (int i_box = 0; i_box < c_boxes; i_box++) 391 | { 392 | float max_prob = 0.0f; 393 | int label_index = -1; 394 | for (int j_confidence = 4; j_confidence < c_values; j_confidence++) 395 | { 396 | int index = i_box * c_values + j_confidence; 397 | if (results[index] > max_prob) 398 | { 399 | max_prob = results[index]; 400 | label_index = j_confidence - 4; 401 | } 402 | } 403 | if (max_prob > confidence_threshold) 404 | { 405 | List bbox = new List(); 406 | bbox.Add(results[i_box * c_values + 0]); 407 | bbox.Add(results[i_box * c_values + 1]); 408 | bbox.Add(results[i_box * c_values + 2]); 409 | bbox.Add(results[i_box * c_values + 3]); 410 | 411 | detections.Add(new DetectionResult() 412 | { 413 | label = _labels[label_index], 414 | bbox = bbox, 415 | prob = max_prob 416 | }); 417 | } 418 | } 419 | return detections; 420 | } 421 | 422 | } 423 | 424 | /// 425 | /// Detection result struct that contains the label, probability and bounding box co-ordinates of a detected object. 426 | /// 427 | public class DetectionResult 428 | { 429 | public string label; 430 | public List bbox; 431 | public double prob; 432 | } 433 | } 434 | -------------------------------------------------------------------------------- /ObjectDetector/Yolo.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | // See the LICENSE file in the project root for more information. 4 | 5 | // This file was automatically generated by VS extension Windows Machine Learning Code Generator v3 6 | // from model file Yolo.onnx 7 | // Warning: This file may get overwritten if you add add an onnx file with the same name 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Threading.Tasks; 11 | using Windows.Media; 12 | using Windows.Storage; 13 | using Windows.Storage.Streams; 14 | using Windows.AI.MachineLearning; 15 | namespace CommunityToolkit.Labs.Intelligent.ObjectDetection 16 | { 17 | /// 18 | /// Input for the YOLOv4 model 19 | /// 20 | public sealed class YoloInput 21 | { 22 | public ImageFeatureValue input_100; // BitmapPixelFormat: Bgra8, BitmapAlphaMode: Premultiplied, width: 416, height: 416 23 | } 24 | 25 | 26 | /// 27 | /// Output of the YOLOv4 model 28 | /// 29 | public sealed class YoloOutput 30 | { 31 | public TensorFloat Identity00; // shape(-1,-1,-1) 32 | } 33 | 34 | 35 | /// 36 | /// YOLOv4 Model 37 | /// 38 | public sealed class YoloModel 39 | { 40 | 41 | /// 42 | /// LearningModel instance for the trained YOLOv4 model 43 | /// 44 | private LearningModel model; 45 | 46 | /// 47 | /// LearningModelSession instance that will be used to evaluate the model 48 | /// 49 | private LearningModelSession session; 50 | 51 | /// 52 | /// Bindings that will bind values to named input and output features. 53 | /// 54 | private LearningModelBinding binding; 55 | 56 | /// 57 | /// Loads the model, creates a session and binding. 58 | /// 59 | /// 60 | /// 61 | public static async Task CreateFromStreamAsync(IRandomAccessStreamReference stream) 62 | { 63 | YoloModel learningModel = new YoloModel(); 64 | learningModel.model = await LearningModel.LoadFromStreamAsync(stream); 65 | learningModel.session = new LearningModelSession(learningModel.model); 66 | learningModel.binding = new LearningModelBinding(learningModel.session); 67 | return learningModel; 68 | } 69 | 70 | /// 71 | /// Asynchronously evaluate YOLOv4 model 72 | /// 73 | /// 74 | /// 75 | public async Task EvaluateAsync(YoloInput input) 76 | { 77 | binding.Bind("input_1:0", input.input_100); 78 | var result = await session.EvaluateAsync(binding, "0"); 79 | var output = new YoloOutput(); 80 | output.Identity00 = result.Outputs["Identity:0"] as TensorFloat; 81 | return output; 82 | } 83 | 84 | } 85 | } 86 | 87 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | Intelligent APIs 3 |

4 | 5 | ## What are Intelligent APIs? 6 | 7 | Intelligent APIs aim to make machine learning tasks easier for developers to leverage in their applications without needing ML expertise or creating a new model. 8 | By just importing a nuget package and calling a function, we want developers to be able to build intelligent app experiences without needing to deal with the complexities of inferencing machine learning models on Windows. 9 | 10 | Each of these APIs employs WinML (Windows Machine Learning) to use the models on Windows. WinML helps abstract a lot of the model-specific code away and performs hardware optimizations to improve performance significantly on Windows. Learn more about WinML [here](https://docs.microsoft.com/en-us/windows/ai/windows-ml/). 11 | 12 | ## Pre-requisites 13 | 14 | [Visual Studio 2017 Version 15.7.4 or Newer](https://developer.microsoft.com/en-us/windows/downloads/) 15 | 16 | [Windows 10 - Build 17763 (RS5) or Newer](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewiso) 17 | 18 | [Windows SDK - Build 17763 (RS5) or Newer](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewSDK) 19 | 20 | ## Getting started with the nuget packages 21 | 22 | We have 2 nuget packages ready for you to test and play around with. These nuget packages enable you to perform classic machine learning tasks like image classification and object detection in 1-2 lines of code. 23 | 24 | ## Steps to import the nuget package into your project: 25 | 26 | 1. Add a new nuget source with the feed URL as `https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-Labs/nuget/v3/index.json`. If you have not done this before, follow the steps listed [here](https://docs.microsoft.com/en-us/azure/devops/artifacts/nuget/consume?view=azure-devops&tabs=windows#2-set-up-visual-studio) to add a new nuget package source. Name the source as "WCT Labs" and set the URL as `https://pkgs.dev.azure.com/dotnet/CommunityToolkit/_packaging/CommunityToolkit-Labs/nuget/v3/index.json`. 27 | 2. Open a blank UWP app or an existing app and add one or both packages from the newly created source. Follow step 3 [here](https://docs.microsoft.com/en-us/azure/devops/artifacts/nuget/consume?view=azure-devops&tabs=windows#3-consume-packages) to do so. 28 | 3. There should be two nuget packages listed, `CommunityToolkit.Labs.Intelligent.ImageClassification` and `CommunityToolkit.Labs.Intelligent.ObjectDetection`. 29 | 30 | ## Using the packages 31 | 32 | ### Image Classification 33 | To perform image classification, import the `CommunityToolkit.Labs.Intelligent.ImageClassification` nuget package. To classify an image, you will need to pass a StorageFile object which is the image file itself, and the number of top results that you want (optional). In the following example, we pass an image of a Rottweiler and we want the top 3 results. 34 | 35 | ```C# 36 | using CommunityToolkit.Labs.Intelligent.ImageClassification; 37 | ... 38 | List imageClasses = await SqueezeNetImageClassifier.ClassifyImage(selectedStorageFile, 3); 39 | ``` 40 |
41 | drawing 42 |
43 | 44 | 45 | This nuget package performs [SqueezeNet](https://github.com/onnx/models/tree/master/vision/classification/squeezenet) model inferencing using [WinML](https://github.com/microsoft/Windows-Machine-Learning). SqueezeNet can detect [1000 different classes](https://github.com/onnx/models/blob/master/vision/classification/synset.txt). 46 | 47 | ### Object Detection 48 | (Note: This currently only works with Windows 11. We are looking into this [issue](https://github.com/CommunityToolkit/Labs-IntelligentAPIs/issues/3)) 49 | 50 | To perform object detection on your images/video, import the `CommunityToolkit.Labs.Intelligent.ObjectDetection` nuget package. To detect objects in the image, you can either pass an image file as a StorageFile object, VideoFrame or SoftwareBitmap. 51 | 52 | ```C# 53 | using CommunityToolkit.Labs.Intelligent.ObjectDetection; 54 | ... 55 | List listOfObjects = await YOLOObjectDetector.DetectObjects(selectedStorageFile); 56 | ``` 57 | 58 | This nuget package performs object detection using [YOLOv4](https://github.com/hunglc007/tensorflow-yolov4-tflite) model inference on WinML and also return the co-ordinates of the bounding boxes around the detected objects. YOLOv4 can detect objects of [80 different classes](https://github.com/hunglc007/tensorflow-yolov4-tflite/blob/9f16748aa3f45ff240608da4bd9b1216a29127f5/android/app/src/main/assets/coco.txt). 59 |
60 | drawing 61 |
62 | 63 | ## NEW!!! Emotion Recognition 64 | To perform emotion recognition, import the `CommunityToolkit.Labs.Intelligent.EmotionRecognition` nuget package. To detect emotion in an image, you can either pass a StorageFile object or a SoftwareBitmap of the image. 65 | 66 | ```C# 67 | using CommunityToolkit.Labs.Intelligent.EmotionRecognition; 68 | ... 69 | DetectedEmotion detectedEmotion = await EmotionRecognizer.DetectEmotion(selectedStorageFile); 70 | ``` 71 |
72 | image 73 |
74 | 75 | ## 🧪 This project is under Community Toolkit Labs. What does that mean? 76 | 77 | [Community Toolkit Labs](https://aka.ms/toolkit/wiki/labs) is a place for rapidly prototyping ideas and gathering community feedback. It is an incubation space where the developer community can come together to work on new ideas before thinking about final quality gates and ship cycles. Developers can focus on the scenarios and usage of their features before finalizing docs, samples, and tests required to ship a complete idea within the Toolkit. 78 | 79 | 80 | ## Steps to clone the repo 81 | 82 | 1. `git clone` the repo 83 | 3. Open the .sln file in VS 2017 or newer 84 | 4. Set `IntelligentLabsTest` as the startup project. 85 | 5. Build the project and run! 86 | 87 | Note: If you have the Windows machine learning code generator or [mlgen](https://marketplace.visualstudio.com/items?itemName=WinML.mlgen) extension on VS, please disable it for this project since all the code is already generated for you. 88 | 89 | -------------------------------------------------------------------------------- /ThirdPartyNotices.txt: -------------------------------------------------------------------------------- 1 | Intelligent-APIs 2 | 3 | THIRD-PARTY SOFTWARE NOTICES AND INFORMATION 4 | Do Not Translate or Localize 5 | 6 | This project incorporates components from the projects listed below. The original copyright notices and the licenses under which the .NET Foundation received such components are set forth below. The .NET Foundation reserves all rights not expressly granted herein, whether by implication, estoppel or otherwise. 7 | 8 | 1. SqueezeNet ONNX model (https://github.com/microsoft/Windows-Machine-Learning/blob/master/Samples/SqueezeNetObjectDetection/UWP/cs/Assets/model.onnx) included in ImageClassifier/Assets as model.onnx. 9 | 2. YOLOV4 ONNX model (https://github.com/microsoft/Windows-Machine-Learning/blob/master/Samples/Tutorial%20Samples/YOLOv4ObjectDetection/YOLOv4ObjectDetection/Assets/Yolo.onnx) included in ObjectDetector/Assets as yolo.onnx 10 | 1. Emotion FerPlus ONNX model (https://github.com/onnx/models/tree/master/vision/body_analysis/emotion_ferplus) included in EmotionRecognizer/Assets as model_emotion.onnx. 11 | 3. microsoft/Windows-Machine-Learning commit eb8b8be from which some of the pre-processing and post-processing functions for object detection were used. 12 | 4. microsoft/Windows-Machine-Learning commit 593575a from which some of the pre-processing and post-processing functions for image classification were used. 13 | 5. nmetulev/AlarmML commit 03f7ec0 from which some of the pre-processing and post-processing functions for emotion recognition were used. 14 | %% microsoft/Windows-Machine-Learning NOTICES AND INFORMATION BEGIN HERE 15 | ========================================= 16 | MIT License 17 | 18 | Copyright (c) Microsoft Corporation. All rights reserved. 19 | 20 | Permission is hereby granted, free of charge, to any person obtaining a copy 21 | of this software and associated documentation files (the "Software"), to deal 22 | in the Software without restriction, including without limitation the rights 23 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 24 | copies of the Software, and to permit persons to whom the Software is 25 | furnished to do so, subject to the following conditions: 26 | 27 | The above copyright notice and this permission notice shall be included in 28 | all copies or substantial portions of the Software. 29 | 30 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 31 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 32 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 33 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 34 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 35 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 36 | THE SOFTWARE. 37 | ========================================= 38 | END OF microsoft/Windows-Machine-Learning NOTICES AND INFORMATION -------------------------------------------------------------------------------- /Windows.Toolkit.Common.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | .NET Foundation 5 | Microsoft.Toolkit 6 | Community Toolkit Labs 7 | Windows;Community;Toolkit;WCT 8 | MIT 9 | true 10 | (c) .NET Foundation and Contributors. All rights reserved. 11 | https://github.com/CommunityToolkit/Labs-IntelligentAPIs 12 | https://github.com/CommunityToolkit/Labs-IntelligentAPIs/releases 13 | Icon.png 14 | https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/main/nuget.png 15 | 16 | 17 | 18 | Strict 19 | Disable 20 | Latest 21 | en-US 22 | true 23 | 24 | 25 | 26 | true 27 | true 28 | true 29 | 30 | 31 | -------------------------------------------------------------------------------- /global.json: -------------------------------------------------------------------------------- 1 | { 2 | "msbuild-sdks": 3 | { 4 | "MSBuild.Sdk.Extras":"3.0.23" 5 | } 6 | } -------------------------------------------------------------------------------- /nuget.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CommunityToolkit/Labs-IntelligentAPIs/2ae6217be93b9df825c12dddddc5ba957604440e/nuget.png --------------------------------------------------------------------------------