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

Function testValidCustom

mlmodel/tests/NNValidatorTests.cpp:3931–3969  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3929
3930
3931int testValidCustom() {
3932
3933 Specification::Model m1;
3934 m1.set_specificationversion(MLMODEL_SPECIFICATION_VERSION);
3935
3936 auto *topIn = m1.mutable_description()->add_input();
3937 topIn->set_name("input");
3938 auto *shape = topIn->mutable_type()->mutable_multiarraytype();
3939 shape->set_datatype(Specification::ArrayFeatureType_ArrayDataType_DOUBLE);
3940 shape->add_shape(10);
3941 shape->add_shape(11);
3942 shape->add_shape(12);
3943
3944 auto *out = m1.mutable_description()->add_output();
3945 out->set_name("probs");
3946 auto *outvec = out->mutable_type()->mutable_multiarraytype();
3947 outvec->set_datatype(Specification::ArrayFeatureType_ArrayDataType_DOUBLE);
3948
3949 const auto nn = m1.mutable_neuralnetwork();
3950
3951 Specification::NeuralNetworkLayer *layer = nn->add_layers();
3952 layer->add_input("input");
3953 layer->add_output("probs");
3954 auto *params = layer->mutable_custom();
3955
3956 params->set_classname("CustomClassName");
3957
3958 auto *weights = params->add_weights();
3959 weights->set_float16value("somebitshere");
3960
3961 Result res = validate<MLModelType_neuralNetwork>(m1);
3962 ML_ASSERT_GOOD(res);
3963
3964 // We'll also test that the spec version is correct here
3965 Model mlmodel = Model(m1);
3966 ML_ASSERT(mlmodel.getProto().specificationversion() == MLMODEL_SPECIFICATION_VERSION_IOS11_2);
3967
3968 return 0;
3969}
3970
3971int testInvalidCustomNoName() {
3972

Callers

nothing calls this directly

Calls 2

ModelClass · 0.50
set_nameMethod · 0.45

Tested by

no test coverage detected