code: def _select_targets(
      dataset: SupportedDataset, indices: Optional[List[int]]
  ) -> Sequence[TTargetType]:
      if hasattr(dataset, "targets"):
          # Standard supported dataset
          found_targets = dataset.targets  # type: ignore
      elif hasattr(dataset, "tensors"):
          # Support for PyTorch TensorDataset
          if len(dataset.tensors) < 2:  # type: ignore
              raise ValueError(
                  "Tensor dataset has not enough tensors: "
                  "at least 2 are required."
              )
          found_targets = dataset.tensors[1]  # type: ignore
      else:
          raise ValueError(
              "Unsupported dataset: must have a valid targets field "
              "or has to be a Tensor Dataset with at least 2 "
              "Tensors"
          )
  
      if indices is not None:
          found_targets = SubSequence(found_targets, indices=indices)
  
      return found_targets
  
imports: from functools import partial
  import torch
  from torch.utils.data.dataset import Subset, ConcatDataset, TensorDataset
  from avalanche.benchmarks.utils.utils import TaskSet, _count_unique, find_common_transforms_group, _init_task_labels, _init_transform_groups, _split_user_def_targets, _split_user_def_task_label, _traverse_supported_dataset
  from avalanche.benchmarks.utils.data import AvalancheDataset
  from avalanche.benchmarks.utils.transform_groups import TransformGroupDef, DefaultTransformGroups, XTransform, YTransform
  from avalanche.benchmarks.utils.data_attribute import DataAttribute
  from avalanche.benchmarks.utils.dataset_utils import SubSequence
  from avalanche.benchmarks.utils.flat_data import ConstantSequence
  from avalanche.benchmarks.utils.dataset_definitions import ISupportedClassificationDataset, ITensorDataset, IDatasetWithTargets
  from typing import List, Any, Sequence, Union, Optional, TypeVar, Callable, Dict, Tuple, Mapping, overload
label_desc: Use image node_id 18 for calling a global function with example usage: _select_targets(dataset, indices) and returns: found_targets