docstr: Adds the given labels to the sample.
  
  The provided ``labels`` can be any of the following:
  
  -   A :class:`fiftyone.core.labels.Label` instance, in which case the
      labels are directly saved in the specified ``label_field``
  
  -   A dict mapping keys to :class:`fiftyone.core.labels.Label`
      instances. In this case, the labels are added as follows::
  
          for key, value in labels.items():
              sample[label_key(key)] = value
  
  -   A dict mapping frame numbers to :class:`fiftyone.core.labels.Label`
      instances. In this case, the provided labels are interpreted as
      frame-level labels that should be added as follows::
  
          sample.frames.merge(
              {
                  frame_number: {label_field: label}
                  for frame_number, label in labels.items()
              }
          )
  
  -   A dict mapping frame numbers to dicts mapping keys to
      :class:`fiftyone.core.labels.Label` instances. In this case, the
      provided labels are interpreted as frame-level labels that should
      be added as follows::
  
          sample.frames.merge(
              {
                  frame_number: {
                      label_key(key): value
                      for key, value in frame_dict.items()
                  }
                  for frame_number, frame_dict in labels.items()
              }
          )
  
  In the above, the ``label_key`` function maps label dict keys to field
  names, and is defined from ``label_field`` as follows::
  
      if isinstance(label_field, dict):
          label_key = lambda k: label_field.get(k, k)
      elif label_field is not None:
          label_key = lambda k: label_field + "_" + k
      else:
          label_key = lambda k: k
  
  Args:
      labels: a :class:`fiftyone.core.labels.Label` or dict of labels per
          the description above
      label_field (None): the sample field, prefix, or dict defining in
          which field(s) to save the labels
      confidence_thresh (None): an optional confidence threshold to apply
          to any applicable labels before saving them
      expand_schema (True): whether to dynamically add new fields
          encountered to the dataset schema. If False, an error is raised
          if any fields are not in the dataset schema
      validate (True): whether to validate values for existing fields
      dynamic (False): whether to declare dynamic attributes
code: def add_labels(
      self,
      labels,
      label_field=None,
      confidence_thresh=None,
      expand_schema=True,
      validate=True,
      dynamic=False,
  ):
      """Adds the given labels to the sample.
  
      The provided ``labels`` can be any of the following:
  
      -   A :class:`fiftyone.core.labels.Label` instance, in which case the
          labels are directly saved in the specified ``label_field``
  
      -   A dict mapping keys to :class:`fiftyone.core.labels.Label`
          instances. In this case, the labels are added as follows::
  
              for key, value in labels.items():
                  sample[label_key(key)] = value
  
      -   A dict mapping frame numbers to :class:`fiftyone.core.labels.Label`
          instances. In this case, the provided labels are interpreted as
          frame-level labels that should be added as follows::
  
              sample.frames.merge(
                  {
                      frame_number: {label_field: label}
                      for frame_number, label in labels.items()
                  }
              )
  
      -   A dict mapping frame numbers to dicts mapping keys to
          :class:`fiftyone.core.labels.Label` instances. In this case, the
          provided labels are interpreted as frame-level labels that should
          be added as follows::
  
              sample.frames.merge(
                  {
                      frame_number: {
                          label_key(key): value
                          for key, value in frame_dict.items()
                      }
                      for frame_number, frame_dict in labels.items()
                  }
              )
  
      In the above, the ``label_key`` function maps label dict keys to field
      names, and is defined from ``label_field`` as follows::
  
          if isinstance(label_field, dict):
              label_key = lambda k: label_field.get(k, k)
          elif label_field is not None:
              label_key = lambda k: label_field + "_" + k
          else:
              label_key = lambda k: k
  
      Args:
          labels: a :class:`fiftyone.core.labels.Label` or dict of labels per
              the description above
          label_field (None): the sample field, prefix, or dict defining in
              which field(s) to save the labels
          confidence_thresh (None): an optional confidence threshold to apply
              to any applicable labels before saving them
          expand_schema (True): whether to dynamically add new fields
              encountered to the dataset schema. If False, an error is raised
              if any fields are not in the dataset schema
          validate (True): whether to validate values for existing fields
          dynamic (False): whether to declare dynamic attributes
      """
      if isinstance(label_field, dict):
          label_key = lambda k: label_field.get(k, k)
      elif label_field is not None:
          label_key = lambda k: label_field + "_" + k
      else:
          label_key = lambda k: k
  
      if confidence_thresh is not None:
          labels = _apply_confidence_thresh(labels, confidence_thresh)
  
      if _is_frames_dict(labels):
          if self.media_type != fomm.VIDEO:
              raise ValueError(
                  "Cannot add frame labels to non-video samples"
              )
  
          if isinstance(next(iter(labels.values())), dict):
              # Multiple frame-level fields
              self.frames.merge(
                  {
                      frame_number: {
                          label_key(fname): flabel
                          for fname, flabel in frame_dict.items()
                      }
                      for frame_number, frame_dict in labels.items()
                  },
                  expand_schema=expand_schema,
                  validate=validate,
                  dynamic=dynamic,
              )
          elif label_field is None:
              raise ValueError(
                  "A `label_field` must be provided in order to add labels "
                  "to a single frame-level field"
              )
          else:
              # Single frame-level field
              self.frames.merge(
                  {
                      frame_number: {label_field: label}
                      for frame_number, label in labels.items()
                  },
                  expand_schema=expand_schema,
                  validate=validate,
                  dynamic=dynamic,
              )
  
      elif isinstance(labels, dict):
          # Multiple sample-level fields
          self.update_fields(
              {label_key(k): v for k, v in labels.items()},
              expand_schema=expand_schema,
              validate=validate,
              dynamic=dynamic,
          )
      elif labels is not None:
          if label_field is None:
              raise ValueError(
                  "A `label_field` must be provided in order to add labels "
                  "to a single sample field"
              )
  
          # Single sample-level field
          self.set_field(
              label_field,
              labels,
              create=expand_schema,
              validate=validate,
              dynamic=dynamic,
          )
  
imports: import os
  from bson import ObjectId
  from fiftyone.core.document import Document, DocumentView
  import fiftyone.core.frame
  import fiftyone.core.frame_utils
  import fiftyone.core.labels
  import fiftyone.core.metadata
  import fiftyone.core.media
  import fiftyone.core.odm
  import fiftyone.core.utils
  from fiftyone.core.singletons import SampleSingleton
label_desc: Use image node_id 14 for calling the _SampleMixin obj's underlying member method code with example usage: obj.add_labels(labels, label_field, confidence_thresh, expand_schema, validate, dynamic) without return types