MCPcopy Create free account
hub / github.com/apple/coremltools / testUpwardPass

Function testUpwardPass

mlmodel/tests/NNShaperTest.cpp:269–337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269int testUpwardPass() {
270
271 Specification::Model m1;
272
273 auto *topIn = m1.mutable_description()->add_input();
274 topIn->set_name("input");
275 auto *shape = topIn->mutable_type()->mutable_multiarraytype();
276 auto *shape1 = shape->mutable_shaperange()->add_sizeranges();
277 shape1->set_lowerbound(4);
278 shape1->set_upperbound(4);
279 auto *shape2 = shape->mutable_shaperange()->add_sizeranges();
280 shape2->set_lowerbound(1);
281 shape2->set_upperbound(1);
282 auto *shape3 = shape->mutable_shaperange()->add_sizeranges();
283 shape3->set_lowerbound(1);
284 shape3->set_upperbound(-1);
285
286 auto *out = m1.mutable_description()->add_output();
287 out->set_name("output");
288 out->mutable_type()->mutable_multiarraytype();
289
290 auto *nn = m1.mutable_neuralnetwork();
291
292 Specification::NeuralNetworkLayer *convLayer = nn->add_layers();
293 convLayer->add_input("input");
294 convLayer->add_output("conv_out");
295 Specification::ConvolutionLayerParams *convParams = convLayer->mutable_convolution();
296 convParams->set_outputchannels(5);
297 convParams->set_kernelchannels(4);
298 convParams->add_kernelsize(1);
299 convParams->add_kernelsize(10);
300 convParams->mutable_valid();
301 convParams->set_hasbias(false);
302 for (int i = 0; i < 5*4*10; i++) {
303 convParams->mutable_weights()->add_floatvalue(1.0);
304 }
305
306 Specification::NeuralNetworkLayer *ipLayer = nn->add_layers();
307 ipLayer->add_input("conv_out");
308 ipLayer->add_output("output");
309 Specification::InnerProductLayerParams *ipParams = ipLayer->mutable_innerproduct();
310 ipParams->set_inputchannels(5);
311 ipParams->set_outputchannels(1);
312 ipParams->set_hasbias(false);
313 for (int i = 0; i < 5; i++) {
314 ipParams->mutable_weights()->add_floatvalue(1.0);
315 }
316
317 NeuralNetworkShaper shapes(m1);
318
319 const ShapeConstraint &inShape = shapes.shape("input");
320 ML_ASSERT(inShape.sequenceRange().minimumValue() == 0);
321 ML_ASSERT(inShape.sequenceRange().maximumValue().isUnbound());
322
323 ML_ASSERT(inShape.batchRange().minimumValue() == 0);
324 ML_ASSERT(inShape.batchRange().maximumValue().isUnbound());
325
326 ML_ASSERT(inShape.channelRange().minimumValue() == 4);

Callers

nothing calls this directly

Calls 6

minimumValueMethod · 0.80
isUnboundMethod · 0.80
maximumValueMethod · 0.80
set_nameMethod · 0.45
shapeMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected