tensorflow/lite/experimental/acceleration/mini_benchmark/call.cc
// Verifies that number, shape and type of inputs match for subgraph and CALL
// node. If shape of inputs is unset for subgraph, it is inferred.
Verifies that number, shape and type of inputs match for subgraph and CALL
node. If shape of inputs is unset for subgraph, it is inferred.
Verifies that number shape and type of inputs match for subgraph and CALL node . If shape of inputs is unset for subgraph it is inferred .
TfLiteStatus ValidateAndResizeInputsIfNeeded(TfLiteContext* context,
                                             TfLiteNode* node,
                                             Subgraph* subgraph,
                                             int loop_count) {
  TF_LITE_ENSURE_EQ(context, subgraph->inputs().size(), node->inputs->size);
  for (int i = 0; i < node->inputs->size; ++i) {
    TfLiteTensor* node_input = context->tensors + node->inputs->data[i];
    TfLiteTensor* subgraph_input = subgraph->tensor(subgraph->inputs()[i]);
    TF_LITE_ENSURE_TYPES_EQ(context, node_input->type, subgraph_input->type);
    TF_LITE_ENSURE_MSG(
        context, node_input->dims->size > 0,
        "Dimensions of all of call node's inputs should be non-zero.");
    TF_LITE_ENSURE_EQ(context, node_input->dims->data[0], loop_count);
    if (!subgraph_input->dims->size) {
      std::vector<int> new_dims;
      new_dims.reserve(node_input->dims->size);
      new_dims.push_back(1);  
      new_dims.insert(new_dims.end(), node_input->dims->data + 1,
                      node_input->dims->data + node_input->dims->size);
      subgraph->ResizeInputTensor(subgraph->inputs()[i], new_dims);
    } else {
      if (!MatchDimensionsExceptBatchSize(node_input, subgraph_input)) {
        std::stringstream node_input_dims, subgraph_input_dims;
        for (int i = 0; i < node_input->dims->size; i++) {
          node_input_dims << node_input->dims->data[i] << " ";
          subgraph_input_dims << subgraph_input->dims->data[i] << " ";
        }
        TF_LITE_KERNEL_LOG(
            context,
            "%s:%d: All dimensions except the batch size should match for call "
            "node and the subgraph to invoke (input tensor %s[ %s], subgraph "
            "tensor %s[ %s])",
            __FILE__, __LINE__, node_input->name, node_input_dims.str().c_str(),
            subgraph_input->name, node_input_dims.str().c_str());
        return kTfLiteError;
      }
      TF_LITE_ENSURE_EQ(context, subgraph_input->dims->data[0], 1);
    }
  }
  return kTfLiteOk;
}
TfLiteStatus ValidateAndResizeInputsIfNeeded ( TfLiteContext * context , TfLiteNode * node , Subgraph * subgraph , int loop_count ) { TF_LITE_ENSURE_EQ ( context , subgraph -> inputs ( ) . size ( ) , node -> inputs -> size ) ; for ( int i = 0 ; i < node -> inputs -> size ; ++ i ) { TfLiteTensor * node_input = context -> tensors + node -> inputs -> data [ i ] ; TfLiteTensor * subgraph_input = subgraph -> tensor ( subgraph -> inputs ( ) [ i ] ) ; TF_LITE_ENSURE_TYPES_EQ ( context , node_input -> type , subgraph_input -> type ) ; TF_LITE_ENSURE_MSG ( context , node_input -> dims -> size > 0 , " " ) ; TF_LITE_ENSURE_EQ ( context , node_input -> dims -> data [ 0 ] , loop_count ) ; if ( ! subgraph_input -> dims -> size ) { std :: vector < int > new_dims ; new_dims . reserve ( node_input -> dims -> size ) ; new_dims . push_back ( 1 ) ; new_dims . insert ( new_dims . end ( ) , node_input -> dims -> data + 1 , node_input -> dims -> data + node_input -> dims -> size ) ; subgraph -> ResizeInputTensor ( subgraph -> inputs ( ) [ i ] , new_dims ) ; } else { if ( ! MatchDimensionsExceptBatchSize ( node_input , subgraph_input ) ) { std :: stringstream node_input_dims , subgraph_input_dims ; for ( int i = 0 ; i < node_input -> dims -> size ; i ++ ) { node_input_dims << node_input -> dims -> data [ i ] << " " ; subgraph_input_dims << subgraph_input -> dims -> data [ i ] << " " ; } TF_LITE_KERNEL_LOG ( context , " " " " " " , __FILE__ , __LINE__ , node_input -> name , node_input_dims . str ( ) . c_str ( ) , subgraph_input -> name , node_input_dims . str ( ) . c_str ( ) ) ; return kTfLiteError ; } TF_LITE_ENSURE_EQ ( context , subgraph_input -> dims -> data [ 0 ] , 1 ) ; } } return kTfLiteOk ; }
Verifies that number, shape and type of inputs match for subgraph and CALL
node.
Verifies that number shape and type of inputs match for subgraph and CALL node .
// Match number of inputs for subgraph and CALL node. // Match input types. // Ensure batch size of CALL node's input is same as loop size. // Subgraph input dimensions unset and will be inferred. // Batch size is fixed as 1 for subgraph. // Dimensions already set for subgraph, match input dimensions. // Batch size of subgraph's input should be 1.