@@ -65,28 +65,6 @@ SoftwareBitmapToFloatVector(SoftwareBitmap softwareBitmap) {
6565 return outputVector;
6666}
6767
68- VideoFrame LoadImageFile (hstring filePath) {
69- VideoFrame inputImage = nullptr ;
70- try {
71- // open the file
72- StorageFile file = StorageFile::GetFileFromPathAsync (filePath).get ();
73- // get a stream on it
74- auto stream = file.OpenAsync (FileAccessMode::Read).get ();
75- // Create the decoder from the stream
76- BitmapDecoder decoder = BitmapDecoder::CreateAsync (stream).get ();
77- // get the bitmap
78- SoftwareBitmap softwareBitmap = decoder.GetSoftwareBitmapAsync ().get ();
79- // load a videoframe from it
80- inputImage = VideoFrame::CreateWithSoftwareBitmap (softwareBitmap);
81- } catch (...) {
82- printf (" failed to load the image file, make sure you are using fully "
83- " qualified paths\r\n " );
84- exit (EXIT_FAILURE);
85- }
86- // all done
87- return inputImage;
88- }
89-
9068hstring GetModelPath (std::string modelType) {
9169 hstring modelPath;
9270 if (modelType == " fixedBatchSize" ) {
@@ -104,7 +82,7 @@ TensorFloat CreateInputTensorFloat() {
10482 std::vector<float > inputVector = {};
10583 for (hstring imageName : imageNames) {
10684 auto imagePath = static_cast <hstring>(FileHelper::GetModulePath ().c_str ()) + imageName;
107- auto imageFrame = LoadImageFile (imagePath);
85+ auto imageFrame = FileHelper:: LoadImageFile (imagePath);
10886 std::vector<float > imageVector =
10987 SoftwareBitmapToFloatVector (imageFrame.SoftwareBitmap ());
11088 inputVector.insert (inputVector.end (), imageVector.begin (), imageVector.end ());
@@ -124,44 +102,19 @@ IVector<VideoFrame> CreateVideoFrames() {
124102 std::vector<VideoFrame> inputFrames = {};
125103 for (hstring imageName : imageNames) {
126104 auto imagePath = static_cast <hstring>(FileHelper::GetModulePath ().c_str ()) + imageName;
127- auto imageFrame = LoadImageFile (imagePath);
105+ auto imageFrame = FileHelper:: LoadImageFile (imagePath);
128106 inputFrames.emplace_back (imageFrame);
129107 }
130108 auto videoFrames = winrt::single_threaded_vector (std::move (inputFrames));
131109 return videoFrames;
132110}
133111
134- std::vector<std::string> LoadLabels (std::string labelsFilePath) {
135- // Parse labels from labels file. We know the file's entries are already
136- // sorted in order.
137- std::vector<std::string> labels;
138- std::ifstream labelFile{labelsFilePath, std::ifstream::in};
139- if (labelFile.fail ()) {
140- printf (" failed to load the %s file. Make sure it exists in the same "
141- " folder as the app\r\n " ,
142- labelsFilePath.c_str ());
143- exit (EXIT_FAILURE);
144- }
145-
146- std::string s;
147- while (std::getline (labelFile, s, ' ,' )) {
148- int labelValue = atoi (s.c_str ());
149- if (labelValue >= labels.size ()) {
150- labels.resize (labelValue + 1 );
151- }
152- std::getline (labelFile, s);
153- labels[labelValue] = s;
154- }
155-
156- return labels;
157- }
158-
159112void PrintResults (IVectorView<float > results) {
160113 // load the labels
161114 auto modulePath = FileHelper::GetModulePath ();
162115 std::string labelsFilePath =
163116 std::string (modulePath.begin (), modulePath.end ()) + " Labels.txt" ;
164- std::vector<std::string> labels = LoadLabels (labelsFilePath);
117+ std::vector<std::string> labels = FileHelper:: LoadLabels (labelsFilePath);
165118 // SqueezeNet returns a list of 1000 options, with probabilities for each,
166119 // loop through all
167120 for (uint32_t batchId = 0 ; batchId < BATCH_SIZE; ++batchId) {
0 commit comments