johko / computer-vision-course

This repo is the homebase of a community driven course on Computer Vision with Neural Networks. Feel free to join us on the Hugging Face discord: hf.co/join/discord
MIT License
376 stars 124 forks source link

Unit-3 Chapter-3 Vision Transformers Transfer learning for classification. #67

Closed Anindyadeep closed 5 months ago

Anindyadeep commented 7 months ago

This PR is contributed by @shreydan @Anindyadeep @alanahmet @hanouticelina @asusevski @sezan92

In this PR, the following things are added:

  1. The initial code for classification using transfer learning.

    1. Model: google/vit-base-patch16-224: this is the most downloaded and well-known base transformer model.
    2. Dataset: oxford-iiit pets datasethf-link - quite a popular dataset for image classification on the HF hub.
    3. Exclusively used HuggingFace API, that includes datasets, evaluate and transformers
  2. This initial PR is merged in the forked repo after review by @Anindyadeep @sezan92 and @alanahmet

  3. This also adds the code

Some questions to the reviewers in the main repo.

  1. Should we only prioritize HuggingFace APIs or should we also include custom loops using PyTorch in the end.
  2. For Transfer Learning / Fine-tuning, should we also add segmentation and object detection along with classification? (more explained in this issue)
  3. Right now this PR only adds some codes for running, transfer learning for classification. But, how should we structure the folder? Should we follow this examples?
  4. Transfer Learning
    1. Classification.mdx
    2. Object detection.mdx
    3. segmentation.mdx
      1. Fine-tuning
    4. Classification.mdx
    5. Object detection.mdx
    6. segmentation.mdx

Or, should we have follow a structure where we have two files for Transfer learning and fine-tuning and inside that, we include all of the tasks at once.

.
└── course/
    └── chapters/
        ├── chapter3/
        │   ├── Transfer Learning and Fine-tuning/
                        └── transfer-learning.mdx
                        └── fine-tuning.mdx
                        └── knowledge-distillation.mdx
        ├── chapter-n/
        │   └── ...mdx
        └── _toctree.yml
  1. Right now this PR adds some code for Classification using Transfer Learning, but since this is going to be a tutorial, so how much explaination (in terms of natural words) is needed and diagrams etc.

Please note: This PR only contains the Jupyter Notebook, based on the feedback, we will start creating .mdx files for the same :)

review-notebook-app[bot] commented 7 months ago

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

review-notebook-app[bot] commented 7 months ago

View / edit / reply to this conversation on ReviewNB

merveenoyan commented on 2023-12-06T16:32:30Z ----------------------------------------------------------------

Maybe add some explanation on what is this notebook for and explain the end to end process that is happening in it.

Also instead of # Imports, just write "We will now import necessary modules and functions."


review-notebook-app[bot] commented 7 months ago

View / edit / reply to this conversation on ReviewNB

merveenoyan commented on 2023-12-06T16:32:31Z ----------------------------------------------------------------

For which task?


review-notebook-app[bot] commented 7 months ago

View / edit / reply to this conversation on ReviewNB

merveenoyan commented on 2023-12-06T16:32:32Z ----------------------------------------------------------------

maybe mention this is also necessary to pass to the model since model doesn't accept string classes. (you're mentioning briefly below, you can also have this section below instead if you're not using id2label yet).


review-notebook-app[bot] commented 7 months ago

View / edit / reply to this conversation on ReviewNB

merveenoyan commented on 2023-12-06T16:32:32Z ----------------------------------------------------------------

"Let's see some sample images from the dataset."


review-notebook-app[bot] commented 7 months ago

View / edit / reply to this conversation on ReviewNB

merveenoyan commented on 2023-12-06T16:32:33Z ----------------------------------------------------------------

I saw here you're doing evaluation split but not doing end of training validation with a separate split, maybe you could have a separate split for this here (if the dataset doesn't come with a final test split)


review-notebook-app[bot] commented 7 months ago

View / edit / reply to this conversation on ReviewNB

merveenoyan commented on 2023-12-06T16:32:34Z ----------------------------------------------------------------

suggestions for clarity:

"It might be possible that some images in your dataset will be grayscale or transparent (RGBA)."

"We pass the images through the processor to apply the transforms to process and convert them into PyTorch format."

also you could carry label2id here instead


review-notebook-app[bot] commented 7 months ago

View / edit / reply to this conversation on ReviewNB

merveenoyan commented on 2023-12-06T16:32:36Z ----------------------------------------------------------------

We can set push_to_hub to True and later call push_to_hub on Trainer after the save so people can learn how to use HF Hub as model registry.


MKhalusova commented on 2023-12-08T17:56:01Z ----------------------------------------------------------------

If we set push_to_hub to True, we also need to add a call with notebook_login:

from huggingface_hub import notebook_login
notebook_login()

In this case, the output_dir will also be the name of the repo where your model checkpoint will be pushed.