docstr: A generic _predict_batch that stacks and passes items to TensorFlow
docstr_tok: ["A","generic","_predict_batch","that","stacks","and","passes","items","to","TensorFlow"]
code: def _predict_batch(self, items, **kwargs):
      """A generic _predict_batch that stacks and passes items to TensorFlow"""
      mask = [self._is_empty(item) for item in items]
      if all(mask):
          return self._rebuild_predictions_with_mask(mask, {})
      vects = {
          key: np.stack(
              [
                  item[key]
                  for item, mask in zip(items, mask)
                  if not mask
              ],
              axis=0,
          )
          for key in items[0]
      }
      predictions = self._tensorflow_predict(vects)
      return self._rebuild_predictions_with_mask(mask, predictions)
  
imports: import abc
  import json
  import os
  from typing import Any, Dict, List, Optional, Tuple, Type
  import aiohttp
  import requests
  from structlog import get_logger
  from tenacity import Retrying, retry_if_exception, stop_after_attempt, wait_random_exponential
  from modelkit.core.model import AsyncModel, Model
  from modelkit.core.types import ItemType, ReturnType
  from modelkit.utils.serialization import safe_np_dump
label_desc: Use image node_id 2 for calling the TensorflowModel obj's underlying member method code with example usage: obj._predict_batch(items) and returns: self, self