}
const ArrayMap& GetArrayMap() const { return arrays; }
+ int64 ArithmeticOpsCount() const { return ops_count; }
+
// Optional arrays are used for optional tensors,
// these tensors do not have data, but with reserved names as op inputs.
std::set<string> optional_arrays;
std::size_t transient_data_size = 0;
// For code-generation only: required alignment of the transient_data buffer
std::size_t transient_data_alignment = 0;
+ // Arithmatic operations performed in the model.
+ int64 ops_count = 0;
private:
// The associative array mapping names to Array's.
// Convert a model represented in `input_contents`. `model_flags_proto`
// describes model parameters. `toco_flags_proto` describes conversion
// parameters (see relevant .protos for more information). Returns a string
-// representing the contents of the converted model.
+// representing the contents of the converted model. When extended_return
+// flag is set to true returns a dictionary that contains string representation
+// of the converted model and some statitics like arithmetic ops count.
PyObject* TocoConvert(PyObject* model_flags_proto_txt_raw,
PyObject* toco_flags_proto_txt_raw,
- PyObject* input_contents_txt_raw);
+ PyObject* input_contents_txt_raw,
+ bool extended_return = false);
} // namespace toco
\ No newline at end of file
// sure we input and output bytes rather than unicode strings for Python3.
PyObject* TocoConvert(PyObject* model_flags_proto_txt_raw,
PyObject* toco_flags_proto_txt_raw,
- PyObject* input_contents_txt_raw) {
+ PyObject* input_contents_txt_raw, bool extended_return) {
// Use Python C API to validate and convert arguments. In py3 (bytes),
// in py2 (str).
auto ConvertArg = [&](PyObject* obj, bool* error) {
Export(toco_flags, *model, toco_flags.allow_custom_ops(),
&output_file_contents_txt);
+ if (extended_return) {
+ PyObject* dict = PyDict_New();
+ PyDict_SetItemString(
+ dict, "flatbuffer",
+ TOCO_FROM_CPPSTRING_TO_PY(output_file_contents_txt.data(),
+ output_file_contents_txt.size()));
+ PyDict_SetItemString(dict, "arithmetic_ops",
+ PyLong_FromLong(model->ArithmeticOpsCount()));
+ return dict;
+ }
// Convert arguments back to byte (py3) or str (py2)
return TOCO_FROM_CPPSTRING_TO_PY(output_file_contents_txt.data(),
output_file_contents_txt.size());
// Convert a model represented in `input_contents`. `model_flags_proto`
// describes model parameters. `toco_flags_proto` describes conversion
// parameters (see relevant .protos for more information). Returns a string
-// representing the contents of the converted model.
+// representing the contents of the converted model. When extended_return
+// flag is set to true returns a dictionary that contains string representation
+// of the converted model and some statitics like arithmetic ops count.
PyObject* TocoConvert(PyObject* model_flags_proto_txt_raw,
PyObject* toco_flags_proto_txt_raw,
- PyObject* input_contents_txt_raw);
+ PyObject* input_contents_txt_raw,
+ bool extended_return = false);
} // namespace toco
LOG(INFO) << "Estimated count of arithmetic ops: " << 1e-9 * ops_count
<< " billion (note that a multiply-add is counted as 2 ops).";
}
+ model->ops_count = ops_count;
}
void Export(const TocoFlags& toco_flags, const Model& model,