{
  "id": "task_libraries:computer-vision/python",
  "path": "/exapedia/python-computer-vision-libraries",
  "template": {
    "id": "task_libraries",
    "version": 4
  },
  "title": "Python computer vision libraries",
  "answer": [
    {
      "t": "text",
      "text": "Python computer vision libraries load images and video, transform them, and extract information such as objects, faces, and text. Most current pipelines pass each image through a trained neural network rather than hand-written filters. These libraries let apps and AI agents detect, classify, and measure what appears in images."
    }
  ],
  "breadcrumb": [
    {
      "label": "Tools"
    },
    {
      "label": "Python computer vision libraries"
    }
  ],
  "sections": [
    {
      "id": "libraries_popularity",
      "anchor": "popularity",
      "heading": "Popularity",
      "blocks": [
        {
          "b": "table",
          "columns": [
            "Library",
            "Monthly downloads",
            "Stars",
            "Last release",
            "License"
          ],
          "rows": [
            [
              [
                {
                  "t": "link",
                  "href": "#pillow",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F132"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F133"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F141"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F136"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F134"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#transformers",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F150"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F151"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F159"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F154"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F152"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#opencv-python-headless",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F168"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F169"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F177"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F172"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F170"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#scikit-image",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F187"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F188"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F194"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F191"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F189"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#torchvision",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F203"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F204"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F210"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F207"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F205"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#tensorflow",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F219"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F220"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F228"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F223"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F221"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#keras",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F233"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F234"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F242"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F237"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F235"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#timm",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F252"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F253"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F261"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F256"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F254"
                }
              ]
            ]
          ],
          "variant": "pop",
          "caption": [
            {
              "t": "text",
              "text": "Downloads: "
            },
            {
              "t": "text",
              "text": "PyPI"
            },
            {
              "t": "text",
              "text": ", last thirty days. Stars and releases: GitHub. Amber: no release in over a year."
            }
          ]
        }
      ],
      "note": [
        {
          "t": "link",
          "href": "#pillow",
          "label": [
            {
              "t": "text",
              "text": "Pillow"
            }
          ]
        },
        {
          "t": "text",
          "text": ", whose count covers all image handling, has the most monthly downloads in this comparison, at "
        },
        {
          "t": "fact",
          "fact": "F133"
        },
        {
          "t": "text",
          "text": "."
        }
      ]
    },
    {
      "id": "libraries_capabilities",
      "anchor": "capabilities",
      "heading": "Capabilities",
      "blocks": [
        {
          "b": "table",
          "columns": [
            "Library",
            "Neural model loader",
            "PyTorch required"
          ],
          "rows": [
            [
              [
                {
                  "t": "link",
                  "href": "#pillow",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F132"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F142"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F143"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#transformers",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F150"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F160"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F161"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#opencv-python-headless",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F168"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F178"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F179"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#scikit-image",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F187"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F195"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F196"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#torchvision",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F203"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F211"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F212"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#tensorflow",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F219"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F229"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F230"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#keras",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F233"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F243"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F244"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#timm",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F252"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F262"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F263"
                }
              ]
            ]
          ],
          "variant": "cap"
        }
      ]
    },
    {
      "id": "libraries_entries",
      "anchor": "libraries",
      "heading": "Libraries",
      "blocks": [
        {
          "b": "entry",
          "anchor": "pillow",
          "name": [
            {
              "t": "fact",
              "fact": "F132"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/python-pillow/Pillow"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/pillow"
            },
            {
              "label": "Docs",
              "href": "https://pillow.readthedocs.io/en/stable/"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F139"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F133"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F141"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F135"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F134"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://pillow.readthedocs.io/en/stable/",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F132"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F148"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F149"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/gradio-app/gradio",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F148"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "def resize_and_crop(img, size, crop_type=\"center\"):\n    \"\"\"\n    Resize and crop an image to fit the specified size.\n    args:\n        size: `(width, height)` tuple. Pass `None` for either width or height\n        to only crop and resize the other.\n        crop_type: can be 'top', 'middle' or 'bottom', depending on this\n            value, the image will cropped getting the 'top/left', 'middle' or\n            'bottom/right' of the image to fit the size.\n    raises:\n        ValueError: if an invalid `crop_type` is provided.\n    \"\"\"\n    if crop_type == \"top\":\n        center = (0, 0)\n    elif crop_type == \"center\":\n        center = (0.5, 0.5)\n    else:\n        raise ValueError\n\n    resize = list(size)\n    if size[0] is None:\n        resize[0] = img.size[0]\n    if size[1] is None:\n        resize[1] = img.size[1]\n    return ImageOps.fit(img, resize, centering=center)  # type: ignore\n",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/gradio-app/gradio/blob/ec06278ed72e5eb73494a9d171ca851d553dc82a/gradio/processing_utils.py#L737-L761",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F147"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=pillow%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F132"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "from PIL import Image\nim = Image.open(\"hopper.ppm\")\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://pillow.readthedocs.io/en/stable/handbook/tutorial.html",
                  "label": [
                    {
                      "t": "text",
                      "text": "tutorial.rst"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F137"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "transformers",
          "name": [
            {
              "t": "fact",
              "fact": "F150"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/huggingface/transformers"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/transformers"
            },
            {
              "label": "Docs",
              "href": "https://huggingface.co/docs/transformers/en/tasks/image_classification"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F157"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F151"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F159"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F153"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F152"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://huggingface.co/docs/transformers/en/tasks/image_classification",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F150"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F166"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F167"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/obss/sahi",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F166"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "def perform_inference(self, image: list | np.ndarray):\n    \"\"\"Prediction is performed using self.model and the prediction result is set to self._original_predictions.\n\n    Args:\n        image: np.ndarray\n            A numpy array that contains the image to be predicted. 3 channel image should be in RGB order.\n    \"\"\"\n    import torch\n\n    # Confirm model is loaded\n    if self.model is None or self.processor is None:\n        raise RuntimeError(\"Model is not loaded, load it by calling .load_model()\")\n\n    with torch.no_grad():\n        inputs = self.processor(images=image, return_tensors=\"pt\")\n        inputs[\"pixel_values\"] = inputs.pixel_values.to(self.device)\n        if hasattr(inputs, \"pixel_mask\"):\n            inputs[\"pixel_mask\"] = inputs.pixel_mask.to(self.device)\n        outputs = self.model(**inputs)\n\n    if isinstance(image, list):\n        self._image_shapes = [img.shape for img in image]\n    else:\n        self._image_shapes = [image.shape]\n    self._original_predictions = outputs",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/obss/sahi/blob/8af413e53115525e4af1cfbc1873019ccb548434/sahi/models/huggingface.py",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F165"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=transformers%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F150"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "from transformers import CLIPVisionConfig, CLIPVisionModelWithProjection\nconfiguration = CLIPVisionConfig()\nmodel = CLIPVisionModelWithProjection(configuration)\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://huggingface.co/docs/transformers/model_doc/clip",
                  "label": [
                    {
                      "t": "text",
                      "text": "clip.md"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F155"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "opencv-python-headless",
          "name": [
            {
              "t": "fact",
              "fact": "F168"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/opencv/opencv-python"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/opencv-python-headless"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F175"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F169"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F177"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F171"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F170"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://github.com/opencv/opencv-python",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F168"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F185"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F186"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/ultralytics/yolov5",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F185"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "def letterbox(im, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True, stride=32):\n    \"\"\"Resizes and pads image to new_shape with stride-multiple constraints, returns resized image, ratio, padding.\"\"\"\n    shape = im.shape[:2]  # current shape [height, width]\n    if isinstance(new_shape, int):\n        new_shape = (new_shape, new_shape)\n\n    # Scale ratio (new / old)\n    r = min(new_shape[0] / shape[0], new_shape[1] / shape[1])\n    if not scaleup:  # only scale down, do not scale up (for better val mAP)\n        r = min(r, 1.0)\n\n    # Compute padding\n    ratio = r, r  # width, height ratios\n    new_unpad = round(shape[1] * r), round(shape[0] * r)\n    dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1]  # wh padding\n    if auto:  # minimum rectangle\n        dw, dh = np.mod(dw, stride), np.mod(dh, stride)  # wh padding\n    elif scaleFill:  # stretch\n        dw, dh = 0.0, 0.0\n        new_unpad = (new_shape[1], new_shape[0])\n        ratio = new_shape[1] / shape[1], new_shape[0] / shape[0]  # width, height ratios\n\n    dw /= 2  # divide padding into 2 sides\n    dh /= 2\n\n    if shape[::-1] != new_unpad:  # resize\n        im = cv2.resize(im, new_unpad, interpolation=cv2.INTER_LINEAR)\n    top, bottom = round(dh - 0.1), round(dh + 0.1)\n    left, right = round(dw - 0.1), round(dw + 0.1)\n    im = cv2.copyMakeBorder(im, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color)  # add border\n    return im, ratio, (dw, dh)\n",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/ultralytics/yolov5/blob/cb2f17fd5d790cfdd0c07c25351904df9affbe6e/utils/augmentations.py#L85-L115",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F184"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=opencv-python-headless%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F168"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import cv2\nimage = cv2.imread('input.jpg')\nresized = cv2.resize(image, (320, 240))\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://docs.opencv.org/5.0/main_modules/imgproc_transform.html",
                  "label": [
                    {
                      "t": "text",
                      "text": "imgproc_transform.html"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F173"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "scikit-image",
          "name": [
            {
              "t": "fact",
              "fact": "F187"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/scikit-image/scikit-image"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/scikit-image"
            },
            {
              "label": "Docs",
              "href": "https://scikit-image.org/docs/stable/"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F37"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F188"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F194"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F190"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F189"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://scikit-image.org/docs/stable/",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F187"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F38"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F39"
                }
              ]
            },
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F40"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F41"
                }
              ]
            }
          ],
          "cons": [
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F42"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F43"
                }
              ]
            },
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F44"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F45"
                }
              ]
            }
          ],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F201"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F202"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/sbrunner/deskew",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F201"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "def determine_skew_dev(\n    image: ImageType,\n    sigma: float = 3.0,\n    num_peaks: int = 20,\n    min_angle: float | None = None,  # -np.pi / 2,\n    max_angle: float | None = None,  # np.pi / 2,\n    min_deviation: float = np.pi / 180,\n    angle_pm_90: bool = False,\n) -> tuple[\n    np.float64 | None,\n    tuple[\n        tuple[ImageTypeUint64, list[list[np.float64]], ImageTypeFloat64],\n        tuple[list[Any], list[np.float64], list[np.float64]],\n        tuple[dict[np.float64, int], dict[np.float64, int]],\n    ],\n]:\n    \"\"\"Calculate skew angle.\"\"\"\n    num_angles = round(np.pi / min_deviation)\n    imagergb = rgba2rgb(image) if len(image.shape) == 3 and image.shape[2] == 4 else image  # type: ignore[no-untyped-call]\n    img = rgb2gray(imagergb) if len(imagergb.shape) == 3 else imagergb\n    edges = canny(img, sigma=sigma)  # type: ignore[no-untyped-call]\n    out, angles, distances = hough_line(edges, np.linspace(-np.pi / 2, np.pi / 2, num_angles, endpoint=False))  # type: ignore[no-untyped-call]\n    hough_line_out = (out, angles, distances)\n\n    hspace, angles_peaks, dists = hough_line_peaks(  # type: ignore[no-untyped-call]\n        out,\n        angles,\n        distances,\n        num_peaks=num_peaks,\n        threshold=0.05 * np.max(out),\n    )\n    hough_line_peaks_out = (hspace, angles_peaks, dists)\n\n    if len(angles_peaks) == 0:\n        return None, (hough_line_out, hough_line_peaks_out, ({}, {}))\n\n    freqs_original: dict[np.float64, int] = {}\n    for peak in angles_peaks:\n        freqs_original.setdefault(peak, 0)\n        freqs_original[peak] += 1\n\n    angles_peaks_corrected = [\n        (a % np.pi - np.pi / 2) if angle_pm_90 else ((a + np.pi / 4) % (np.pi / 2) - np.pi / 4)\n        for a in angles_peaks\n    ]\n    angles_peaks_filtred = (\n        [a for a in angles_peaks_corrected if a >= min_angle]\n        if min_angle is not None\n        else angles_peaks_corrected\n    )\n    angles_peaks_filtred = (\n        [a for a in angles_peaks_filtred if a <= max_angle] if max_angle is not None else angles_peaks_filtred\n    )\n    if not angles_peaks_filtred:\n        return None, (hough_line_out, hough_line_peaks_out, ({}, {}))\n\n    freqs: dict[np.float64, int] = {}\n    for peak in angles_peaks_filtred:\n        freqs.setdefault(peak, 0)\n        freqs[peak] += 1\n\n    sorted_keys = sorted(freqs.keys(), key=freqs.get, reverse=True)  # type: ignore[arg-type]\n    max_freq = freqs[sorted_keys[0]]\n\n    angle = None\n    for sorted_key in sorted_keys:\n        if freqs[sorted_key] == max_freq:\n            angle = sorted_key\n            break\n\n    return (\n        angle,\n        (hough_line_out, hough_line_peaks_out, (freqs_original, freqs)),\n    )\n",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/sbrunner/deskew/blob/b362a48f18ccb650d69cd8d7df3d81c31a5410a5/deskew/__init__.py#L28-L101",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F200"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20scikit-image%20to%20resize%20detection%20inputs%2C%20adapt%20scientific%20image%20processing%20and%20build%20paired%20or%20training-time%20image%20transforms&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F187"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import skimage as ski\ncoins = ski.data.coins()\nthreshold_value = ski.filters.threshold_otsu(coins)\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://scikit-image.org/docs/stable/user_guide/getting_started.html",
                  "label": [
                    {
                      "t": "text",
                      "text": "plot_canny.py"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F192"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "torchvision",
          "name": [
            {
              "t": "fact",
              "fact": "F203"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/pytorch/vision"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/torchvision"
            },
            {
              "label": "Docs",
              "href": "https://pytorch.org/vision/stable/models.html"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F64"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F204"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F210"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F206"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F205"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://pytorch.org/vision/stable/models.html",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F203"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F65"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F66"
                }
              ]
            },
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F67"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F68"
                }
              ]
            }
          ],
          "cons": [
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F69"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F70"
                }
              ]
            },
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F71"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F72"
                }
              ]
            }
          ],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F217"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F218"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/lucidrains/denoising-diffusion-pytorch",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F217"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "def __init__(\n    self,\n    folder,\n    image_size,\n    exts = ['jpg', 'jpeg', 'png', 'tiff'],\n    augment_horizontal_flip = False,\n    convert_image_to = None\n):\n    super().__init__()\n    self.folder = folder\n    self.image_size = image_size\n    self.paths = [p for ext in exts for p in Path(f'{folder}').glob(f'**/*.{ext}')]\n\n    maybe_convert_fn = partial(convert_image_to_fn, convert_image_to) if exists(convert_image_to) else nn.Identity()\n\n    self.transform = T.Compose([\n        T.Lambda(maybe_convert_fn),\n        T.Resize(image_size),\n        T.RandomHorizontalFlip() if augment_horizontal_flip else nn.Identity(),\n        T.CenterCrop(image_size),\n        T.ToTensor()\n    ])\n",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/lucidrains/denoising-diffusion-pytorch/blob/c8155b1dc622e3f1ef0d53dc6e5a570ca105bcec/denoising_diffusion_pytorch/denoising_diffusion_pytorch.py#L854-L875",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F216"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20torchvision%20to%20resize%20detection%20inputs%2C%20adapt%20scientific%20image%20processing%20and%20build%20paired%20or%20training-time%20image%20transforms&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F203"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "from torchvision.models import resnet50, ResNet50_Weights\nmodel = resnet50(weights=None)\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://pytorch.org/vision/stable/models.html",
                  "label": [
                    {
                      "t": "text",
                      "text": "plot_transforms_getting_started.py"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F208"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "tensorflow",
          "name": [
            {
              "t": "fact",
              "fact": "F219"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/tensorflow/tensorflow"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/tensorflow"
            },
            {
              "label": "Docs",
              "href": "https://www.tensorflow.org/api_docs/python/tf/image"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F226"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F220"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F228"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F222"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F221"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://www.tensorflow.org/api_docs/python/tf/image",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F219"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import tensorflow as tf\nimage = tf.zeros([224, 224, 3])\nflipped = tf.image.flip_left_right(image)\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://www.tensorflow.org/api_docs/python/tf/image/flip_left_right",
                  "label": [
                    {
                      "t": "text",
                      "text": "image_ops_impl.py"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=tensorflow%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "Find projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F219"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F224"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "keras",
          "name": [
            {
              "t": "fact",
              "fact": "F233"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/keras-team/keras"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/keras"
            },
            {
              "label": "Docs",
              "href": "https://keras.io/getting_started/"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F240"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F234"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F242"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F236"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F235"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://keras.io/getting_started/",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F233"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F250"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F251"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/keras-team/keras-io",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F250"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "def make_model(input_shape, num_classes):\n    inputs = keras.Input(shape=input_shape)\n\n    # Entry block\n    x = layers.Rescaling(1.0 / 255)(inputs)\n    x = layers.Conv2D(128, 3, strides=2, padding=\"same\")(x)\n    x = layers.BatchNormalization()(x)\n    x = layers.Activation(\"relu\")(x)\n\n    previous_block_activation = x  # Set aside residual\n\n    for size in [256, 512, 728]:\n        x = layers.Activation(\"relu\")(x)\n        x = layers.SeparableConv2D(size, 3, padding=\"same\")(x)\n        x = layers.BatchNormalization()(x)\n\n        x = layers.Activation(\"relu\")(x)\n        x = layers.SeparableConv2D(size, 3, padding=\"same\")(x)\n        x = layers.BatchNormalization()(x)\n\n        x = layers.MaxPooling2D(3, strides=2, padding=\"same\")(x)\n\n        # Project residual\n        residual = layers.Conv2D(size, 1, strides=2, padding=\"same\")(\n            previous_block_activation\n        )\n        x = layers.add([x, residual])  # Add back residual\n        previous_block_activation = x  # Set aside next residual\n\n    x = layers.SeparableConv2D(1024, 3, padding=\"same\")(x)\n    x = layers.BatchNormalization()(x)\n    x = layers.Activation(\"relu\")(x)\n\n    x = layers.GlobalAveragePooling2D()(x)\n    if num_classes == 2:\n        units = 1\n    else:\n        units = num_classes\n\n    x = layers.Dropout(0.25)(x)\n    # We specify activation=None so as to return logits\n    outputs = layers.Dense(units, activation=None)(x)\n    return keras.Model(inputs, outputs)\n",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/keras-team/keras-io/blob/f5891b3cd4df69f6bd5a3c26ea92310f3a973626/examples/vision/image_classification_from_scratch.py#L236-L278",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F249"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=keras%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F233"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "from keras.applications.resnet50 import ResNet50\nmodel = ResNet50(weights='imagenet')\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://keras.io/api/applications/",
                  "label": [
                    {
                      "t": "text",
                      "text": "index.md"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F238"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "timm",
          "name": [
            {
              "t": "fact",
              "fact": "F252"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/huggingface/pytorch-image-models"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/timm"
            },
            {
              "label": "Docs",
              "href": "https://huggingface.co/docs/timm/quickstart"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F259"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F253"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F261"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F255"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F254"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://huggingface.co/docs/timm/quickstart",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F252"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F268"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F269"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/huggingface/transformers",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F268"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "def __init__(\n    self,\n    pretrained_cfg: dict[str, Any],\n    architecture: str | None = None,\n    **kwargs,\n):\n    super().__init__(architecture=architecture)\n\n    self.data_config = timm.data.resolve_data_config(pretrained_cfg, model=None, verbose=False)\n    self.val_transforms = timm.data.create_transform(**self.data_config, is_training=False)\n\n    # useful for training\n    self.train_transforms = timm.data.create_transform(**self.data_config, is_training=True)\n\n    # If `ToTensor` is in the transforms, then the input should be numpy array or PIL image.\n    # Otherwise, the input can be a tensor. In later timm versions, `MaybeToTensor` is used\n    # which can handle both numpy arrays / PIL images and tensors.\n    self._not_supports_tensor_input = any(\n        transform.__class__.__name__ == \"ToTensor\" for transform in self.val_transforms.transforms\n    )\n",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/huggingface/transformers/blob/8f9c231c86db3e41b4b09cd0df90965c9b951dad/src/transformers/models/timm_wrapper/image_processing_timm_wrapper.py#L52-L71",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F267"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=timm%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F252"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import timm\nm = timm.create_model('mobilenetv3_large_100', pretrained=True)\nm.eval()\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://huggingface.co/docs/timm/quickstart",
                  "label": [
                    {
                      "t": "text",
                      "text": "quickstart.mdx"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F257"
            }
          ]
        }
      ]
    }
  ],
  "questions": [
    {
      "q": "Which Python computer vision library should I use?",
      "a": [
        {
          "t": "link",
          "href": "#opencv-python-headless",
          "label": [
            {
              "t": "text",
              "text": "opencv-python-headless"
            }
          ]
        },
        {
          "t": "text",
          "text": " suits classical image processing and video on servers. "
        },
        {
          "t": "link",
          "href": "#torchvision",
          "label": [
            {
              "t": "text",
              "text": "TorchVision"
            }
          ]
        },
        {
          "t": "text",
          "text": " and "
        },
        {
          "t": "link",
          "href": "#timm",
          "label": [
            {
              "t": "text",
              "text": "timm"
            }
          ]
        },
        {
          "t": "text",
          "text": " suit training and running image models in PyTorch. "
        },
        {
          "t": "link",
          "href": "#transformers",
          "label": [
            {
              "t": "text",
              "text": "Transformers"
            }
          ]
        },
        {
          "t": "text",
          "text": " suits pretrained vision and multimodal models."
        }
      ]
    },
    {
      "q": "What is OpenCV?",
      "a": [
        {
          "t": "text",
          "text": "OpenCV is an open-source computer vision library with Python bindings for image processing, video capture, and feature detection. The "
        },
        {
          "t": "link",
          "href": "#opencv-python-headless",
          "label": [
            {
              "t": "text",
              "text": "headless package"
            }
          ]
        },
        {
          "t": "text",
          "text": " drops GUI dependencies for servers."
        }
      ]
    },
    {
      "q": "What is Pillow?",
      "a": [
        {
          "t": "link",
          "href": "#pillow",
          "label": [
            {
              "t": "text",
              "text": "Pillow"
            }
          ]
        },
        {
          "t": "text",
          "text": " is the maintained fork of the Python Imaging Library. It opens, converts, resizes, and saves images in many formats."
        }
      ]
    },
    {
      "q": "What is timm?",
      "a": [
        {
          "t": "link",
          "href": "#timm",
          "label": [
            {
              "t": "text",
              "text": "timm"
            }
          ]
        },
        {
          "t": "text",
          "text": ", short for PyTorch Image Models, is a collection of pretrained image models with training and inference scripts."
        }
      ]
    },
    {
      "q": "What is torchvision?",
      "a": [
        {
          "t": "link",
          "href": "#torchvision",
          "label": [
            {
              "t": "text",
              "text": "TorchVision"
            }
          ]
        },
        {
          "t": "text",
          "text": " provides PyTorch vision datasets, pretrained models, and image transforms."
        }
      ]
    },
    {
      "q": "Keras vs TensorFlow: what is the difference?",
      "a": [
        {
          "t": "link",
          "href": "#keras",
          "label": [
            {
              "t": "text",
              "text": "Keras"
            }
          ]
        },
        {
          "t": "text",
          "text": " is a high-level model API that runs on TensorFlow, JAX, or PyTorch. "
        },
        {
          "t": "link",
          "href": "#tensorflow",
          "label": [
            {
              "t": "text",
              "text": "TensorFlow"
            }
          ]
        },
        {
          "t": "text",
          "text": " is a full machine learning framework that Keras can use as its backend."
        }
      ]
    }
  ],
  "facts": {
    "F1": {
      "label": "Library name, opencv-python",
      "display": "OpenCV",
      "asOf": "2026-11-17"
    },
    "F2": {
      "label": "Monthly downloads, opencv-python",
      "display": "33.5M",
      "asOf": "2026-11-16"
    },
    "F3": {
      "label": "License, opencv-python",
      "display": "Apache-2.0",
      "asOf": "2026-11-17"
    },
    "F4": {
      "label": "Package release, opencv-python",
      "display": "5.0.0.93, Jul 2026",
      "asOf": "2026-07-02"
    },
    "F5": {
      "label": "Package release date, opencv-python",
      "display": "Jul 2026",
      "asOf": "2026-07-02"
    },
    "F6": {
      "label": "Repository stars, opencv-python",
      "display": "91.6K",
      "asOf": "2026-11-17"
    },
    "F7": {
      "label": "Reads image files, opencv-python",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F8": {
      "label": "Runs GPU transforms, opencv-python",
      "display": "Unsupported",
      "asOf": "2026-11-17"
    },
    "F9": {
      "label": "Loads pretrained detectors, opencv-python",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F10": {
      "label": "Output formats, opencv-python",
      "display": "PNG",
      "asOf": "2026-11-17"
    },
    "F11": {
      "label": "Install, opencv-python",
      "display": "pip install opencv-python",
      "asOf": "2026-11-17"
    },
    "F12": {
      "label": "What it does, opencv-python",
      "display": "Provides prebuilt Python bindings for OpenCV image processing, computer vision, and pretrained cascade detection.",
      "asOf": "2026-11-17"
    },
    "F13": {
      "label": "strengths lead, opencv-python",
      "display": "Shares image data with NumPy",
      "asOf": "2026-11-17"
    },
    "F14": {
      "label": "strengths, opencv-python",
      "display": "Use OpenCV image arrays directly in NumPy-based processing.",
      "asOf": "2026-11-17"
    },
    "F15": {
      "label": "strengths lead, opencv-python",
      "display": "Includes ready-to-load face cascades",
      "asOf": "2026-11-17"
    },
    "F16": {
      "label": "strengths, opencv-python",
      "display": "Load the bundled Haar cascade files for classical face detection.",
      "asOf": "2026-11-17"
    },
    "F17": {
      "label": "limitations lead, opencv-python",
      "display": "GPU needs a custom build",
      "asOf": "2026-11-17"
    },
    "F18": {
      "label": "limitations, opencv-python",
      "display": "Standard Python wheels contain CPU-only builds.",
      "asOf": "2026-11-17"
    },
    "F19": {
      "label": "limitations lead, opencv-python",
      "display": "Color channels differ from RGB",
      "asOf": "2026-11-17"
    },
    "F20": {
      "label": "limitations, opencv-python",
      "display": "Convert BGR channel order when sharing color images with scikit-image.",
      "asOf": "2026-11-17"
    },
    "F21": {
      "label": "Quickstart, opencv-python",
      "display": "from __future__ import print_function\nimport cv2 as cv\nimport argparse\n\nmax_value = 255\nmax_type = 4\nmax_binary_value = 255\ntrackbar_type = 'Type: \\n 0: Binary \\n 1: Binary Inverted \\n 2: Truncate \\n 3: To Zero \\n 4: To Zero Inverted'\ntrackbar_value = 'Value'\nwindow_name = 'Threshold Demo'\n\n## [Threshold_Demo]\ndef Threshold_Demo(val):\n    #0: Binary\n    #1: Binary Inverted\n    #2: Threshold Truncated\n    #3: Threshold to Zero\n    #4: Threshold to Zero Inverted\n    threshold_type = cv.getTrackbarPos(trackbar_type, window_name)\n    threshold_value = cv.getTrackbarPos(trackbar_value, window_name)\n    _, dst = cv.threshold(src_gray, threshold_value, max_binary_value, threshold_type )\n    cv.imshow(window_name, dst)\n## [Threshold_Demo]\n\nparser = argparse.ArgumentParser(description='Code for Basic Thresholding Operations tutorial.')\nparser.add_argument('--input', help='Path to input image.', default='stuff.jpg')\nargs = parser.parse_args()\n\n## [load]\n# Load an image\nsrc = cv.imread(cv.samples.findFile(args.input))\nif src is None:\n    print('Could not open or find the image: ', args.input)\n    exit(0)\n# Convert the image to Gray\nsrc_gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)\n## [load]\n\n## [window]\n# Create a window to display results\ncv.namedWindow(window_name)\n## [window]\n\n## [trackbar]\n# Create Trackbar to choose type of Threshold\ncv.createTrackbar(trackbar_type, window_name , 3, max_type, Threshold_Demo)\n# Create Trackbar to choose Threshold value\ncv.createTrackbar(trackbar_value, window_name , 0, max_value, Threshold_Demo)\n## [trackbar]\n\n# Call the function to initialize\nThreshold_Demo(0)\n# Wait until user finishes program\ncv.waitKey()\n",
      "asOf": "2026-11-17"
    },
    "F22": {
      "label": "Project function, opencv-python",
      "display": "def letterbox(im, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True, stride=32):\n    # ...\n    shape = im.shape[:2]  # current shape [height, width]\n    if isinstance(new_shape, int):\n        new_shape = (new_shape, new_shape)\n\n    # Scale ratio (new / old)\n    r = min(new_shape[0] / shape[0], new_shape[1] / shape[1])\n    if not scaleup:  # only scale down, do not scale up (for better val mAP)\n        r = min(r, 1.0)\n\n    # Compute padding\n    ratio = r, r  # width, height ratios\n    new_unpad = round(shape[1] * r), round(shape[0] * r)\n    dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1]  # wh padding\n    if auto:  # minimum rectangle\n        dw, dh = np.mod(dw, stride), np.mod(dh, stride)  # wh padding\n    elif scaleFill:  # stretch\n        dw, dh = 0.0, 0.0\n        new_unpad = (new_shape[1], new_shape[0])\n        ratio = new_shape[1] / shape[1], new_shape[0] / shape[0]  # width, height ratios\n\n    dw /= 2  # divide padding into 2 sides\n    dh /= 2\n\n    if shape[::-1] != new_unpad:  # resize\n        im = cv2.resize(im, new_unpad, interpolation=cv2.INTER_LINEAR)\n    top, bottom = round(dh - 0.1), round(dh + 0.1)\n    left, right = round(dw - 0.1), round(dw + 0.1)\n    im = cv2.copyMakeBorder(im, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color)  # add border\n    return im, ratio, (dw, dh)\n",
      "asOf": "2026-11-17"
    },
    "F23": {
      "label": "Project function reference, opencv-python",
      "display": "augmentations.py · letterbox()",
      "asOf": "2026-11-17"
    },
    "F24": {
      "label": "Project repository, opencv-python",
      "display": "ultralytics/yolov5",
      "asOf": "2026-11-17"
    },
    "F25": {
      "label": "Project stars, ultralytics/yolov5",
      "display": "58.3K",
      "asOf": "2026-11-17"
    },
    "F26": {
      "label": "Project push date, ultralytics/yolov5",
      "display": "Nov 2026",
      "asOf": "2026-11-07"
    },
    "F27": {
      "label": "Library name, scikit-image",
      "display": "scikit-image",
      "asOf": "2026-11-17"
    },
    "F28": {
      "label": "Monthly downloads, scikit-image",
      "display": "29.8M",
      "asOf": "2026-11-16"
    },
    "F29": {
      "label": "License, scikit-image",
      "display": "BSD",
      "asOf": "2026-11-17"
    },
    "F30": {
      "label": "Package release, scikit-image",
      "display": "0.26.0, Dec 2025",
      "asOf": "2025-12-20"
    },
    "F31": {
      "label": "Package release date, scikit-image",
      "display": "Dec 2025",
      "asOf": "2025-12-20"
    },
    "F32": {
      "label": "Repository stars, scikit-image",
      "display": "6.6K",
      "asOf": "2026-11-17"
    },
    "F33": {
      "label": "Reads image files, scikit-image",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F34": {
      "label": "Random image augmentation, scikit-image",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F35": {
      "label": "Loads pretrained detectors, scikit-image",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F36": {
      "label": "Install, scikit-image",
      "display": "pip install scikit-image matplotlib",
      "asOf": "2026-11-17"
    },
    "F37": {
      "label": "What it does, scikit-image",
      "display": "Analyzes NumPy images with image-processing, feature-detection, and scientific imaging functions.",
      "asOf": "2026-11-17"
    },
    "F38": {
      "label": "strengths lead, scikit-image",
      "display": "Works directly with NumPy images",
      "asOf": "2026-11-17"
    },
    "F39": {
      "label": "strengths, scikit-image",
      "display": "Apply image processing to ordinary NumPy arrays.",
      "asOf": "2026-11-17"
    },
    "F40": {
      "label": "strengths lead, scikit-image",
      "display": "Finds image edges with Canny",
      "asOf": "2026-11-17"
    },
    "F41": {
      "label": "strengths, scikit-image",
      "display": "Compare edge maps using different smoothing strengths.",
      "asOf": "2026-11-17"
    },
    "F42": {
      "label": "limitations lead, scikit-image",
      "display": "Type changes need intensity rescaling",
      "asOf": "2026-11-17"
    },
    "F43": {
      "label": "limitations, scikit-image",
      "display": "Use image conversion helpers when changing pixel data types.",
      "asOf": "2026-11-17"
    },
    "F44": {
      "label": "limitations lead, scikit-image",
      "display": "OpenCV colors need channel conversion",
      "asOf": "2026-11-17"
    },
    "F45": {
      "label": "limitations, scikit-image",
      "display": "Convert BGR images to RGB before processing them.",
      "asOf": "2026-11-17"
    },
    "F46": {
      "label": "Quickstart, scikit-image",
      "display": "\"\"\"\n===================\nCanny edge detector\n===================\n\nThe Canny filter is a multi-stage edge detector. It uses a filter based on the\nderivative of a Gaussian in order to compute the intensity of the gradients.The\nGaussian reduces the effect of noise present in the image. Then, potential\nedges are thinned down to 1-pixel curves by removing non-maximum pixels of the\ngradient magnitude. Finally, edge pixels are kept or removed using hysteresis\nthresholding on the gradient magnitude.\n\nThe Canny has three adjustable parameters: the width of the Gaussian (the\nnoisier the image, the greater the width), and the low and high threshold for\nthe hysteresis thresholding.\n\n\"\"\"\n\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy import ndimage as ndi\nfrom skimage.util import random_noise\nfrom skimage import feature\n\n\n# Generate noisy image of a square\nimage = np.zeros((128, 128), dtype=float)\nimage[32:-32, 32:-32] = 1\n\nimage = ndi.rotate(image, 15, mode='constant')\nimage = ndi.gaussian_filter(image, 4)\nimage = random_noise(image, mode='speckle', mean=0.1)\n\n# Compute the Canny filter for two values of sigma\nedges1 = feature.canny(image)\nedges2 = feature.canny(image, sigma=3)\n\n# display results\nfig, ax = plt.subplots(nrows=1, ncols=3, figsize=(8, 3))\n\nax[0].imshow(image, cmap='gray')\nax[0].set_title('noisy image', fontsize=20)\n\nax[1].imshow(edges1, cmap='gray')\nax[1].set_title(r'Canny filter, $\\sigma=1$', fontsize=20)\n\nax[2].imshow(edges2, cmap='gray')\nax[2].set_title(r'Canny filter, $\\sigma=3$', fontsize=20)\n\nfor a in ax:\n    a.axis('off')\n\nfig.tight_layout()\nplt.show()\n",
      "asOf": "2026-11-17"
    },
    "F47": {
      "label": "Project function, scikit-image",
      "display": "def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True,\n           preserve_range=False, anti_aliasing=False, anti_aliasing_sigma=None):\n    # ...\n    if LooseVersion(skimage.__version__) >= LooseVersion(\"0.14\"):\n        # New in 0.14: anti_aliasing. Default it to False for backward\n        # compatibility with skimage 0.13.\n        return skimage.transform.resize(\n            image, output_shape,\n            order=order, mode=mode, cval=cval, clip=clip,\n            preserve_range=preserve_range, anti_aliasing=anti_aliasing,\n            anti_aliasing_sigma=anti_aliasing_sigma)\n    else:\n        return skimage.transform.resize(\n            image, output_shape,\n            order=order, mode=mode, cval=cval, clip=clip,\n            preserve_range=preserve_range)\n",
      "asOf": "2026-11-17"
    },
    "F48": {
      "label": "Project function reference, scikit-image",
      "display": "utils.py · resize()",
      "asOf": "2026-11-17"
    },
    "F49": {
      "label": "Project repository, scikit-image",
      "display": "matterport/Mask_RCNN",
      "asOf": "2026-11-17"
    },
    "F50": {
      "label": "Project stars, matterport/Mask_RCNN",
      "display": "25.6K",
      "asOf": "2026-11-17"
    },
    "F51": {
      "label": "Project push date, matterport/Mask_RCNN",
      "display": "Jun 2024",
      "asOf": "2024-06-07"
    },
    "F52": {
      "label": "Library name, torchvision",
      "display": "Torchvision",
      "asOf": "2026-11-17"
    },
    "F53": {
      "label": "Monthly downloads, torchvision",
      "display": "17.5M",
      "asOf": "2026-11-16"
    },
    "F54": {
      "label": "License, torchvision",
      "display": "BSD",
      "asOf": "2026-11-17"
    },
    "F55": {
      "label": "Package release, torchvision",
      "display": "0.29.2, Oct 2026",
      "asOf": "2026-10-28"
    },
    "F56": {
      "label": "Package release date, torchvision",
      "display": "Oct 2026",
      "asOf": "2026-10-28"
    },
    "F57": {
      "label": "Repository stars, torchvision",
      "display": "18.0K",
      "asOf": "2026-11-17"
    },
    "F58": {
      "label": "Reads image files, torchvision",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F59": {
      "label": "Runs GPU transforms, torchvision",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F60": {
      "label": "Random image augmentation, torchvision",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F61": {
      "label": "Loads pretrained detectors, torchvision",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F62": {
      "label": "Output formats, torchvision",
      "display": "PNG",
      "asOf": "2026-11-17"
    },
    "F63": {
      "label": "Install, torchvision",
      "display": "pip install torchvision matplotlib",
      "asOf": "2026-11-17"
    },
    "F64": {
      "label": "What it does, torchvision",
      "display": "Provides PyTorch vision datasets, pretrained models, image transforms, and image encoding or decoding.",
      "asOf": "2026-11-17"
    },
    "F65": {
      "label": "strengths lead, torchvision",
      "display": "Bundles preprocessing with pretrained weights",
      "asOf": "2026-11-17"
    },
    "F66": {
      "label": "strengths, torchvision",
      "display": "Use each weight configuration’s transforms before running inference.",
      "asOf": "2026-11-17"
    },
    "F67": {
      "label": "strengths lead, torchvision",
      "display": "Augments CPU and GPU tensors",
      "asOf": "2026-11-17"
    },
    "F68": {
      "label": "strengths, torchvision",
      "display": "Use image transforms with PIL images or CPU and CUDA tensors.",
      "asOf": "2026-11-17"
    },
    "F69": {
      "label": "limitations lead, torchvision",
      "display": "Detection APIs can change",
      "asOf": "2026-11-17"
    },
    "F70": {
      "label": "limitations, torchvision",
      "display": "The detection module remains beta without guaranteed backward compatibility.",
      "asOf": "2026-11-17"
    },
    "F71": {
      "label": "limitations lead, torchvision",
      "display": "Pretrained weights need matching preprocessing",
      "asOf": "2026-11-17"
    },
    "F72": {
      "label": "limitations, torchvision",
      "display": "Apply the selected weight’s transforms to prepare images for inference.",
      "asOf": "2026-11-17"
    },
    "F73": {
      "label": "Quickstart, torchvision",
      "display": "\"\"\"\n==================================\nGetting started with transforms v2\n==================================\n\n.. note::\n    Try on `Colab <https://colab.research.google.com/github/pytorch/vision/blob/gh-pages/main/_generated_ipynb_notebooks/plot_transforms_getting_started.ipynb>`_\n    or :ref:`go to the end <sphx_glr_download_auto_examples_transforms_plot_transforms_getting_started.py>` to download the full example code.\n\nThis example illustrates all of what you need to know to get started with the\nnew :mod:`torchvision.transforms.v2` API. We'll cover simple tasks like\nimage classification, and more advanced ones like object detection /\nsegmentation.\n\"\"\"\n\n# %%\n# First, a bit of setup\nfrom pathlib import Path\nimport torch\nimport matplotlib.pyplot as plt\nplt.rcParams[\"savefig.bbox\"] = 'tight'\n\nfrom torchvision.transforms import v2\nfrom torchvision.io import decode_image\n\ntorch.manual_seed(1)\n\n# If you're trying to run that on Colab, you can download the assets and the\n# helpers from https://github.com/pytorch/vision/tree/main/gallery/\nfrom helpers import plot\nimg = decode_image(str(Path('../assets') / 'astronaut.jpg'))\nprint(f\"{type(img) = }, {img.dtype = }, {img.shape = }\")\n\n# %%\n# The basics\n# ----------\n#\n# The Torchvision transforms behave like a regular :class:`torch.nn.Module` (in\n# fact, most of them are): instantiate a transform, pass an input, get a\n# transformed output:\n\ntransform = v2.RandomCrop(size=(224, 224))\nout = transform(img)\n\nplot([img, out])\n\n# %%\n# I just want to do image classification\n# --------------------------------------\n#\n# If you just care about image classification, things are very simple. A basic\n# classification pipeline may look like this:\n\ntransforms = v2.Compose([\n    v2.RandomResizedCrop(size=(224, 224), antialias=True),\n    v2.RandomHorizontalFlip(p=0.5),\n    v2.ToDtype(torch.float32, scale=True),\n    v2.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),\n])\nout = transforms(img)\n\nplot([img, out])\n\n# %%\n# Such transformation pipeline is typically passed as the ``transform`` argument\n# to the :ref:`Datasets <datasets>`, e.g. ``ImageNet(...,\n# transform=transforms)``.\n#\n# That's pretty much all there is. From there, read through our :ref:`main docs\n# <transforms>` to learn more about recommended practices and conventions, or\n# explore more :ref:`examples <transforms_gallery>` e.g. how to use augmentation\n# transforms like :ref:`CutMix and MixUp\n# <sphx_glr_auto_examples_transforms_plot_cutmix_mixup.py>`.\n#\n# .. note::\n#\n#     If you're already relying on the ``torchvision.transforms`` v1 API,\n#     we recommend to :ref:`switch to the new v2 transforms<v1_or_v2>`. It's\n#     very easy: the v2 transforms are fully compatible with the v1 API, so you\n#     only need to change the import!\n#\n# Videos, boxes, masks, keypoints\n# -------------------------------\n#\n# The Torchvision transforms in the ``torchvision.transforms.v2`` namespace\n# support tasks beyond image classification: they can also transform rotated or\n# axis-aligned bounding boxes, segmentation / detection masks, videos, and\n# keypoints.\n#\n# Let's briefly look at a detection example with bounding boxes.\n\nfrom torchvision import tv_tensors  # we'll describe this a bit later, bare with us\n\nboxes = tv_tensors.BoundingBoxes(\n    [\n        [15, 10, 370, 510],\n        [275, 340, 510, 510],\n        [130, 345, 210, 425]\n    ],\n    format=\"XYXY\", canvas_size=img.shape[-2:])\n\ntransforms = v2.Compose([\n    v2.RandomResizedCrop(size=(224, 224), antialias=True),\n    v2.RandomPhotometricDistort(p=1),\n    v2.RandomHorizontalFlip(p=1),\n])\nout_img, out_boxes = transforms(img, boxes)\nprint(type(boxes), type(out_boxes))\n\nplot([(img, boxes), (out_img, out_boxes)])\n\n# %%\n#\n# The example above focuses on object detection. But if we had masks\n# (:class:`torchvision.tv_tensors.Mask`) for object segmentation or semantic\n# segmentation, or videos (:class:`torchvision.tv_tensors.Video`), we could have\n# passed them to the transforms in exactly the same way.\n#\n# By now you likely have a few questions: what are these TVTensors, how do we\n# use them, and what is the expected input/output of those transforms? We'll\n# answer these in the next sections.\n\n# %%\n#\n# .. _what_are_tv_tensors:\n#\n# What are TVTensors?\n# --------------------\n#\n# TVTensors are :class:`torch.Tensor` subclasses. The available TVTensors are\n# :class:`~torchvision.tv_tensors.Image`,\n# :class:`~torchvision.tv_tensors.BoundingBoxes`,\n# :class:`~torchvision.tv_tensors.Mask`,\n# :class:`~torchvision.tv_tensors.Video`, and\n# :class:`~torchvision.tv_tensors.KeyPoints`.\n#\n# TVTensors look and feel just like regular tensors - they **are** tensors.\n# Everything that is supported on a plain :class:`torch.Tensor` like ``.sum()``\n# or any ``torch.*`` operator will also work on a TVTensor:\n\nimg_dp = tv_tensors.Image(torch.randint(0, 256, (3, 256, 256), dtype=torch.uint8))\n\nprint(f\"{isinstance(img_dp, torch.Tensor) = }\")\nprint(f\"{img_dp.dtype = }, {img_dp.shape = }, {img_dp.sum() = }\")\n\n# %%\n# These TVTensor classes are at the core of the transforms: in order to\n# transform a given input, the transforms first look at the **class** of the\n# object, and dispatch to the appropriate implementation accordingly.\n#\n# You don't need to know much more about TVTensors at this point, but advanced\n# users who want to learn more can refer to\n# :ref:`sphx_glr_auto_examples_transforms_plot_tv_tensors.py`.\n#\n# What do I pass as input?\n# ------------------------\n#\n# Above, we've seen two examples: one where we passed a single image as input\n# i.e. ``out = transforms(img)``, and one where we passed both an image and\n# bounding boxes, i.e. ``out_img, out_boxes = transforms(img, boxes)``.\n#\n# In fact, transforms support **arbitrary input structures**. The input can be a\n# single image, a tuple, an arbitrarily nested dictionary... pretty much\n# anything. The same structure will be returned as output. Below, we use the\n# same detection transforms, but pass a tuple (image, target_dict) as input and\n# we're getting the same structure as output:\n\ntarget = {\n    \"boxes\": boxes,\n    \"labels\": torch.arange(boxes.shape[0]),\n    \"this_is_ignored\": (\"arbitrary\", {\"structure\": \"!\"})\n}\n\n# Re-using the transforms and definitions from above.\nout_img, out_target = transforms(img, target)\n\n# sphinx_gallery_thumbnail_number = 4\nplot([(img, target[\"boxes\"]), (out_img, out_target[\"boxes\"])])\nprint(f\"{out_target['this_is_ignored']}\")\n\n# %%\n# We passed a tuple so we get a tuple back, and the second element is the\n# tranformed target dict. Transforms don't really care about the structure of\n# the input; as mentioned above, they only care about the **type** of the\n# objects and transforms them accordingly.\n#\n# *Foreign* objects like strings or ints are simply passed-through. This can be\n# useful e.g. if you want to associate a path with every single sample when\n# debugging!\n#\n# .. _passthrough_heuristic:\n#\n# .. note::\n#\n#     **Disclaimer** This note is slightly advanced and can be safely skipped on\n#     a first read.\n#\n#     Pure :class:`torch.Tensor` objects are, in general, treated as images (or\n#     as videos for video-specific transforms). Indeed, you may have noticed\n#     that in the code above we haven't used the\n#     :class:`~torchvision.tv_tensors.Image` class at all, and yet our images\n#     got transformed properly. Transforms follow the following logic to\n#     determine whether a pure Tensor should be treated as an image (or video),\n#     or just ignored:\n#\n#     * If there is an :class:`~torchvision.tv_tensors.Image`,\n#       :class:`~torchvision.tv_tensors.Video`,\n#       or :class:`PIL.Image.Image` instance in the input, all other pure\n#       tensors are passed-through.\n#     * If there is no :class:`~torchvision.tv_tensors.Image` or\n#       :class:`~torchvision.tv_tensors.Video` instance, only the first pure\n#       :class:`torch.Tensor` will be transformed as image or video, while all\n#       others will be passed-through. Here \"first\" means \"first in a depth-wise\n#       traversal\".\n#\n#     This is what happened in the detection example above: the first pure\n#     tensor was the image so it got transformed properly, and all other pure\n#     tensor instances like the ``labels`` were passed-through (although labels\n#     can still be transformed by some transforms like\n#     :class:`~torchvision.transforms.v2.SanitizeBoundingBoxes`!).\n#\n# .. _transforms_datasets_intercompatibility:\n#\n# Transforms and Datasets intercompatibility\n# ------------------------------------------\n#\n# Roughly speaking, the output of the datasets must correspond to the input of\n# the transforms. How to do that depends on whether you're using the torchvision\n# :ref:`built-in datatsets <datasets>`, or your own custom datasets.\n#\n# Using built-in datasets\n# ^^^^^^^^^^^^^^^^^^^^^^^\n#\n# If you're just doing image classification, you don't need to do anything. Just\n# use ``transform`` argument of the dataset e.g. ``ImageNet(...,\n# transform=transforms)`` and you're good to go.\n#\n# Torchvision also supports datasets for object detection or segmentation like\n# :class:`torchvision.datasets.CocoDetection`. Those datasets predate\n# the existence of the :mod:`torchvision.transforms.v2` module and of the\n# TVTensors, so they don't return TVTensors out of the box.\n#\n# An easy way to force those datasets to return TVTensors and to make them\n# compatible with v2 transforms is to use the\n# :func:`torchvision.datasets.wrap_dataset_for_transforms_v2` function:\n#\n# .. code-block:: python\n#\n#    from torchvision.datasets import CocoDetection, wrap_dataset_for_transforms_v2\n#\n#    dataset = CocoDetection(..., transforms=my_transforms)\n#    dataset = wrap_dataset_for_transforms_v2(dataset)\n#    # Now the dataset returns TVTensors!\n#\n# Using your own datasets\n# ^^^^^^^^^^^^^^^^^^^^^^^\n#\n# If you have a custom dataset, then you'll need to convert your objects into\n# the appropriate TVTensor classes. Creating TVTensor instances is very easy,\n# refer to :ref:`tv_tensor_creation` for more details.\n#\n# There are two main places where you can implement that conversion logic:\n#\n# - At the end of the datasets's ``__getitem__`` method, before returning the\n#   sample (or by sub-classing the dataset).\n# - As the very first step of your transforms pipeline\n#\n# Either way, the logic will depend on your specific dataset.\n",
      "asOf": "2026-11-17"
    },
    "F74": {
      "label": "Project function, torchvision",
      "display": "def __init__(\n    self,\n    folder,\n    image_size,\n    exts = ['jpg', 'jpeg', 'png', 'tiff'],\n    augment_horizontal_flip = False,\n    convert_image_to = None\n):\n    super().__init__()\n    self.folder = folder\n    self.image_size = image_size\n    self.paths = [p for ext in exts for p in Path(f'{folder}').glob(f'**/*.{ext}')]\n\n    maybe_convert_fn = partial(convert_image_to_fn, convert_image_to) if exists(convert_image_to) else nn.Identity()\n\n    self.transform = T.Compose([\n        T.Lambda(maybe_convert_fn),\n        T.Resize(image_size),\n        T.RandomHorizontalFlip() if augment_horizontal_flip else nn.Identity(),\n        T.CenterCrop(image_size),\n        T.ToTensor()\n    ])\n",
      "asOf": "2026-11-17"
    },
    "F75": {
      "label": "Project function reference, torchvision",
      "display": "denoising_diffusion_pytorch.py · __init__()",
      "asOf": "2026-11-17"
    },
    "F76": {
      "label": "Project repository, torchvision",
      "display": "lucidrains/denoising-diffusion-pytorch",
      "asOf": "2026-11-17"
    },
    "F77": {
      "label": "Project stars, lucidrains/denoising-diffusion-pytorch",
      "display": "10.7K",
      "asOf": "2026-11-17"
    },
    "F78": {
      "label": "Project push date, lucidrains/denoising-diffusion-pytorch",
      "display": "Sep 2026",
      "asOf": "2026-09-29"
    },
    "F79": {
      "label": "Library name, kornia",
      "display": "Kornia",
      "asOf": "2026-11-17"
    },
    "F80": {
      "label": "Monthly downloads, kornia",
      "display": "3.0M",
      "asOf": "2026-11-16"
    },
    "F81": {
      "label": "License, kornia",
      "display": "Apache-2.0",
      "asOf": "2026-11-17"
    },
    "F82": {
      "label": "Package release, kornia",
      "display": "0.9.1, Nov 2026",
      "asOf": "2026-11-13"
    },
    "F83": {
      "label": "Package release date, kornia",
      "display": "Nov 2026",
      "asOf": "2026-11-13"
    },
    "F84": {
      "label": "Repository stars, kornia",
      "display": "12.4K",
      "asOf": "2026-11-17"
    },
    "F85": {
      "label": "Reads image files, kornia",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F86": {
      "label": "Runs GPU transforms, kornia",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F87": {
      "label": "Random image augmentation, kornia",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F88": {
      "label": "Loads pretrained detectors, kornia",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F89": {
      "label": "Output formats, kornia",
      "display": "PNG",
      "asOf": "2026-11-17"
    },
    "F90": {
      "label": "Install, kornia",
      "display": "pip install kornia",
      "asOf": "2026-11-17"
    },
    "F91": {
      "label": "What it does, kornia",
      "display": "Applies differentiable vision operations and paired image augmentation to batched PyTorch tensors.",
      "asOf": "2026-11-17"
    },
    "F92": {
      "label": "strengths lead, kornia",
      "display": "Augments paired images and labels",
      "asOf": "2026-11-17"
    },
    "F93": {
      "label": "strengths, kornia",
      "display": "Apply the same sampled transform to images, masks, boxes, and keypoints.",
      "asOf": "2026-11-17"
    },
    "F94": {
      "label": "strengths lead, kornia",
      "display": "Transforms image batches on GPU",
      "asOf": "2026-11-17"
    },
    "F95": {
      "label": "strengths, kornia",
      "display": "Run random augmentations on batches of floating-point tensors.",
      "asOf": "2026-11-17"
    },
    "F96": {
      "label": "limitations lead, kornia",
      "display": "Color transforms need scaled floats",
      "asOf": "2026-11-17"
    },
    "F97": {
      "label": "limitations, kornia",
      "display": "Rescale pixel values before converting images to floating-point augmentation input.",
      "asOf": "2026-11-17"
    },
    "F98": {
      "label": "limitations lead, kornia",
      "display": "Inversion cannot restore cropped pixels",
      "asOf": "2026-11-17"
    },
    "F99": {
      "label": "limitations, kornia",
      "display": "Reversing geometry leaves discarded image data missing and color changes intact.",
      "asOf": "2026-11-17"
    },
    "F100": {
      "label": "Quickstart, kornia",
      "display": "import torch\nimport kornia.augmentation as K\n\naug = K.AugmentationSequential(\n    K.RandomAffine(degrees=30.0, p=1.0),\n    K.ColorJiggle(0.1, 0.1, 0.1, 0.1, p=1.0),\n    data_keys=[\"input\", \"mask\", \"keypoints\"],\n)\nimage = torch.rand(2, 3, 64, 64)\nmask = (torch.rand(2, 1, 64, 64) > 0.5).float()\nkeypoints = torch.tensor([[[16.0, 16.0], [48.0, 32.0]]]).repeat(2, 1, 1)\n\nimg_out, mask_out, kpts_out = aug(image, mask, keypoints)  # same random parameters for all three\nimg_back, mask_back, kpts_back = aug.inverse(img_out, mask_out, kpts_out)\nmatrix = aug.transform_matrix  # (B, 3, 3) composed matrix for the geometric steps\n",
      "asOf": "2026-11-17"
    },
    "F101": {
      "label": "Developer need",
      "display": "Classical image processing and cascades",
      "asOf": "2026-11-17"
    },
    "F102": {
      "label": "Why choose opencv-python",
      "display": "bundled ready-to-load Haar cascade files",
      "asOf": "2026-11-17"
    },
    "F103": {
      "label": "Developer need in introduction",
      "display": "classical image processing and cascades",
      "asOf": "2026-11-17"
    },
    "F104": {
      "label": "When to consider scikit-image",
      "display": "the workflow centers on NumPy-based image analysis",
      "asOf": "2026-11-17"
    },
    "F105": {
      "label": "Developer need",
      "display": "NumPy image analysis",
      "asOf": "2026-11-17"
    },
    "F106": {
      "label": "Why choose scikit-image",
      "display": "image processing on ordinary NumPy arrays",
      "asOf": "2026-11-17"
    },
    "F107": {
      "label": "Developer need in introduction",
      "display": "NumPy image analysis",
      "asOf": "2026-11-17"
    },
    "F108": {
      "label": "When to consider kornia",
      "display": "image augmentation should run on GPU tensor batches",
      "asOf": "2026-11-17"
    },
    "F109": {
      "label": "Developer need",
      "display": "Paired training-data augmentation",
      "asOf": "2026-11-17"
    },
    "F110": {
      "label": "Why choose kornia",
      "display": "shared transformations for images and labels",
      "asOf": "2026-11-17"
    },
    "F111": {
      "label": "Developer need in introduction",
      "display": "paired training-data augmentation",
      "asOf": "2026-11-17"
    },
    "F112": {
      "label": "When to consider torchvision",
      "display": "pretrained models and their weight-specific preprocessing are central",
      "asOf": "2026-11-17"
    },
    "F113": {
      "label": "Developer need",
      "display": "Pretrained PyTorch vision models",
      "asOf": "2026-11-17"
    },
    "F114": {
      "label": "Why choose torchvision",
      "display": "weights with matching preprocessing transforms",
      "asOf": "2026-11-17"
    },
    "F115": {
      "label": "Developer need in introduction",
      "display": "pretrained PyTorch vision models",
      "asOf": "2026-11-17"
    },
    "F116": {
      "label": "Page introduction",
      "display": "Python computer vision libraries let developers analyze visual information in images.",
      "asOf": "2026-11-17"
    },
    "F117": {
      "label": "FAQ: Which Python computer vision library should I choose?",
      "display": "OpenCV includes classical cascade files ready to load.",
      "asOf": "2026-11-17"
    },
    "F118": {
      "label": "FAQ: Which Python computer vision library should I choose?",
      "display": "scikit-image works with NumPy image arrays.",
      "asOf": "2026-11-17"
    },
    "F119": {
      "label": "FAQ: Which Python computer vision library should I choose?",
      "display": "Kornia applies paired augmentation to images and labels.",
      "asOf": "2026-11-17"
    },
    "F120": {
      "label": "FAQ: Which Python computer vision library should I choose?",
      "display": "Torchvision bundles preprocessing with pretrained weights.",
      "asOf": "2026-11-17"
    },
    "F121": {
      "label": "FAQ: Does pip install opencv-python enable GPU transforms?",
      "display": "The prebuilt opencv-python wheels are CPU-only.",
      "asOf": "2026-11-17"
    },
    "F122": {
      "label": "FAQ: Does pip install opencv-python enable GPU transforms?",
      "display": "The packaging project directs CUDA users to a manual source build.",
      "asOf": "2026-11-17"
    },
    "F123": {
      "label": "FAQ: Why do OpenCV colors look wrong in scikit-image?",
      "display": "OpenCV uses BGR channel order while scikit-image uses RGB.",
      "asOf": "2026-11-17"
    },
    "F124": {
      "label": "FAQ: Does casting an image to float also rescale its pixel values?",
      "display": "Kornia warns that casting alone does not rescale augmentation inputs.",
      "asOf": "2026-11-17"
    },
    "F125": {
      "label": "FAQ: Does casting an image to float also rescale its pixel values?",
      "display": "scikit-image supplies conversion helpers that rescale values for the desired type.",
      "asOf": "2026-11-17"
    },
    "F126": {
      "label": "FAQ: How do I apply the same random transform to images and masks?",
      "display": "Kornia AugmentationSequential shares one sampled draw across images, masks, boxes, and keypoints.",
      "asOf": "2026-11-17"
    },
    "F127": {
      "label": "FAQ: Can inverse augmentation recover cropped image pixels?",
      "display": "Kornia inversion cannot restore pixels lost to cropping or resampling and leaves color changes in place.",
      "asOf": "2026-11-17"
    },
    "F128": {
      "label": "FAQ: Why should preprocessing follow the selected Torchvision weights?",
      "display": "Preprocessing differs between model families, variants, and weight versions.",
      "asOf": "2026-11-17"
    },
    "F129": {
      "label": "FAQ: Why should preprocessing follow the selected Torchvision weights?",
      "display": "Torchvision bundles the needed transforms with each model weight.",
      "asOf": "2026-11-17"
    },
    "F130": {
      "label": "FAQ: Does the package code license cover every pretrained model?",
      "display": "Torchvision states that pretrained models may have their own licenses or dataset-derived terms.",
      "asOf": "2026-11-17"
    },
    "F131": {
      "label": "FAQ: Does Kornia image loading need a separately installed codec plugin?",
      "display": "Kornia installs its kornia-rs image backend automatically as a dependency.",
      "asOf": "2026-11-17"
    },
    "F132": {
      "label": "Library name, pillow",
      "display": "Pillow",
      "asOf": "2026-11-20"
    },
    "F133": {
      "label": "Monthly downloads, pillow",
      "display": "703.4M",
      "asOf": "2026-11-20"
    },
    "F134": {
      "label": "License, pillow",
      "display": "MIT-CMU",
      "asOf": "2026-11-20"
    },
    "F135": {
      "label": "Package release, pillow",
      "display": "13.0.0",
      "asOf": "2026-11-20"
    },
    "F136": {
      "label": "Package release date, pillow",
      "display": "Oct 2026",
      "asOf": "2026-11-20"
    },
    "F137": {
      "label": "Install, pillow",
      "display": "python3 -m pip install pillow",
      "asOf": "2026-11-20"
    },
    "F138": {
      "label": "Quickstart, pillow",
      "display": "from PIL import Image\nim = Image.open(\"hopper.ppm\")\n",
      "asOf": "2026-11-20"
    },
    "F139": {
      "label": "Official description, pillow",
      "display": "Provides the maintained fork of the Python Imaging Library.",
      "asOf": "2026-11-20"
    },
    "F140": {
      "label": "Quickstart source file, pillow",
      "display": "docs/handbook/tutorial.rst",
      "asOf": "2026-11-20"
    },
    "F141": {
      "label": "Repository stars, pillow",
      "display": "14.0K",
      "asOf": "2026-11-20"
    },
    "F142": {
      "label": "Neural model loader, pillow",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F143": {
      "label": "PyTorch required, pillow",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F144": {
      "label": "Task and stack role, pillow",
      "display": "Foundational image loading, pixel operations, resizing, and cropping; not a neural architecture/weight model zoo.",
      "asOf": "2026-11-20"
    },
    "F145": {
      "label": "Download scope, pillow",
      "display": "Whole distribution installations, including dependency overlap and use outside this page. Not distinct developers or computer-vision-only adoption.",
      "asOf": "2026-11-20"
    },
    "F146": {
      "label": "Project function, pillow",
      "display": "def resize_and_crop(img, size, crop_type=\"center\"):\n    \"\"\"\n    Resize and crop an image to fit the specified size.\n    args:\n        size: `(width, height)` tuple. Pass `None` for either width or height\n        to only crop and resize the other.\n        crop_type: can be 'top', 'middle' or 'bottom', depending on this\n            value, the image will cropped getting the 'top/left', 'middle' or\n            'bottom/right' of the image to fit the size.\n    raises:\n        ValueError: if an invalid `crop_type` is provided.\n    \"\"\"\n    if crop_type == \"top\":\n        center = (0, 0)\n    elif crop_type == \"center\":\n        center = (0.5, 0.5)\n    else:\n        raise ValueError\n\n    resize = list(size)\n    if size[0] is None:\n        resize[0] = img.size[0]\n    if size[1] is None:\n        resize[1] = img.size[1]\n    return ImageOps.fit(img, resize, centering=center)  # type: ignore\n",
      "asOf": "2026-11-20"
    },
    "F147": {
      "label": "Project source file, pillow",
      "display": "gradio/processing_utils.py",
      "asOf": "2026-11-20"
    },
    "F148": {
      "label": "Project full_name, pillow",
      "display": "gradio-app/gradio",
      "asOf": "2026-11-20"
    },
    "F149": {
      "label": "Project stargazers_count, pillow",
      "display": "44.1K",
      "asOf": "2026-11-20"
    },
    "F150": {
      "label": "Library name, transformers",
      "display": "Transformers",
      "asOf": "2026-11-20"
    },
    "F151": {
      "label": "Monthly downloads, transformers",
      "display": "119.8M",
      "asOf": "2026-11-20"
    },
    "F152": {
      "label": "License, transformers",
      "display": "Apache-2.0",
      "asOf": "2026-11-20"
    },
    "F153": {
      "label": "Package release, transformers",
      "display": "5.23.0",
      "asOf": "2026-11-20"
    },
    "F154": {
      "label": "Package release date, transformers",
      "display": "Nov 2026",
      "asOf": "2026-11-20"
    },
    "F155": {
      "label": "Install, transformers",
      "display": "python3 -m pip install \"transformers[torch,vision]\"",
      "asOf": "2026-11-20"
    },
    "F156": {
      "label": "Quickstart, transformers",
      "display": "from transformers import CLIPVisionConfig, CLIPVisionModelWithProjection\nconfiguration = CLIPVisionConfig()\nmodel = CLIPVisionModelWithProjection(configuration)\n",
      "asOf": "2026-11-20"
    },
    "F157": {
      "label": "Official description, transformers",
      "display": "Defines and runs pretrained models for text, vision, audio, and multimodal tasks.",
      "asOf": "2026-11-20"
    },
    "F158": {
      "label": "Quickstart source file, transformers",
      "display": "docs/source/en/model_doc/clip.md",
      "asOf": "2026-11-20"
    },
    "F159": {
      "label": "Repository stars, transformers",
      "display": "169.2K",
      "asOf": "2026-11-20"
    },
    "F160": {
      "label": "Neural model loader, transformers",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F161": {
      "label": "PyTorch required, transformers",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F162": {
      "label": "Task and stack role, transformers",
      "display": "Pretrained vision/multimodal model definitions, image processors, and inference/training interfaces; package counter also includes text/audio use.",
      "asOf": "2026-11-20"
    },
    "F163": {
      "label": "Download scope, transformers",
      "display": "Whole distribution installations, including dependency overlap and use outside this page. Not distinct developers or computer-vision-only adoption.",
      "asOf": "2026-11-20"
    },
    "F164": {
      "label": "Project function, transformers",
      "display": "def perform_inference(self, image: list | np.ndarray):\n    \"\"\"Prediction is performed using self.model and the prediction result is set to self._original_predictions.\n\n    Args:\n        image: np.ndarray\n            A numpy array that contains the image to be predicted. 3 channel image should be in RGB order.\n    \"\"\"\n    import torch\n\n    # Confirm model is loaded\n    if self.model is None or self.processor is None:\n        raise RuntimeError(\"Model is not loaded, load it by calling .load_model()\")\n\n    with torch.no_grad():\n        inputs = self.processor(images=image, return_tensors=\"pt\")\n        inputs[\"pixel_values\"] = inputs.pixel_values.to(self.device)\n        if hasattr(inputs, \"pixel_mask\"):\n            inputs[\"pixel_mask\"] = inputs.pixel_mask.to(self.device)\n        outputs = self.model(**inputs)\n\n    if isinstance(image, list):\n        self._image_shapes = [img.shape for img in image]\n    else:\n        self._image_shapes = [image.shape]\n    self._original_predictions = outputs",
      "asOf": "2026-11-20"
    },
    "F165": {
      "label": "Project source file, transformers",
      "display": "sahi/models/huggingface.py",
      "asOf": "2026-11-20"
    },
    "F166": {
      "label": "Project full_name, transformers",
      "display": "obss/sahi",
      "asOf": "2026-11-20"
    },
    "F167": {
      "label": "Project stargazers_count, transformers",
      "display": "5.6K",
      "asOf": "2026-11-20"
    },
    "F168": {
      "label": "Library name, opencv-python-headless",
      "display": "opencv-python-headless",
      "asOf": "2026-11-20"
    },
    "F169": {
      "label": "Monthly downloads, opencv-python-headless",
      "display": "63.0M",
      "asOf": "2026-11-20"
    },
    "F170": {
      "label": "License, opencv-python-headless",
      "display": "Apache-2.0",
      "asOf": "2026-11-20"
    },
    "F171": {
      "label": "Package release, opencv-python-headless",
      "display": "5.1.0.95",
      "asOf": "2026-11-20"
    },
    "F172": {
      "label": "Package release date, opencv-python-headless",
      "display": "Nov 2026",
      "asOf": "2026-11-20"
    },
    "F173": {
      "label": "Install, opencv-python-headless",
      "display": "python3 -m pip install opencv-python-headless",
      "asOf": "2026-11-20"
    },
    "F174": {
      "label": "Quickstart, opencv-python-headless",
      "display": "import cv2\nimage = cv2.imread('input.jpg')\nresized = cv2.resize(image, (320, 240))\n",
      "asOf": "2026-11-20"
    },
    "F175": {
      "label": "Official description, opencv-python-headless",
      "display": "Wraps the OpenCV Python bindings.",
      "asOf": "2026-11-20"
    },
    "F176": {
      "label": "Quickstart source file, opencv-python-headless",
      "display": "imgproc_transform.html",
      "asOf": "2026-11-20"
    },
    "F177": {
      "label": "Repository stars, opencv-python-headless",
      "display": "5.5K",
      "asOf": "2026-11-20"
    },
    "F178": {
      "label": "Neural model loader, opencv-python-headless",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F179": {
      "label": "PyTorch required, opencv-python-headless",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F180": {
      "label": "Task and stack role, opencv-python-headless",
      "display": "Classical image/video geometry, features, and DNN inference with caller-supplied supported model files; selected server wheel has no GUI dependencies.",
      "asOf": "2026-11-20"
    },
    "F181": {
      "label": "Download scope, opencv-python-headless",
      "display": "Whole distribution installations, including dependency overlap and use outside this page. Not distinct developers or computer-vision-only adoption.",
      "asOf": "2026-11-20"
    },
    "F182": {
      "label": "Distribution identity, opencv-python-headless",
      "display": "One cv2 API across mutually exclusive GUI/headless and standard/contrib wheel options; only the highest-download headless distribution is ranked. GitHub stars below identify packaging repository, not upstream algorithm repository.",
      "asOf": "2026-11-20"
    },
    "F183": {
      "label": "Project function, opencv-python-headless",
      "display": "def letterbox(im, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True, stride=32):\n    \"\"\"Resizes and pads image to new_shape with stride-multiple constraints, returns resized image, ratio, padding.\"\"\"\n    shape = im.shape[:2]  # current shape [height, width]\n    if isinstance(new_shape, int):\n        new_shape = (new_shape, new_shape)\n\n    # Scale ratio (new / old)\n    r = min(new_shape[0] / shape[0], new_shape[1] / shape[1])\n    if not scaleup:  # only scale down, do not scale up (for better val mAP)\n        r = min(r, 1.0)\n\n    # Compute padding\n    ratio = r, r  # width, height ratios\n    new_unpad = round(shape[1] * r), round(shape[0] * r)\n    dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1]  # wh padding\n    if auto:  # minimum rectangle\n        dw, dh = np.mod(dw, stride), np.mod(dh, stride)  # wh padding\n    elif scaleFill:  # stretch\n        dw, dh = 0.0, 0.0\n        new_unpad = (new_shape[1], new_shape[0])\n        ratio = new_shape[1] / shape[1], new_shape[0] / shape[0]  # width, height ratios\n\n    dw /= 2  # divide padding into 2 sides\n    dh /= 2\n\n    if shape[::-1] != new_unpad:  # resize\n        im = cv2.resize(im, new_unpad, interpolation=cv2.INTER_LINEAR)\n    top, bottom = round(dh - 0.1), round(dh + 0.1)\n    left, right = round(dw - 0.1), round(dw + 0.1)\n    im = cv2.copyMakeBorder(im, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color)  # add border\n    return im, ratio, (dw, dh)\n",
      "asOf": "2026-11-20"
    },
    "F184": {
      "label": "Project source file, opencv-python-headless",
      "display": "utils/augmentations.py",
      "asOf": "2026-11-20"
    },
    "F185": {
      "label": "Project full_name, opencv-python-headless",
      "display": "ultralytics/yolov5",
      "asOf": "2026-11-20"
    },
    "F186": {
      "label": "Project stargazers_count, opencv-python-headless",
      "display": "58.3K",
      "asOf": "2026-11-20"
    },
    "F187": {
      "label": "Library name, scikit-image",
      "display": "scikit-image",
      "asOf": "2026-11-20"
    },
    "F188": {
      "label": "Monthly downloads, scikit-image",
      "display": "31.7M",
      "asOf": "2026-11-20"
    },
    "F189": {
      "label": "License, scikit-image",
      "display": "BSD-3-Clause",
      "asOf": "2026-11-20"
    },
    "F190": {
      "label": "Package release, scikit-image",
      "display": "0.26.0",
      "asOf": "2026-11-20"
    },
    "F191": {
      "label": "Package release date, scikit-image",
      "display": "Dec 2025",
      "asOf": "2026-11-20"
    },
    "F192": {
      "label": "Install, scikit-image",
      "display": "python3 -m pip install scikit-image",
      "asOf": "2026-11-20"
    },
    "F193": {
      "label": "Quickstart, scikit-image",
      "display": "import skimage as ski\ncoins = ski.data.coins()\nthreshold_value = ski.filters.threshold_otsu(coins)\n",
      "asOf": "2026-11-20"
    },
    "F194": {
      "label": "Repository stars, scikit-image",
      "display": "6.6K",
      "asOf": "2026-11-20"
    },
    "F195": {
      "label": "Neural model loader, scikit-image",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F196": {
      "label": "PyTorch required, scikit-image",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F197": {
      "label": "Task and stack role, scikit-image",
      "display": "NumPy/SciPy image filters, morphology, segmentation, features, and geometric transforms; explicit array-oriented classical workflow.",
      "asOf": "2026-11-20"
    },
    "F198": {
      "label": "Download scope, scikit-image",
      "display": "Whole distribution installations, including dependency overlap and use outside this page. Not distinct developers or computer-vision-only adoption.",
      "asOf": "2026-11-20"
    },
    "F199": {
      "label": "Project function, scikit-image",
      "display": "def determine_skew_dev(\n    image: ImageType,\n    sigma: float = 3.0,\n    num_peaks: int = 20,\n    min_angle: float | None = None,  # -np.pi / 2,\n    max_angle: float | None = None,  # np.pi / 2,\n    min_deviation: float = np.pi / 180,\n    angle_pm_90: bool = False,\n) -> tuple[\n    np.float64 | None,\n    tuple[\n        tuple[ImageTypeUint64, list[list[np.float64]], ImageTypeFloat64],\n        tuple[list[Any], list[np.float64], list[np.float64]],\n        tuple[dict[np.float64, int], dict[np.float64, int]],\n    ],\n]:\n    \"\"\"Calculate skew angle.\"\"\"\n    num_angles = round(np.pi / min_deviation)\n    imagergb = rgba2rgb(image) if len(image.shape) == 3 and image.shape[2] == 4 else image  # type: ignore[no-untyped-call]\n    img = rgb2gray(imagergb) if len(imagergb.shape) == 3 else imagergb\n    edges = canny(img, sigma=sigma)  # type: ignore[no-untyped-call]\n    out, angles, distances = hough_line(edges, np.linspace(-np.pi / 2, np.pi / 2, num_angles, endpoint=False))  # type: ignore[no-untyped-call]\n    hough_line_out = (out, angles, distances)\n\n    hspace, angles_peaks, dists = hough_line_peaks(  # type: ignore[no-untyped-call]\n        out,\n        angles,\n        distances,\n        num_peaks=num_peaks,\n        threshold=0.05 * np.max(out),\n    )\n    hough_line_peaks_out = (hspace, angles_peaks, dists)\n\n    if len(angles_peaks) == 0:\n        return None, (hough_line_out, hough_line_peaks_out, ({}, {}))\n\n    freqs_original: dict[np.float64, int] = {}\n    for peak in angles_peaks:\n        freqs_original.setdefault(peak, 0)\n        freqs_original[peak] += 1\n\n    angles_peaks_corrected = [\n        (a % np.pi - np.pi / 2) if angle_pm_90 else ((a + np.pi / 4) % (np.pi / 2) - np.pi / 4)\n        for a in angles_peaks\n    ]\n    angles_peaks_filtred = (\n        [a for a in angles_peaks_corrected if a >= min_angle]\n        if min_angle is not None\n        else angles_peaks_corrected\n    )\n    angles_peaks_filtred = (\n        [a for a in angles_peaks_filtred if a <= max_angle] if max_angle is not None else angles_peaks_filtred\n    )\n    if not angles_peaks_filtred:\n        return None, (hough_line_out, hough_line_peaks_out, ({}, {}))\n\n    freqs: dict[np.float64, int] = {}\n    for peak in angles_peaks_filtred:\n        freqs.setdefault(peak, 0)\n        freqs[peak] += 1\n\n    sorted_keys = sorted(freqs.keys(), key=freqs.get, reverse=True)  # type: ignore[arg-type]\n    max_freq = freqs[sorted_keys[0]]\n\n    angle = None\n    for sorted_key in sorted_keys:\n        if freqs[sorted_key] == max_freq:\n            angle = sorted_key\n            break\n\n    return (\n        angle,\n        (hough_line_out, hough_line_peaks_out, (freqs_original, freqs)),\n    )\n",
      "asOf": "2026-11-20"
    },
    "F200": {
      "label": "Project source file, scikit-image",
      "display": "deskew/__init__.py",
      "asOf": "2026-11-20"
    },
    "F201": {
      "label": "Project full_name, scikit-image",
      "display": "sbrunner/deskew",
      "asOf": "2026-11-20"
    },
    "F202": {
      "label": "Project stargazers_count, scikit-image",
      "display": "531",
      "asOf": "2026-11-20"
    },
    "F203": {
      "label": "Library name, torchvision",
      "display": "TorchVision",
      "asOf": "2026-11-20"
    },
    "F204": {
      "label": "Monthly downloads, torchvision",
      "display": "18.0M",
      "asOf": "2026-11-20"
    },
    "F205": {
      "label": "License, torchvision",
      "display": "BSD",
      "asOf": "2026-11-20"
    },
    "F206": {
      "label": "Package release, torchvision",
      "display": "0.29.2",
      "asOf": "2026-11-20"
    },
    "F207": {
      "label": "Package release date, torchvision",
      "display": "Oct 2026",
      "asOf": "2026-11-20"
    },
    "F208": {
      "label": "Install, torchvision",
      "display": "python3 -m pip install torchvision",
      "asOf": "2026-11-20"
    },
    "F209": {
      "label": "Quickstart, torchvision",
      "display": "from torchvision.models import resnet50, ResNet50_Weights\nmodel = resnet50(weights=None)\n",
      "asOf": "2026-11-20"
    },
    "F210": {
      "label": "Repository stars, torchvision",
      "display": "18.0K",
      "asOf": "2026-11-20"
    },
    "F211": {
      "label": "Neural model loader, torchvision",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F212": {
      "label": "PyTorch required, torchvision",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F213": {
      "label": "Task and stack role, torchvision",
      "display": "PyTorch vision datasets, transforms, and pretrained model factories, useful when those APIs already form the training/inference stack.",
      "asOf": "2026-11-20"
    },
    "F214": {
      "label": "Download scope, torchvision",
      "display": "Whole distribution installations, including dependency overlap and use outside this page. Not distinct developers or computer-vision-only adoption.",
      "asOf": "2026-11-20"
    },
    "F215": {
      "label": "Project function, torchvision",
      "display": "def __init__(\n    self,\n    folder,\n    image_size,\n    exts = ['jpg', 'jpeg', 'png', 'tiff'],\n    augment_horizontal_flip = False,\n    convert_image_to = None\n):\n    super().__init__()\n    self.folder = folder\n    self.image_size = image_size\n    self.paths = [p for ext in exts for p in Path(f'{folder}').glob(f'**/*.{ext}')]\n\n    maybe_convert_fn = partial(convert_image_to_fn, convert_image_to) if exists(convert_image_to) else nn.Identity()\n\n    self.transform = T.Compose([\n        T.Lambda(maybe_convert_fn),\n        T.Resize(image_size),\n        T.RandomHorizontalFlip() if augment_horizontal_flip else nn.Identity(),\n        T.CenterCrop(image_size),\n        T.ToTensor()\n    ])\n",
      "asOf": "2026-11-20"
    },
    "F216": {
      "label": "Project source file, torchvision",
      "display": "denoising_diffusion_pytorch/denoising_diffusion_pytorch.py",
      "asOf": "2026-11-20"
    },
    "F217": {
      "label": "Project full_name, torchvision",
      "display": "lucidrains/denoising-diffusion-pytorch",
      "asOf": "2026-11-20"
    },
    "F218": {
      "label": "Project stargazers_count, torchvision",
      "display": "10.7K",
      "asOf": "2026-11-20"
    },
    "F219": {
      "label": "Library name, tensorflow",
      "display": "TensorFlow",
      "asOf": "2026-11-20"
    },
    "F220": {
      "label": "Monthly downloads, tensorflow",
      "display": "12.4M",
      "asOf": "2026-11-20"
    },
    "F221": {
      "label": "License, tensorflow",
      "display": "Apache-2.0",
      "asOf": "2026-11-20"
    },
    "F222": {
      "label": "Package release, tensorflow",
      "display": "2.21.0",
      "asOf": "2026-11-20"
    },
    "F223": {
      "label": "Package release date, tensorflow",
      "display": "Mar 2026",
      "asOf": "2026-11-20"
    },
    "F224": {
      "label": "Install, tensorflow",
      "display": "python3 -m pip install tensorflow",
      "asOf": "2026-11-20"
    },
    "F225": {
      "label": "Quickstart, tensorflow",
      "display": "import tensorflow as tf\nimage = tf.zeros([224, 224, 3])\nflipped = tf.image.flip_left_right(image)\n",
      "asOf": "2026-11-20"
    },
    "F226": {
      "label": "Official description, tensorflow",
      "display": "Provides an open-source machine learning framework.",
      "asOf": "2026-11-20"
    },
    "F227": {
      "label": "Quickstart source file, tensorflow",
      "display": "tensorflow/python/ops/image_ops_impl.py",
      "asOf": "2026-11-20"
    },
    "F228": {
      "label": "Repository stars, tensorflow",
      "display": "201.6K",
      "asOf": "2026-11-20"
    },
    "F229": {
      "label": "Neural model loader, tensorflow",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F230": {
      "label": "PyTorch required, tensorflow",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F231": {
      "label": "Task and stack role, tensorflow",
      "display": "Native TensorFlow image/tensor processing and execution framework; tf.image is distinct from the Keras model-definition interface. tf.keras delegates to Keras3 by default rather than an independently ranked second Keras implementation.",
      "asOf": "2026-11-20"
    },
    "F232": {
      "label": "Download scope, tensorflow",
      "display": "Whole distribution installations, including dependency overlap and use outside this page. Not distinct developers or computer-vision-only adoption.",
      "asOf": "2026-11-20"
    },
    "F233": {
      "label": "Library name, keras",
      "display": "Keras",
      "asOf": "2026-11-20"
    },
    "F234": {
      "label": "Monthly downloads, keras",
      "display": "12.0M",
      "asOf": "2026-11-20"
    },
    "F235": {
      "label": "License, keras",
      "display": "Apache-2.0",
      "asOf": "2026-11-20"
    },
    "F236": {
      "label": "Package release, keras",
      "display": "3.15.1",
      "asOf": "2026-11-20"
    },
    "F237": {
      "label": "Package release date, keras",
      "display": "Jul 2026",
      "asOf": "2026-11-20"
    },
    "F238": {
      "label": "Install, keras",
      "display": "python3 -m pip install keras tensorflow",
      "asOf": "2026-11-20"
    },
    "F239": {
      "label": "Quickstart, keras",
      "display": "from keras.applications.resnet50 import ResNet50\nmodel = ResNet50(weights='imagenet')\n",
      "asOf": "2026-11-20"
    },
    "F240": {
      "label": "Official description, keras",
      "display": "Provides multi-backend Keras.",
      "asOf": "2026-11-20"
    },
    "F241": {
      "label": "Quickstart source file, keras",
      "display": "templates/api/applications/index.md",
      "asOf": "2026-11-20"
    },
    "F242": {
      "label": "Repository stars, keras",
      "display": "64.4K",
      "asOf": "2026-11-20"
    },
    "F243": {
      "label": "Neural model loader, keras",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F244": {
      "label": "PyTorch required, keras",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F245": {
      "label": "Task and stack role, keras",
      "display": "Functional/sequential neural-network construction and Applications model factories with TensorFlow, JAX, or PyTorch backend selection.",
      "asOf": "2026-11-20"
    },
    "F246": {
      "label": "Download scope, keras",
      "display": "Whole distribution installations, including dependency overlap and use outside this page. Not distinct developers or computer-vision-only adoption.",
      "asOf": "2026-11-20"
    },
    "F247": {
      "label": "Backend setup, keras",
      "display": "Select and install TensorFlow, JAX, or PyTorch; the keras package itself does not bundle an execution engine.",
      "asOf": "2026-11-20"
    },
    "F248": {
      "label": "Project function, keras",
      "display": "def make_model(input_shape, num_classes):\n    inputs = keras.Input(shape=input_shape)\n\n    # Entry block\n    x = layers.Rescaling(1.0 / 255)(inputs)\n    x = layers.Conv2D(128, 3, strides=2, padding=\"same\")(x)\n    x = layers.BatchNormalization()(x)\n    x = layers.Activation(\"relu\")(x)\n\n    previous_block_activation = x  # Set aside residual\n\n    for size in [256, 512, 728]:\n        x = layers.Activation(\"relu\")(x)\n        x = layers.SeparableConv2D(size, 3, padding=\"same\")(x)\n        x = layers.BatchNormalization()(x)\n\n        x = layers.Activation(\"relu\")(x)\n        x = layers.SeparableConv2D(size, 3, padding=\"same\")(x)\n        x = layers.BatchNormalization()(x)\n\n        x = layers.MaxPooling2D(3, strides=2, padding=\"same\")(x)\n\n        # Project residual\n        residual = layers.Conv2D(size, 1, strides=2, padding=\"same\")(\n            previous_block_activation\n        )\n        x = layers.add([x, residual])  # Add back residual\n        previous_block_activation = x  # Set aside next residual\n\n    x = layers.SeparableConv2D(1024, 3, padding=\"same\")(x)\n    x = layers.BatchNormalization()(x)\n    x = layers.Activation(\"relu\")(x)\n\n    x = layers.GlobalAveragePooling2D()(x)\n    if num_classes == 2:\n        units = 1\n    else:\n        units = num_classes\n\n    x = layers.Dropout(0.25)(x)\n    # We specify activation=None so as to return logits\n    outputs = layers.Dense(units, activation=None)(x)\n    return keras.Model(inputs, outputs)\n",
      "asOf": "2026-11-20"
    },
    "F249": {
      "label": "Project source file, keras",
      "display": "examples/vision/image_classification_from_scratch.py",
      "asOf": "2026-11-20"
    },
    "F250": {
      "label": "Project full_name, keras",
      "display": "keras-team/keras-io",
      "asOf": "2026-11-20"
    },
    "F251": {
      "label": "Project stargazers_count, keras",
      "display": "3.0K",
      "asOf": "2026-11-20"
    },
    "F252": {
      "label": "Library name, timm",
      "display": "timm",
      "asOf": "2026-11-20"
    },
    "F253": {
      "label": "Monthly downloads, timm",
      "display": "11.7M",
      "asOf": "2026-11-20"
    },
    "F254": {
      "label": "License, timm",
      "display": "Apache-2.0",
      "asOf": "2026-11-20"
    },
    "F255": {
      "label": "Package release, timm",
      "display": "1.0.31",
      "asOf": "2026-11-20"
    },
    "F256": {
      "label": "Package release date, timm",
      "display": "Nov 2026",
      "asOf": "2026-11-20"
    },
    "F257": {
      "label": "Install, timm",
      "display": "python3 -m pip install timm",
      "asOf": "2026-11-20"
    },
    "F258": {
      "label": "Quickstart, timm",
      "display": "import timm\nm = timm.create_model('mobilenetv3_large_100', pretrained=True)\nm.eval()\n",
      "asOf": "2026-11-20"
    },
    "F259": {
      "label": "Official description, timm",
      "display": "Provides PyTorch image models.",
      "asOf": "2026-11-20"
    },
    "F260": {
      "label": "Quickstart source file, timm",
      "display": "hfdocs/source/quickstart.mdx",
      "asOf": "2026-11-20"
    },
    "F261": {
      "label": "Repository stars, timm",
      "display": "37.3K",
      "asOf": "2026-11-20"
    },
    "F262": {
      "label": "Neural model loader, timm",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F263": {
      "label": "PyTorch required, timm",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F264": {
      "label": "Task and stack role, timm",
      "display": "PyTorch image-model collection with model-specific data configurations and image transform factories; distinct model-zoo interface from TorchVision.",
      "asOf": "2026-11-20"
    },
    "F265": {
      "label": "Download scope, timm",
      "display": "Whole distribution installations, including dependency overlap and use outside this page. Not distinct developers or computer-vision-only adoption.",
      "asOf": "2026-11-20"
    },
    "F266": {
      "label": "Project function, timm",
      "display": "def __init__(\n    self,\n    pretrained_cfg: dict[str, Any],\n    architecture: str | None = None,\n    **kwargs,\n):\n    super().__init__(architecture=architecture)\n\n    self.data_config = timm.data.resolve_data_config(pretrained_cfg, model=None, verbose=False)\n    self.val_transforms = timm.data.create_transform(**self.data_config, is_training=False)\n\n    # useful for training\n    self.train_transforms = timm.data.create_transform(**self.data_config, is_training=True)\n\n    # If `ToTensor` is in the transforms, then the input should be numpy array or PIL image.\n    # Otherwise, the input can be a tensor. In later timm versions, `MaybeToTensor` is used\n    # which can handle both numpy arrays / PIL images and tensors.\n    self._not_supports_tensor_input = any(\n        transform.__class__.__name__ == \"ToTensor\" for transform in self.val_transforms.transforms\n    )\n",
      "asOf": "2026-11-20"
    },
    "F267": {
      "label": "Project source file, timm",
      "display": "src/transformers/models/timm_wrapper/image_processing_timm_wrapper.py",
      "asOf": "2026-11-20"
    },
    "F268": {
      "label": "Project full_name, timm",
      "display": "huggingface/transformers",
      "asOf": "2026-11-20"
    },
    "F269": {
      "label": "Project stargazers_count, timm",
      "display": "169.2K",
      "asOf": "2026-11-20"
    }
  },
  "dataCheckedAt": "2026-11-20",
  "agent": {
    "exaCall": {
      "endpoint": "/search",
      "body": {
        "query": "Best Python computer vision libraries OpenCV scikit-image Kornia Torchvision code examples",
        "numResults": 5
      },
      "docsUrl": "https://exa.ai/docs/reference/search"
    },
    "calls": []
  }
}
