tensorflow/lite/tools/optimize/calibration/calibrator.cc
// A wrapper implementation for |TfLiteRegistration.invoke| that logs inputs,
// invokes the wrapped implementation and then logs the outputs.
A wrapper implementation for |TfLiteRegistration.invoke| that logs inputs,
invokes the wrapped implementation and then logs the outputs.
A wrapper implementation for |TfLiteRegistration . invoke| that logs inputs invokes the wrapped implementation and then logs the outputs .
TfLiteStatus LoggingEval(TfLiteContext* context, TfLiteNode* node) {
  Calibrator* calibrator = GetCalibratorRegistry()->GetCalibrator(node);
  if (!calibrator) {
    context->ReportError(context, "No calibrator found for context.");
    return kTfLiteError;
  }
  auto kernel_invoke = calibrator->GetKernelInvoke(node);
  auto logger = calibrator->GetLogger();
  auto op_info = calibrator->GetOpInfo(node);
  auto error_reporter = calibrator->GetErrorReporter();
  for (int i : op_info.loggable_inputs) {
    auto tensor = context->tensors[i];
    TF_LITE_ENSURE_STATUS(
        logger->LogTensorValue(op_info.subgraph_index, i, tensor.data.f,
                               tensor.bytes / sizeof(float), error_reporter));
  }
  auto builtin_op_code = calibrator->GetOpInfo(node).builtin_op_code;
  auto kernel_invoke_intermediate =
      GetLoggingEvalFunc(context, node, builtin_op_code);
  if (kernel_invoke_intermediate == nullptr) {
    TF_LITE_ENSURE_STATUS(kernel_invoke(context, node));
  } else {
    TF_LITE_ENSURE_STATUS(
        kernel_invoke_intermediate(context, op_info.subgraph_index, node,
                                   calibrator->GetLogger(), error_reporter));
  }
  for (int i : op_info.loggable_inputs) {
    auto tensor = context->tensors[i];
    TF_LITE_ENSURE_STATUS(
        logger->LogTensorValue(op_info.subgraph_index, i, tensor.data.f,
                               tensor.bytes / sizeof(float), error_reporter));
  }
  for (int i : op_info.loggable_outputs) {
    auto tensor = context->tensors[i];
    TF_LITE_ENSURE_STATUS(
        logger->LogTensorValue(op_info.subgraph_index, i, tensor.data.f,
                               tensor.bytes / sizeof(float), error_reporter));
  }
  return kTfLiteOk;
}
TfLiteStatus LoggingEval ( TfLiteContext * context , TfLiteNode * node ) { Calibrator * calibrator = GetCalibratorRegistry ( ) -> GetCalibrator ( node ) ; if ( ! calibrator ) { context -> ReportError ( context , " " ) ; return kTfLiteError ; } auto kernel_invoke = calibrator -> GetKernelInvoke ( node ) ; auto logger = calibrator -> GetLogger ( ) ; auto op_info = calibrator -> GetOpInfo ( node ) ; auto error_reporter = calibrator -> GetErrorReporter ( ) ; for ( int i : op_info . loggable_inputs ) { auto tensor = context -> tensors [ i ] ; TF_LITE_ENSURE_STATUS ( logger -> LogTensorValue ( op_info . subgraph_index , i , tensor . data . f , tensor . bytes / sizeof ( float ) , error_reporter ) ) ; } auto builtin_op_code = calibrator -> GetOpInfo ( node ) . builtin_op_code ; auto kernel_invoke_intermediate = GetLoggingEvalFunc ( context , node , builtin_op_code ) ; if ( kernel_invoke_intermediate == nullptr ) { TF_LITE_ENSURE_STATUS ( kernel_invoke ( context , node ) ) ; } else { TF_LITE_ENSURE_STATUS ( kernel_invoke_intermediate ( context , op_info . subgraph_index , node , calibrator -> GetLogger ( ) , error_reporter ) ) ; } for ( int i : op_info . loggable_inputs ) { auto tensor = context -> tensors [ i ] ; TF_LITE_ENSURE_STATUS ( logger -> LogTensorValue ( op_info . subgraph_index , i , tensor . data . f , tensor . bytes / sizeof ( float ) , error_reporter ) ) ; } for ( int i : op_info . loggable_outputs ) { auto tensor = context -> tensors [ i ] ; TF_LITE_ENSURE_STATUS ( logger -> LogTensorValue ( op_info . subgraph_index , i , tensor . data . f , tensor . bytes / sizeof ( float ) , error_reporter ) ) ; } return kTfLiteOk ; }
A wrapper implementation for |TfLiteRegistration.invoke| that logs inputs,
invokes the wrapped implementation and then logs the outputs.
A wrapper implementation for |TfLiteRegistration . invoke| that logs inputs invokes the wrapped implementation and then logs the outputs .
// TODO(shashishekhar): An intermediate tensor in graph will get logged twice // once as an input and second time as output. This doesn't change the min max // values but is inefficient. // Using moving average will also break this. // Log input again to make sure the state tensors are captured after lstm // cell.