code: def test_schema_meta_validation(model_fn):
      if model_fn.__name__ == "maskrcnn_resnet50_fpn_v2":
          pytest.skip(
              reason="FIXME https://github.com/pytorch/vision/issues/7349"
          )
  
      # list of all possible supported high-level fields for weights meta-data
      permitted_fields = {
          "backend",
          "categories",
          "keypoint_names",
          "license",
          "_metrics",
          "min_size",
          "min_temporal_size",
          "num_params",
          "recipe",
          "unquantized",
          "_docs",
          "_ops",
          "_file_size",
      }
      # mandatory fields for each computer vision task
      classification_fields = {
          "categories",
          ("_metrics", "ImageNet-1K", "acc@1"),
          ("_metrics", "ImageNet-1K", "acc@5"),
      }
      defaults = {
          "all": {
              "_metrics",
              "min_size",
              "num_params",
              "recipe",
              "_docs",
              "_file_size",
              "_ops",
          },
          "models": classification_fields,
          "detection": {
              "categories",
              ("_metrics", "COCO-val2017", "box_map"),
          },
          "quantization": classification_fields
          | {"backend", "unquantized"},
          "segmentation": {
              "categories",
              ("_metrics", "COCO-val2017-VOC-labels", "miou"),
              ("_metrics", "COCO-val2017-VOC-labels", "pixel_acc"),
          },
          "video": {
              "categories",
              ("_metrics", "Kinetics-400", "acc@1"),
              ("_metrics", "Kinetics-400", "acc@5"),
          },
          "optical_flow": set(),
      }
      model_name = model_fn.__name__
      module_name = model_fn.__module__.split(".")[-2]
      expected_fields = defaults["all"] | defaults[module_name]
  
      weights_enum = get_model_weights(model_fn)
      if len(weights_enum) == 0:
          pytest.skip(
              f"Model '{model_name}' doesn't have any pre-trained weights."
          )
  
      problematic_weights = {}
      incorrect_meta = []
      bad_names = []
      for w in weights_enum:
          actual_fields = set(w.meta.keys())
          actual_fields |= set(
              ("_metrics", dataset, metric_key)
              for dataset in w.meta.get("_metrics", {}).keys()
              for metric_key in w.meta.get("_metrics", {})
              .get(dataset, {})
              .keys()
          )
          missing_fields = expected_fields - actual_fields
          unsupported_fields = set(w.meta.keys()) - permitted_fields
          if missing_fields or unsupported_fields:
              problematic_weights[w] = {
                  "missing": missing_fields,
                  "unsupported": unsupported_fields,
              }
  
          if w == weights_enum.DEFAULT or any(
              w.meta[k] != weights_enum.DEFAULT.meta[k]
              for k in ["num_params", "_ops"]
          ):
              if module_name == "quantization":
                  # parameters() count doesn't work well with quantization, so we check against the non-quantized
                  unquantized_w = w.meta.get("unquantized")
                  if unquantized_w is not None:
                      if w.meta.get(
                          "num_params"
                      ) != unquantized_w.meta.get("num_params"):
                          incorrect_meta.append((w, "num_params"))
  
                      # the methodology for quantized ops count doesn't work as well, so we take unquantized FLOPs
                      # instead
                      if w.meta["_ops"] != unquantized_w.meta.get(
                          "_ops"
                      ):
                          incorrect_meta.append((w, "_ops"))
  
              else:
                  # loading the model and using it for parameter and ops verification
                  model = model_fn(weights=w)
  
                  if w.meta.get("num_params") != sum(
                      p.numel() for p in model.parameters()
                  ):
                      incorrect_meta.append((w, "num_params"))
  
                  kwargs = {}
                  if model_name in detection_models_input_dims:
                      # detection models have non default height and width
                      height, width = detection_models_input_dims[
                          model_name
                      ]
                      kwargs = {"height": height, "width": width}
  
                  if not model_fn.__name__.startswith("vit"):
                      # FIXME: https://github.com/pytorch/vision/issues/7871
                      calculated_ops = get_ops(
                          model=model, weight=w, **kwargs
                      )
                      if calculated_ops != w.meta["_ops"]:
                          incorrect_meta.append((w, "_ops"))
  
          if not w.name.isupper():
              bad_names.append(w)
  
          if get_file_size_mb(w) != w.meta.get("_file_size"):
              incorrect_meta.append((w, "_file_size"))
  
      assert not problematic_weights
      assert not incorrect_meta
      assert not bad_names
  
imports: import copy
  import os
  import pickle
  import pytest
  import test_models
  import torch
  from common_extended_utils import get_file_size_mb, get_ops
  from torchvision import models
  from torchvision.models import get_model_weights, Weights, WeightsEnum
  from torchvision.models._utils import handle_legacy_interface
  from torchvision.models.detection.backbone_utils import mobilenet_backbone, resnet_fpn_backbone
label_desc: Use image node_id 11 for calling a global function with example usage: test_schema_meta_validation(model_fn) without return types