| 1449 | } |
| 1450 | |
| 1451 | int testInvalid_OnlyTarget() { |
| 1452 | Specification::Model spec; |
| 1453 | Result res; |
| 1454 | TensorAttributes tensorAttributesIn = { "InTensor", 3 }; |
| 1455 | TensorAttributes tensorAttributesOut = { "OutTensor", 1 }; |
| 1456 | |
| 1457 | (void)buildBasicNeuralNetworkModel(spec, true, &tensorAttributesIn, &tensorAttributesOut, 1024); |
| 1458 | spec.set_specificationversion(MLMODEL_SPECIFICATION_VERSION_IOS13); |
| 1459 | auto neuralNet = spec.mutable_neuralnetwork(); |
| 1460 | |
| 1461 | // set a softmax layer |
| 1462 | (void)addSoftmaxLayer(spec, "softmax", "OutTensor", "softmax_out"); |
| 1463 | |
| 1464 | std::string targetName = "cce_target"; |
| 1465 | addCategoricalCrossEntropyLoss(spec, neuralNet, "cross_entropy_loss_layer", "softmax_out", targetName.c_str()); |
| 1466 | |
| 1467 | addLearningRate(neuralNet, Specification::Optimizer::kSgdOptimizer, 0.7f, 0.0f, 1.0f); |
| 1468 | addMiniBatchSize(neuralNet, Specification::Optimizer::kSgdOptimizer, 10, 5, 100, std::set<int64_t>()); |
| 1469 | addEpochs(neuralNet, 100, 1, 100, std::set<int64_t>()); |
| 1470 | addShuffleAndSeed(neuralNet, 2019, 0, 2019, std::set<int64_t>()); |
| 1471 | |
| 1472 | // Clearing and then specifically adding only the target as a training input |
| 1473 | spec.mutable_description()->clear_traininginput(); |
| 1474 | |
| 1475 | auto trainingInput = spec.mutable_description()->mutable_traininginput()->Add(); |
| 1476 | trainingInput->set_name(targetName); |
| 1477 | auto trainingInputTensorShape = trainingInput->mutable_type()->mutable_multiarraytype(); |
| 1478 | trainingInputTensorShape->set_datatype(Specification::ArrayFeatureType_ArrayDataType_INT32); |
| 1479 | trainingInputTensorShape->add_shape(1); |
| 1480 | |
| 1481 | res = Model::validate(spec); |
| 1482 | ML_ASSERT_BAD(res); |
| 1483 | |
| 1484 | // Remove predictedFeatureName from model's outputs and add model's inputs to training inputs |
| 1485 | spec.mutable_description()->clear_output(); |
| 1486 | auto outTensor = spec.mutable_description()->add_output(); |
| 1487 | outTensor->set_name(tensorAttributesOut.name); |
| 1488 | auto outTensorShape = outTensor->mutable_type()->mutable_multiarraytype(); |
| 1489 | outTensorShape->set_datatype(Specification::ArrayFeatureType_ArrayDataType_FLOAT32); |
| 1490 | for (int i = 0; i < tensorAttributesOut.dimension; i++) { |
| 1491 | outTensorShape->add_shape(1); |
| 1492 | } |
| 1493 | |
| 1494 | for (auto feature : spec.description().input()) { |
| 1495 | auto trainingInputModel = spec.mutable_description()->mutable_traininginput()->Add(); |
| 1496 | trainingInputModel->CopyFrom(feature); |
| 1497 | } |
| 1498 | res = Model::validate(spec); |
| 1499 | ML_ASSERT_GOOD(res); return 0; |
| 1500 | } |
| 1501 | |
| 1502 | int testInvalid_OnlyPredictedFeatureName() { |
| 1503 | Specification::Model spec; |
nothing calls this directly
no test coverage detected