@@ -100,104 +100,9 @@ namespace winrt::WinMLSamplesGalleryNative::implementation
100100 1 ,0 ,0
101101 };
102102
103- // .Inputs.Add(LearningModelBuilder.CreateTensorFeatureDescriptor("Input", TensorKind.UInt8, new long[] { 1, bufferInBytes }))
104- // .Outputs.Add(LearningModelBuilder.CreateTensorFeatureDescriptor("Output", TensorKind.Float, new long[] { 1, newH, newW, c }))
105- // .Operators.Add(new LearningModelOperator("Cast")
106- // .SetInput("input", "Input")
107- // .SetAttribute("to", TensorInt64Bit.CreateFromIterable(new long[] {}, new long[] { (long)OnnxDataType.FLOAT }))
108- // .SetOutput("output", "CastOutput"))
109- // .Operators.Add(new LearningModelOperator("Reshape")
110- // .SetInput("data", "CastOutput")
111- // .SetConstant("shape", TensorInt64Bit.CreateFromIterable(new long[] { 4 }, new long[] { 1, height, width, 4 }))
112- // .SetOutput("reshaped", "ReshapeOutput"))
113- // .Operators.Add(new LearningModelOperator("Slice")
114- // .SetInput("data", "ReshapeOutput")
115- // .SetConstant("starts", TensorInt64Bit.CreateFromIterable(new long[] { 4 }, new long[] { 0, 0, 0, 0 }))
116- // .SetConstant("ends", TensorInt64Bit.CreateFromIterable(new long[] { 4 }, new long[] { long.MaxValue, long.MaxValue, width, c - 1 }))
117- // .SetOutput("output", "SliceOutput"))
118- // .Operators.Add(new LearningModelOperator("Resize")
119- // .SetInput("X", "ReshapeOutput")
120- // .SetConstant("roi", TensorFloat.CreateFromIterable(new long[] { 8 }, new float[] { 0, 0, 0, 0, 1, 1, 1, 1 }))
121- // .SetConstant("scales", TensorFloat.CreateFromIterable(new long[] { 4 }, new float[] { 1, (float)(1 + resizedH) / (float)h, (float)(1 + resizedH) / (float)h, 1 }))
122- // //.SetConstant("sizes", TensorInt64Bit.CreateFromIterable(new long[] { 4 }, new long[] { 1, 3, resizedH, resizedW }))
123- // .SetAttribute("mode", TensorString.CreateFromArray(new long[] {}, new string[]{ interpolationMode }))
124- // .SetOutput("Y", "ResizeOutput"))
125- // .Operators.Add(new LearningModelOperator("Slice")
126- // .SetInput("data", "ResizeOutput")
127- // .SetConstant("starts", TensorInt64Bit.CreateFromIterable(new long[] { 4 }, new long[] { 0, 0, 0, 0 }))
128- // .SetConstant("ends", TensorInt64Bit.CreateFromIterable(new long[] { 4 }, new long[] { long.MaxValue, 224, 224, 3 }))
129- // .SetOutput("output", "SliceOutput"))
130- // This is just getting bgr to rgb
131- /* .Operators.Add(new LearningModelOperator("Conv")
132- .SetInput("X", "Input")
133- .SetConstant("W", TensorFloat.CreateFromArray(new long[] { 3, 3, 1, 1 }, kernel))
134- .SetConstant("B", TensorFloat.CreateFromArray(new long[] { 1, 3, 1, 1 }, new float[] { 0, 0, 0 }))
135- .SetOutput("Y", "Output"));*/
136-
137- // if above doesn't work try
138- // .SetConstant("W", TensorFloat.CreateFromArray(new long[] { 3, 1, 1, 3 }, kernel))
139- // .SetConstant("B", TensorFloat.CreateFromArray(new long[] { 1, 1, 1, 3 }, new float[] { 0, 0, 0 }))
140-
141- // auto resize_op = LearningModelOperator(L"Resize")
142- // .SetInput(L"X", L"Input")
143- // .SetConstant(L"roi", TensorFloat::CreateFromIterable({ 8 }, { 0, 0, 0, 0, 1, 1, 1, 1 }))
144- // .SetConstant(L"scales", TensorFloat::CreateFromIterable({ 4 }, { 1, (float)(1 + resizedH) / (float)h, (float)(1 + resizedH) / (float)h, 1 }))
145- // .SetAttribute(L"mode", TensorString::CreateFromArray({}, { interpolationMode }))
146- // .SetOutput(L"Y", L"ResizeOutput");
147-
148- // auto slice_op = LearningModelOperator(L"Slice")
149- // .SetInput(L"data", L"ResizeOutput")
150- // .SetConstant(L"starts", TensorInt64Bit::CreateFromIterable({ 4 }, { 0, top, left, 0 }))
151- // .SetConstant(L"ends", TensorInt64Bit::CreateFromIterable({ 4 }, { LLONG_MAX, bottom, right, 3 }))
152- // .SetOutput(L"output", L"Output");
153-
154- auto cast_op = LearningModelOperator (L" Cast" )
155- .SetInput (L" input" , L" Input" )
156- .SetAttribute (L" to" , TensorInt64Bit::CreateFromIterable ({}, { (long )1 }))
157- .SetOutput (L" output" , L" CastOutput" );
158-
159- auto reshape_op = LearningModelOperator (L" Reshape" )
160- .SetInput (L" data" , L" CastOutput" )
161- .SetConstant (L" shape" , TensorInt64Bit::CreateFromIterable ({ 4 }, { 1 , height, 832 , 4 }))
162- .SetOutput (L" reshaped" , L" ReshapeOutput" );
163-
164- auto slice_1 = LearningModelOperator (L" Slice" )
165- .SetInput (L" data" , L" ReshapeOutput" )
166- .SetConstant (L" starts" , TensorInt64Bit::CreateFromIterable ({ 4 }, { 0 , 0 , 0 , 0 }))
167- .SetConstant (L" ends" , TensorInt64Bit::CreateFromIterable ({ 4 }, { LONG_MAX, LONG_MAX, width, c - 1 }))
168- .SetOutput (L" output" , L" SliceOutput" );
169-
170- auto resize_op = LearningModelOperator (L" Resize" )
171- .SetInput (L" X" , L" SliceOutput" )
172- .SetConstant (L" roi" , TensorFloat::CreateFromIterable ({ 8 }, { 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 }))
173- .SetConstant (L" scales" , TensorFloat::CreateFromIterable ({ 4 }, { 1 , (float )(1 + resizedH) / (float )h, (float )(1 + resizedH) / (float )h, 1 }))
174- .SetAttribute (L" mode" , TensorString::CreateFromArray ({}, { interpolationMode }))
175- .SetOutput (L" Y" , L" ResizeOutput" );
176-
177- auto slice_2 = LearningModelOperator (L" Slice" )
178- .SetInput (L" data" , L" ResizeOutput" )
179- .SetConstant (L" starts" , TensorInt64Bit::CreateFromIterable ({ 4 }, { 0 , 0 , 0 , 0 }))
180- .SetConstant (L" ends" , TensorInt64Bit::CreateFromIterable ({ 4 }, { LONG_MAX, 224 , 224 , 3 }))
181- .SetOutput (L" output" , L" Output" );
182-
183- auto preprocessingModelBuilder =
184- LearningModelBuilder::Create (12 )
185- .Inputs ().Add (LearningModelBuilder::CreateTensorFeatureDescriptor (L" Input" , TensorKind::UInt8, preprocessInputShape))
186- .Outputs ().Add (LearningModelBuilder::CreateTensorFeatureDescriptor (L" Output" , TensorKind::Float, preprocessOutputShape))
187- .Operators ().Add (cast_op)
188- .Operators ().Add (reshape_op)
189- .Operators ().Add (slice_1)
190- .Operators ().Add (resize_op)
191- .Operators ().Add (slice_2);
192- auto preprocessingModel = preprocessingModelBuilder.CreateModel ();
193-
194- preprocessingModelBuilder.Save (L" C:/Users/numform/Windows-Machine-Learning/Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative/dx_preprocessor_efficient_net_v2.onnx" );
195-
196103 // Create ORT Sessions that will be used for preprocessing and classification
197- const wchar_t * preprocessingModelFilePath = L" C:/Users/numform/Windows-Machine-Learning/Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative/dx_preprocessor_efficient_net_v2.onnx" ;
198- const wchar_t * inferencemodelFilePath = L" C:/Users/numform/Windows-Machine-Learning/Samples/WinMLSamplesGallery/WinMLSamplesGalleryNative/efficientnet-lite4-11.onnx" ;
199- preprocesingSession = CreateSession (preprocessingModelFilePath);
200- inferenceSession = CreateSession (inferencemodelFilePath);
104+ preprocesingSession = CreateSession (Win32Application::GetAssetPath (L" dx_preprocessor_efficient_net_v2.onnx" ).c_str ());
105+ inferenceSession = CreateSession (Win32Application::GetAssetPath (L" efficientnet-lite4-11.onnx" ).c_str ());
201106
202107 // Spawn the window in a separate thread
203108 std::thread d3d_th (Win32Application::Run, &sample, 10 );
0 commit comments