code: def _init_targets(
      dataset, targets, check_shape=True
  ) -> Optional[DataAttribute[TTargetType]]:
      if targets is not None:
          # User defined targets always take precedence
          if isinstance(targets, int):
              targets = ConstantSequence(targets, len(dataset))
          elif len(targets) != len(dataset) and check_shape:
              raise ValueError(
                  "Invalid amount of target labels. It must be equal to the "
                  "number of patterns in the dataset. Got {}, expected "
                  "{}!".format(len(targets), len(dataset))
              )
          return DataAttribute(targets, "targets")
  
      targets = _traverse_supported_dataset(dataset, _select_targets)
  
      if targets is not None:
          if isinstance(targets, torch.Tensor):
              targets = targets.tolist()
  
      if targets is None:
          return None
  
      return DataAttribute(targets, "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 6 for calling a global function with example usage: _init_targets(dataset, targets, check_shape) and returns: DataAttribute, DataAttribute, None