|
1 | 1 | #include "pch.h" |
2 | 2 | #include "StyleTransferEffect.h" |
3 | 3 | #include "StyleTransferEffect.g.cpp" |
4 | | - |
| 4 | +using namespace std; |
| 5 | +using namespace winrt::Windows::Storage; |
| 6 | +using namespace winrt::Windows::Storage::Streams; |
5 | 7 |
|
6 | 8 | namespace winrt::StyleTransferEffectCpp::implementation |
7 | 9 | { |
@@ -56,22 +58,25 @@ namespace winrt::StyleTransferEffectCpp::implementation |
56 | 58 |
|
57 | 59 | void StyleTransferEffect::SetProperties(IPropertySet config) { |
58 | 60 | this->configuration = config; |
59 | | - |
60 | | - IInspectable val = configuration.TryLookup(L"Session"); |
61 | | - if (val) { |
62 | | - Session = val.try_as<LearningModelSession>(); |
63 | | - } |
64 | | - val = configuration.TryLookup(L"Binding"); |
65 | | - if (val) { |
66 | | - Binding = val.try_as<LearningModelBinding>(); |
67 | | - } |
68 | | - val = configuration.TryLookup(L"InputImageDescription"); |
69 | | - if (val) { |
70 | | - InputImageDescription = unbox_value<hstring>(val); |
71 | | - } |
72 | | - val = configuration.TryLookup(L"OutputImageDescription"); |
73 | | - if (val) { |
74 | | - OutputImageDescription = unbox_value<hstring>(val); |
| 61 | + hstring modelName; |
| 62 | + IInspectable val = config.TryLookup(L"ModelName"); |
| 63 | + if (!val) { |
| 64 | + return; |
75 | 65 | } |
| 66 | + modelName = unbox_value<hstring>(val); |
| 67 | + val = configuration.TryLookup(L"UseGPU"); |
| 68 | + bool useGpu = unbox_value<bool>(val); |
| 69 | + OutputDebugString(modelName.c_str()); |
| 70 | + //std::wstring fullModelName(L"ms-appx:///Assets/"); |
| 71 | + //fullModelName += modelName + L".onnx"; |
| 72 | + //OutputDebugString(fullModelName.c_str()); |
| 73 | + LearningModel m_model = LearningModel::LoadFromFilePath(modelName); |
| 74 | + |
| 75 | + LearningModelDeviceKind m_device = useGpu ? LearningModelDeviceKind::DirectX : LearningModelDeviceKind::Cpu; |
| 76 | + Session = LearningModelSession{ m_model, LearningModelDevice(m_device) }; |
| 77 | + Binding = LearningModelBinding{ Session }; |
| 78 | + |
| 79 | + InputImageDescription = L"inputImage"; |
| 80 | + OutputImageDescription = L"outputImage"; |
76 | 81 | } |
77 | 82 | } |
0 commit comments