| 1507 | } |
| 1508 | |
| 1509 | void ResolveModelFlags(const ModelFlags& model_flags, Model* model) { |
| 1510 | // Merge info about input_arrays from model_flags into model->flags |
| 1511 | for (const auto& specified_input_array : model_flags.input_arrays()) { |
| 1512 | toco::InputArray* dst_input_array = nullptr; |
| 1513 | for (int i = 0; i < model->flags.input_arrays_size(); i++) { |
| 1514 | toco::InputArray* candidate_dst_input_array = |
| 1515 | model->flags.mutable_input_arrays(i); |
| 1516 | if (candidate_dst_input_array->name() == specified_input_array.name()) { |
| 1517 | // specified_input_array from model_flags maps to dst_input_array |
| 1518 | // in model->flags |
| 1519 | dst_input_array = candidate_dst_input_array; |
| 1520 | break; |
| 1521 | } |
| 1522 | } |
| 1523 | if (!dst_input_array) { |
| 1524 | // Specified_input_array from model_flags is not found in model->flags. |
| 1525 | // Match a name-less specified input array when there can be no ambiguity |
| 1526 | // as there is only 1 input array. |
| 1527 | if (model->flags.input_arrays_size() == 1 && |
| 1528 | model_flags.input_arrays_size() == 1 && |
| 1529 | !specified_input_array.has_name()) { |
| 1530 | dst_input_array = model->flags.mutable_input_arrays(0); |
| 1531 | } |
| 1532 | } |
| 1533 | if (!dst_input_array) { |
| 1534 | // Still no match, so create a new input array to copy |
| 1535 | // specified_input_array into. |
| 1536 | dst_input_array = model->flags.add_input_arrays(); |
| 1537 | dst_input_array->set_name(specified_input_array.name()); |
| 1538 | } |
| 1539 | |
| 1540 | #define RESOLVE_MODEL_FLAG(field_name) \ |
| 1541 | if (specified_input_array.has_##field_name()) { \ |
| 1542 | if (dst_input_array->has_##field_name()) { \ |
| 1543 | QCHECK_EQ(dst_input_array->field_name(), \ |
| 1544 | specified_input_array.field_name()) \ |
| 1545 | << "For input array '" << dst_input_array->name() << "', " \ |
| 1546 | << "specified " #field_name " flag with value: " \ |
| 1547 | << specified_input_array.field_name() \ |
| 1548 | << " does not agree with already defined " #field_name \ |
| 1549 | " of this model, with value: " \ |
| 1550 | << specified_input_array.field_name(); \ |
| 1551 | } else { \ |
| 1552 | dst_input_array->set_##field_name(specified_input_array.field_name()); \ |
| 1553 | } \ |
| 1554 | } |
| 1555 | RESOLVE_MODEL_FLAG(std_value); |
| 1556 | RESOLVE_MODEL_FLAG(mean_value); |
| 1557 | #undef RESOLVE_MODEL_FLAG |
| 1558 | |
| 1559 | if (specified_input_array.has_shape()) { |
| 1560 | if (dst_input_array->has_shape()) { |
| 1561 | QCHECK_EQ(specified_input_array.shape().dims_size(), |
| 1562 | dst_input_array->shape().dims_size()) |
| 1563 | << "For input array '" << specified_input_array.name() << "', " |
| 1564 | << "size of specified input shape flag with size: " |
| 1565 | << specified_input_array.shape().dims_size() |
| 1566 | << " does not agree with already defined input shape" |
no test coverage detected