Image Classification ==================== .. image:: https://production-media.paperswithcode.com/thumbnails/task/task-0000000951-52325f45_O0tAMly.jpg :align: right :width: 20% Image Classification is a fundamental task that attempts to comprehend an entire image as a whole. The goal is to classify the image by assigning it to a specific label. Typically, Image Classification refers to images in which only one object appears and is analyzed. In contrast, object detection involves both classification and localization tasks, and is used to analyze more realistic cases in which multiple objects may exist in an image. Learn more: `https://paperswithcode.com/task/image-classification `_ Inference --------- Kornia provides a couple of backbones based on `transformers `_ to perform image classification. Checkout the following apis :py:class:`~kornia.contrib.VisionTransformer`, :py:class:`~kornia.contrib.ClassificationHead` and combine as follows to customize your own classifier: .. code:: python import torch.nn as nn import kornia.contrib as K classifier = nn.Sequential( K.VisionTransformer(image_size=224, patch_size=16), K.ClassificationHead(num_classes=1000) ) img = torch.rand(1, 3, 224, 224) out = classifier(img) # BxN scores = out.argmax(-1) # B .. tip:: Read more about our :ref:`kornia_vit` Finetuning ---------- In order to customize your model with your own data you can use our :ref:`training_api` to perform the `fine-tuning `_ of your model. We provide :py:class:`~kornia.x.ImageClassifierTrainer` with a default training structure to train basic image classification problems. However, one can leverage this is API using the models provided by Kornia or use existing libraries from the PyTorch ecosystem such as `torchvision `_ or `timm `_. Create the dataloaders: .. literalinclude:: ../_static/scripts/image_classifier.py :language: python :lines: 20-36 Define your model, losses, optimizers and schedulers: .. literalinclude:: ../_static/scripts/image_classifier.py :language: python :lines: 37-48 Define your augmentations: .. literalinclude:: ../_static/scripts/image_classifier.py :language: python :lines: 50-65 Finally, instantiate the :py:class:`~kornia.x.ImageClassifierTrainer` and execute your training pipeline. .. literalinclude:: ../_static/scripts/image_classifier.py :language: python :lines: 66-78 .. seealso:: Play with the full example `here `_