| 26 | namespace testing { |
| 27 | |
| 28 | DiffOptions ParseTfliteDiffFlags(int* argc, char** argv) { |
| 29 | struct { |
| 30 | string tensorflow_model; |
| 31 | string tflite_model; |
| 32 | string input_layer; |
| 33 | string input_layer_type; |
| 34 | string input_layer_shape; |
| 35 | string output_layer; |
| 36 | int32_t num_runs_per_pass = 100; |
| 37 | string delegate_name; |
| 38 | } values; |
| 39 | |
| 40 | std::string delegate_name; |
| 41 | std::vector<tensorflow::Flag> flags = { |
| 42 | tensorflow::Flag("tensorflow_model", &values.tensorflow_model, |
| 43 | "Path of tensorflow model."), |
| 44 | tensorflow::Flag("tflite_model", &values.tflite_model, |
| 45 | "Path of tensorflow lite model."), |
| 46 | tensorflow::Flag("input_layer", &values.input_layer, |
| 47 | "Names of input tensors, separated by comma. Example: " |
| 48 | "input_1,input_2."), |
| 49 | tensorflow::Flag("input_layer_type", &values.input_layer_type, |
| 50 | "Data types of input tensors, separated by comma. " |
| 51 | "Example: float,int."), |
| 52 | tensorflow::Flag( |
| 53 | "input_layer_shape", &values.input_layer_shape, |
| 54 | "Shapes of input tensors, separated by colon. Example: 1,3,4,1:2."), |
| 55 | tensorflow::Flag("output_layer", &values.output_layer, |
| 56 | "Names of output tensors, separated by comma. Example: " |
| 57 | "output_1,output_2."), |
| 58 | tensorflow::Flag("num_runs_per_pass", &values.num_runs_per_pass, |
| 59 | "[optional] Number of full runs in each pass."), |
| 60 | tensorflow::Flag("delegate", &values.delegate_name, |
| 61 | "[optional] Delegate to use for executing ops. Must be " |
| 62 | "`{\"\", NNAPI, GPU, FLEX}`"), |
| 63 | }; |
| 64 | |
| 65 | bool no_inputs = *argc == 1; |
| 66 | bool success = tensorflow::Flags::Parse(argc, argv, flags); |
| 67 | if (!success || no_inputs || (*argc == 2 && !strcmp(argv[1], "--helpfull"))) { |
| 68 | fprintf(stderr, "%s", tensorflow::Flags::Usage(argv[0], flags).c_str()); |
| 69 | return {}; |
| 70 | } else if (values.tensorflow_model.empty() || values.tflite_model.empty() || |
| 71 | values.input_layer.empty() || values.input_layer_type.empty() || |
| 72 | values.input_layer_shape.empty() || values.output_layer.empty()) { |
| 73 | fprintf(stderr, "%s", tensorflow::Flags::Usage(argv[0], flags).c_str()); |
| 74 | return {}; |
| 75 | } |
| 76 | |
| 77 | TfLiteDriver::DelegateType delegate = TfLiteDriver::DelegateType::kNone; |
| 78 | if (!values.delegate_name.empty()) { |
| 79 | if (delegate_name == "NNAPI") { |
| 80 | delegate = TfLiteDriver::DelegateType::kNnapi; |
| 81 | } else if (values.delegate_name == "GPU") { |
| 82 | delegate = TfLiteDriver::DelegateType::kGpu; |
| 83 | } else if (values.delegate_name == "FLEX") { |
| 84 | delegate = TfLiteDriver::DelegateType::kFlex; |
| 85 | } else { |