code: def extract_from_output(
      outputs: List[Dict],
      ret_type: str,
      as_ndarray: Optional[bool] = True,
  ):
      """
      Extract desired information, e.g., logits or features, from a list of model outputs.
      Support returning a concatenated tensor/ndarray or a dictionary of tensors/ndarrays.
  
      Parameters
      ----------
      ret_type
          What kind of information to extract from model outputs.
      outputs
          A list of model outputs.
      as_ndarray
          Whether to convert Pytorch tensor to numpy array. (Default True)
  
      Returns
      -------
      The desired information from model outputs.
      """
      if ret_type == LOGITS:
          logits = [ele[LOGITS] for ele in outputs]
          ret = torch.cat(logits).nan_to_num(nan=-1e4)
      elif ret_type == PROBABILITY:
          probability = [ele[PROBABILITY] for ele in outputs]
          ret = torch.cat(probability).nan_to_num(nan=0)
      elif ret_type == FEATURES:
          features = [ele[FEATURES] for ele in outputs]
          ret = torch.cat(features).nan_to_num(nan=0)
      elif ret_type == COLUMN_FEATURES:
          ret = {}
          column_features = [
              ele[COLUMN_FEATURES][FEATURES] for ele in outputs
          ]  # a list of dicts
          for feature_name in column_features[0].keys():
              ret[feature_name] = torch.cat(
                  [ele[feature_name] for ele in column_features]
              )
      elif ret_type == MASKS:
          ret = {}
          feature_masks = [
              ele[COLUMN_FEATURES][MASKS] for ele in outputs
          ]  # a list of dicts
          for feature_name in feature_masks[0].keys():
              ret[feature_name] = torch.cat(
                  [ele[feature_name] for ele in feature_masks]
              )
      elif ret_type == BBOX:
          if (
              isinstance(outputs, list)
              and isinstance(outputs[0], list)
              and len(outputs) == 1
          ):
              # TODO: the output should be a list of dict
              # find the cause of this (should be in cache.py)
              outputs = outputs[0]
          return [ele[BBOX] for ele in outputs]
      elif ret_type == OVD_RET:
          from .object_detection import bbox_ratio_xywh_to_index_xyxy
  
          ovd_pred = []
          for ele in outputs:
              curr_batch_size = len(ele[BBOX])
              for i in range(curr_batch_size):
                  curr_pred = []
                  curr_pred_size = len(ele[BBOX][i])
                  for j in range(curr_pred_size):
                      curr_pred.append(
                          {
                              "bbox": bbox_ratio_xywh_to_index_xyxy(
                                  xywh=ele[BBOX][i][j]
                                  .detach()
                                  .cpu()
                                  .numpy(),
                                  image_wh=ele[IMAGE_META][i],
                              )[0],
                              "class": ele[PROMPT][i][j],
                              "score": ele[LOGITS][i][j]
                              .detach()
                              .cpu()
                              .numpy(),
                          }
                      )
                  ovd_pred.append(curr_pred)
          return ovd_pred
      elif ret_type == TEXT:
          return [ele[TEXT] for ele in outputs]  # single image
      elif ret_type == SCORE:
          return [ele[SCORE] for ele in outputs]
      elif ret_type == NER_RET:
          ner_pred = []
          as_ndarray = False
          for ele in outputs:
              logits_label = ele[NER_ANNOTATION].detach().cpu().numpy()
              logits = softmax(
                  ele[LOGITS].detach().cpu().numpy(), axis=-1
              )
              token_word_mapping = (
                  ele[TOKEN_WORD_MAPPING].detach().cpu().numpy()
              )
              word_offsets = ele[WORD_OFFSETS].detach().cpu().numpy()
              for token_preds, logit, mappings, offsets in zip(
                  logits_label, logits, token_word_mapping, word_offsets
              ):
                  pred_one_sentence, word_offset, pred_proba = (
                      [],
                      [],
                      [],
                  )
                  counter = 0
                  temp = set()
                  for token_pred, mapping, lt in zip(
                      token_preds, mappings, logit
                  ):
                      if mapping != -1 and mapping not in temp:
                          temp.add(mapping)
                          word_offset.append(list(offsets[counter]))
                          pred_one_sentence.append(token_pred)
                          pred_proba.append(lt)
                          counter += 1
                  ner_pred.append(
                      (pred_one_sentence, word_offset, pred_proba)
                  )
          return ner_pred
      elif ret_type == SEMANTIC_MASK:
          masks = [ele[SEMANTIC_MASK] for ele in outputs]
          ret = torch.cat(masks)
      else:
          raise ValueError(f"Unknown return type: {ret_type}")
  
      if as_ndarray:
          if isinstance(ret, torch.Tensor):
              ret = tensor_to_ndarray(ret)
          elif isinstance(ret, dict):
              ret = {k: tensor_to_ndarray(v) for k, v in ret.items()}
          else:
              raise ValueError(f"Unsupported ret type: {type(ret)}")
      return ret
  
file_path: autogluon/multimodal/src/autogluon/multimodal/utils/inference.py
imports: import logging
  from typing import Callable, Dict, List, Optional, Tuple, Union
  import pandas
  import torch
  from omegaconf import OmegaConf
  from scipy.special import softmax
  from torch import nn
  from ..constants import BBOX, COLUMN_FEATURES, FEATURES, IMAGE, IMAGE_META, LOGITS, MASKS, NER_ANNOTATION, NER_RET, OVD_RET, PROBABILITY, PROMPT, QUERY, RESPONSE, SCORE, SEMANTIC_MASK, TEXT, TOKEN_WORD_MAPPING, WORD_OFFSETS
  from ..data.preprocess_dataframe import MultiModalFeaturePreprocessor
  from ..data.utils import apply_data_processor, apply_df_preprocessor, get_collate_fn, get_per_sample_features
  from ..models.utils import run_model
  from .environment import get_precision_context, move_to_device
  from .matcher import compute_matching_probability
  from .misc import tensor_to_ndarray
label_desc: Use image node_id 1 for calling a global function with example usage: extract_from_output(outputs, ret_type, as_ndarray) and returns: ret, unknown, ovd_pred, unknown, unknown, ner_pred