31 arser::Arser arser{
"tfl-inspect allows users to retrieve various information from a TensorFlow "
33 arser.add_argument(
"--operators").nargs(0).help(
"Dump operators in tflite file");
34 arser.add_argument(
"--conv2d_weight")
36 .help(
"Dump Conv2D series weight operators in tflite file");
37 arser.add_argument(
"--op_version").nargs(0).help(
"Dump versions of the operators in tflite file");
38 arser.add_argument(
"tflite").help(
"TFLite file to inspect");
42 arser.parse(argc, argv);
44 catch (
const std::runtime_error &err)
46 std::cout << err.what() << std::endl;
51 if (!
arser[
"--operators"] && !
arser[
"--conv2d_weight"] && !
arser[
"--op_version"])
53 std::cout <<
"At least one option must be specified" << std::endl;
58 std::vector<std::unique_ptr<tflinspect::DumpInterface>> dumps;
60 if (
arser[
"--operators"])
61 dumps.push_back(std::make_unique<tflinspect::DumpOperators>());
62 if (
arser[
"--conv2d_weight"])
63 dumps.push_back(std::make_unique<tflinspect::DumpConv2DWeight>());
64 if (
arser[
"--op_version"])
65 dumps.push_back(std::make_unique<tflinspect::DumpOperatorVersion>());
67 std::string model_file =
arser.get<std::string>(
"tflite");
71 std::vector<char> modelData = fileLoader.
load();
72 const tflite::Model *tfliteModel = tflite::GetModel(modelData.data());
73 if (tfliteModel ==
nullptr)
75 std::cerr <<
"ERROR: Failed to load tflite '" << model_file <<
"'" << std::endl;
79 for (
auto &
dump : dumps)
81 dump->run(std::cout, tfliteModel);