Skip to content

Commit

Permalink
Merge pull request #64 from microsoft/zteutsch/qnn-image-models
Browse files Browse the repository at this point in the history
Added 4 more NPU QNN image models
  • Loading branch information
nmetulev authored Dec 19, 2024
2 parents 012dd7f + f7dcdef commit 3bb7f8d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
"Description": "SqueezeNet 1.1",
"HardwareAccelerator": [
"CPU",
"DML"
"DML",
"QNN"
],
"SupportedOnQualcomm": true,
"Size": 4956208,
Expand Down Expand Up @@ -155,7 +156,8 @@
"Description": "ESRGAN",
"HardwareAccelerator": [
"CPU",
"DML"
"DML",
"QNN"
],
"SupportedOnQualcomm": true,
"Size": 67162397,
Expand All @@ -177,7 +179,8 @@
"Description": "FFNet 78s",
"HardwareAccelerator": [
"CPU",
"DML"
"DML",
"QNN"
],
"SupportedOnQualcomm": true,
"Size": 109974166,
Expand All @@ -190,7 +193,8 @@
"Description": "FFNet 54s",
"HardwareAccelerator": [
"CPU",
"DML"
"DML",
"QNN"
],
"SupportedOnQualcomm": true,
"Size": 72188137,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ private Task InitModel(string modelPath, HardwareAccelerator hardwareAccelerator
{
sessionOptions.AppendExecutionProvider_DML(DeviceUtils.GetBestDeviceId());
}
else if (hardwareAccelerator == HardwareAccelerator.QNN)
{
Dictionary<string, string> options = new()
{
{ "backend_path", "QnnHtp.dll" },
{ "htp_performance_mode", "high_performance" },
{ "htp_graph_finalization_optimization_mode", "3" }
};
sessionOptions.AppendExecutionProvider("QNN", options);
}

_inferenceSession = new InferenceSession(modelPath, sessionOptions);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ private Task InitModel(string modelPath, HardwareAccelerator hardwareAccelerator
{
sessionOptions.AppendExecutionProvider_DML(DeviceUtils.GetBestDeviceId());
}
else if (hardwareAccelerator == HardwareAccelerator.QNN)
{
Dictionary<string, string> options = new()
{
{ "backend_path", "QnnHtp.dll" },
{ "htp_performance_mode", "high_performance" },
{ "htp_graph_finalization_optimization_mode", "3" }
};
sessionOptions.AppendExecutionProvider("QNN", options);
}

_inferenceSession = new InferenceSession(modelPath, sessionOptions);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using AIDevGallery.Models;
using AIDevGallery.Samples.Attributes;
using AIDevGallery.Samples.SharedCode;
using AIDevGallery.Utils;
using Microsoft.ML.OnnxRuntime;
using Microsoft.ML.OnnxRuntime.Tensors;
using Microsoft.UI.Xaml;
Expand Down Expand Up @@ -48,7 +49,8 @@ public ImageClassification()

protected override async Task LoadModelAsync(SampleNavigationParameters sampleParams)
{
await InitModel(sampleParams.ModelPath);
var hardwareAccelerator = sampleParams.HardwareAccelerator;
await InitModel(sampleParams.ModelPath, hardwareAccelerator);
sampleParams.NotifyCompletion();

await ClassifyImage(Path.Join(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "Assets", "team.jpg"));
Expand All @@ -61,7 +63,7 @@ private void Page_Loaded()
}

// </exclude>
private Task InitModel(string modelPath)
private Task InitModel(string modelPath, HardwareAccelerator hardwareAccelerator)
{
return Task.Run(() =>
{
Expand All @@ -72,6 +74,20 @@ private Task InitModel(string modelPath)

SessionOptions sessionOptions = new();
sessionOptions.RegisterOrtExtensions();
if (hardwareAccelerator == HardwareAccelerator.DML)
{
sessionOptions.AppendExecutionProvider_DML(DeviceUtils.GetBestDeviceId());
}
else if (hardwareAccelerator == HardwareAccelerator.QNN)
{
Dictionary<string, string> options = new()
{
{ "backend_path", "QnnHtp.dll" },
{ "htp_performance_mode", "high_performance" },
{ "htp_graph_finalization_optimization_mode", "3" }
};
sessionOptions.AppendExecutionProvider("QNN", options);
}

_inferenceSession = new InferenceSession(modelPath, sessionOptions);
});
Expand Down

0 comments on commit 3bb7f8d

Please sign in to comment.