code: def inject_minigalleries(app, what, name, obj, options, lines):
      """Inject a minigallery into a docstring.
  
      This avoids having to manually write the .. minigallery directive for every item we want a minigallery for,
      as it would be easy to miss some.
  
      This callback is called after the .. auto directives (like ..autoclass) have been processed,
      and modifies the lines parameter inplace to add the .. minigallery that will show which examples
      are using which object.
  
      It's a bit hacky, but not *that* hacky when you consider that the recommended way is to do pretty much the same,
      but instead with templates using autosummary (which we don't want to use):
      (https://sphinx-gallery.github.io/stable/configuration.html#auto-documenting-your-api-with-links-to-examples)
  
      For docs on autodoc-process-docstring, see the autodoc docs:
      https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html
      """
  
      if what in ("class", "function"):
          lines.append(f".. minigallery:: {name}")
          lines.append(
              f"    :add-heading: Examples using ``{name.split('.')[-1]}``:"
          )
          # avoid heading entirely to avoid warning. As a bonud it actually renders better
          lines.append("    :heading-level: 9")
          lines.append("\n")
  
imports: import os
  import sys
  import textwrap
  from copy import copy
  from pathlib import Path
  import pytorch_sphinx_theme
  import torchvision
  import torchvision.models
  from sphinx_gallery.sorting import ExplicitOrder
  from tabulate import tabulate
  from sphinx_gallery import gen_rst
  from docutils import nodes
  from sphinx import addnodes
  from sphinx.util.docfields import TypedField
label_desc: Use image node_id 2 for calling a global function with example usage: inject_minigalleries(app, what, name, obj, options, lines) without return types