Skip to content

Commit 44e3269

Browse files
apply shareLib to custom-operator-sample
1 parent 26a0ad9 commit 44e3269

File tree

3 files changed

+13
-68
lines changed

3 files changed

+13
-68
lines changed

Samples/CustomOperator/desktop/cpp/custom-operator-sample.vcxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,23 @@
234234
</ImportGroup>
235235
<ItemDefinitionGroup>
236236
<ClCompile>
237-
<AdditionalIncludeDirectories>$(SolutionDir)\packages\rapidjson.v110.1.1.0\build\native\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
237+
<AdditionalIncludeDirectories>$(SolutionDir)\packages\rapidjson.v110.1.1.0\build\native\include\;..\..\..\SampleSharedLib\SampleSharedLib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
238238
</ClCompile>
239239
<ResourceCompile>
240240
<AdditionalIncludeDirectories>$(SolutionDir)\packages\rapidjson.v110.1.1.0\build\native\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
241241
</ResourceCompile>
242242
<Link>
243-
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
243+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;..\..\..\SampleSharedLib\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
244244
</Link>
245245
<Link>
246-
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
246+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;..\..\..\SampleSharedLib\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
247247
</Link>
248248
<Link>
249-
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
249+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;..\..\..\SampleSharedLib\x64\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
250250
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
251251
</Link>
252252
<Link>
253-
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
253+
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|x64'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;..\..\..\SampleSharedLib\x64\$(Configuration)\SampleSharedLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
254254
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">ole32.lib;kernel32.lib;user32.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
255255
</Link>
256256
</ItemDefinitionGroup>

Samples/CustomOperator/desktop/cpp/main.cpp

Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "pch.h"
2-
2+
#include "FileHelper.h"
33
#include "operators/customoperatorprovider.h"
44

55
using namespace winrt;
@@ -11,15 +11,6 @@ using namespace winrt::Windows::Storage;
1111
using namespace winrt::Windows::AI::MachineLearning;
1212
using namespace std;
1313

14-
wstring GetModulePath() {
15-
wchar_t wzModuleFilePath[MAX_PATH + 1];
16-
GetModuleFileName(NULL, wzModuleFilePath, MAX_PATH + 1);
17-
wstring moduleFilePath(wzModuleFilePath);
18-
return wstring(
19-
moduleFilePath.begin(),
20-
moduleFilePath.begin() + moduleFilePath.find_last_of(L"\\"));;
21-
}
22-
2314
struct CommandLineInterpreter
2415
{
2516
vector<wstring> m_commandLineArgs;
@@ -32,7 +23,7 @@ struct CommandLineInterpreter
3223
{
3324
wchar_t wzModuleFilePath[MAX_PATH + 1];
3425
GetModuleFileName(NULL, wzModuleFilePath, MAX_PATH + 1);
35-
return GetModulePath() + L"\\" + pName;
26+
return FileHelper::GetModulePath() + L"\\" + pName;
3627
}
3728

3829
wstring TryGetModelPath()
@@ -90,59 +81,13 @@ using Session = LearningModelSession;
9081
using Kind = LearningModelDeviceKind;
9182
vector<string> labels;
9283

93-
void LoadLabels()
94-
{
95-
wstring labelsFileName = L"labels.txt";
96-
97-
// Parse labels from labels file. We know the file's entries are already sorted in order.
98-
wstring labelsFilePath = GetModulePath() + L"\\" + labelsFileName;
99-
ifstream labelFile(labelsFilePath, ifstream::in);
100-
if (labelFile.fail())
101-
{
102-
printf("failed to load the %ls file. Make sure it exists in the same folder as the app\r\n", labelsFileName.c_str());
103-
exit(EXIT_FAILURE);
104-
}
105-
string s;
106-
while (getline(labelFile, s, ','))
107-
{
108-
int labelValue = atoi(s.c_str());
109-
if (static_cast<size_t>(labelValue) >= labels.size())
110-
{
111-
labels.resize(labelValue + 1);
112-
}
113-
getline(labelFile, s);
114-
labels[labelValue] = s;
115-
}
116-
}
117-
118-
VideoFrame LoadImageFile(hstring filePath)
119-
{
120-
try
121-
{
122-
// open the file
123-
StorageFile file = StorageFile::GetFileFromPathAsync(filePath).get();
124-
// get a stream on it
125-
auto stream = file.OpenAsync(FileAccessMode::Read).get();
126-
// Create the decoder from the stream
127-
BitmapDecoder decoder = BitmapDecoder::CreateAsync(stream).get();
128-
// get the bitmap
129-
SoftwareBitmap softwareBitmap = decoder.GetSoftwareBitmapAsync().get();
130-
// load a videoframe from it
131-
VideoFrame inputImage = VideoFrame::CreateWithSoftwareBitmap(softwareBitmap);
132-
// all done
133-
return inputImage;
134-
}
135-
catch (...)
136-
{
137-
printf("failed to load the image file, make sure you are using fully qualified paths\r\n");
138-
exit(EXIT_FAILURE);
139-
}
140-
}
141-
14284
void PrintResults(IVectorView<float> results)
14385
{
14486
// load the labels
145-
LoadLabels();
87+
auto modulePath = FileHelper::GetModulePath();
88+
std::string labelsFilePath =
89+
std::string(modulePath.begin(), modulePath.end()) + "Labels.txt";
90+
labels = FileHelper::LoadLabels(labelsFilePath);
14691

14792
vector<pair<float, uint32_t>> sortedResults;
14893
for (uint32_t i = 0; i < results.Size(); i++) {
@@ -167,7 +112,7 @@ void RunSqueezeNet(Session session, Model model, hstring imagePath) {
167112

168113
// load the image
169114
printf("Loading the image...\n");
170-
auto imageFrame = LoadImageFile(imagePath);
115+
auto imageFrame = FileHelper::LoadImageFile(imagePath);
171116

172117
// bind the input image
173118
printf("Binding...\n");

Samples/SqueezeNetObjectDetection/Desktop/cpp/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void PrintResults(IVectorView<float> results)
193193
auto modulePath = FileHelper::GetModulePath();
194194
std::string labelsFilePath =
195195
std::string(modulePath.begin(), modulePath.end()) + labelsFileName;
196-
std::vector<std::string> labels = FileHelper::LoadLabels(labelsFilePath);
196+
labels = FileHelper::LoadLabels(labelsFilePath);
197197

198198
vector<pair<float, uint32_t>> sortedResults;
199199
for (uint32_t i = 0; i < results.Size(); i++) {

0 commit comments

Comments
 (0)