### Install open-3d Library (Standard) Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit10/point_clouds.mdx Install the open-3d Python library using pip. This is the standard installation. ```bash pip install open3d ``` -------------------------------- ### Install Optimum Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 9 - Model Optimization/optimum.ipynb Installs the Optimum library. This is the first step before importing required modules. ```python %pip install optimum ``` -------------------------------- ### Install Dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 10 - Synthetic Data Creation/Synthetic_lung_images_hf_course.ipynb Install the necessary libraries for data handling, model training, and acceleration. ```bash !pip install -q datasets huggingface_hub datasets torch torchvision accelerate ``` -------------------------------- ### Install Timm Library Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit2/cnns/mobilenetextra.mdx Required installation step before using the timm library. ```bash pip install timm ``` -------------------------------- ### Install required packages Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 4 - Multimodal Models/CLIP and relatives/Image_retrieval_with_prompts.ipynb Install the necessary libraries for transformers, torch, and datasets. ```bash pip install transformers torch datasets ``` -------------------------------- ### Install TMO and Tensorflow Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 9 - Model Optimization/tmo.ipynb Installs the necessary libraries for using TMO and Tensorflow. Use this at the beginning of your environment setup. ```python %pip install -q tensorflow %pip install -q tensorflow-model-optimization ``` -------------------------------- ### Install dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/Swin.ipynb Install the datasets library required for loading sample images. ```python %pip install datasets ``` -------------------------------- ### Install Dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 2 - Convolutional Neural Networks/timm_Resnet.ipynb Install the required libraries for the project using pip. ```bash !pip install timm torch torchvision ``` -------------------------------- ### Install Required Libraries Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 7 - Video and Video Processing/Vivit_Fine_tuned_Video_Classification.ipynb Installs pytorchvideo, evaluate, accelerate, and transformers. Suppresses output to keep the notebook clean. ```bash !pip install pytorchvideo evaluate accelerate transformers > /dev/null 2>&1 ``` -------------------------------- ### Install Edge TPU Compiler Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 9 - Model Optimization/edge_tpu.ipynb Installs the Edge TPU Compiler using apt-get. This involves adding a GPG key, a repository, and then performing an update and installation. ```bash ! curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - ! echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list ! sudo apt-get update ! sudo apt-get install edgetpu-compiler ``` -------------------------------- ### Install Transformers Library Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit3/vision-transformers/mobilevit.mdx Command to install the necessary library for accessing MobileViTv2 models. ```bash pip install transformers ``` -------------------------------- ### Install and Update Packages Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/fine-tuning-multilabel-image-classification.ipynb Installs or updates necessary Hugging Face and related libraries for the tutorial. Use -Uq for quiet updates. ```python !pip install -Uq transformers datasets timm accelerate evaluate ``` -------------------------------- ### Install PyTorch and Quantization API Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit9/tools_and_frameworks.mdx Install PyTorch and import the quantization API. This is necessary for using PyTorch's quantization features for model optimization. ```bash pip install torch ``` ```python import torch.quantization ``` -------------------------------- ### Install required dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 4 - Multimodal Models/CLIP and relatives/Clustering with CLIP.ipynb Install the necessary libraries for data processing, machine learning, and clustering. ```bash pip install transformers torch datasets matplotlib scikit-learn ``` -------------------------------- ### Install Dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit4/multimodal-models/tasks-models-part1.mdx Install additional required libraries including transformers, safetensors, accelerate, and invisible_watermark. ```bash pip install invisible_watermark transformers accelerate safetensors ``` -------------------------------- ### Install FAISS backend Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 4 - Multimodal Models/CLIP and relatives/Clustering with CLIP.ipynb Select the appropriate FAISS package based on hardware availability. ```bash #pip install faiss-gpu #pip install faiss-cpu ``` -------------------------------- ### Install Evaluate Library Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/transfer-learning-image-classification.ipynb Installs the 'evaluate' library, which is necessary for various evaluation metrics during model training. This command should be run in a notebook environment. ```bash !pip install --quiet evaluate ``` -------------------------------- ### Install Dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/LoRA-Image-Classification.ipynb Installs necessary libraries for the project, including datasets, evaluation tools, accelerate, and PEFT. ```python %%capture !pip install datasets !pip install evaluate !pip install accelerate -U !pip install peft ``` -------------------------------- ### Install Datasets Library Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 6 - Basic CV Tasks/Fine_tune_SAM_(Segment_Anything_Model)_on_Custom_Dataset.ipynb Installs the 🤗 Datasets library, which is essential for loading and processing datasets efficiently. ```python !pip install -q datasets ``` -------------------------------- ### Install Diffusers Library Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit4/multimodal-models/tasks-models-part1.mdx Install the core diffusers library to enable text-to-image generation capabilities. ```bash pip install diffusers --upgrade ``` -------------------------------- ### Install point-cloud-utils Library Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit10/point_clouds.mdx Install the point-cloud-utils library using pip. This library supports reading common mesh formats. ```bash pip install point-cloud-utils ``` -------------------------------- ### Execute Training Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/KnowledgeDistillation.ipynb Starts the training process. ```python trainer.train() ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 10 - Synthetic Data Creation/OWLV2_labeled_image_dataset_with_annotations.ipynb Installs the necessary Python libraries: transformers, huggingface_hub, and datasets. Use this for setting up the environment. ```python !pip install -q transformers huggingface_hub datasets ``` -------------------------------- ### Install Transformers Library Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 6 - Basic CV Tasks/Fine_tune_SAM_(Segment_Anything_Model)_on_Custom_Dataset.ipynb Installs the 🤗 Transformers library from its GitHub repository. This is a prerequisite for using advanced NLP and vision models. ```python !pip install -q git+https://github.com/huggingface/transformers.git ``` -------------------------------- ### Install Necessary Packages Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 10 - Synthetic Data Creation/synthetic_data_creation_sdxl_turbo.ipynb Installs the required Python packages for running the notebook, including diffusers, transformers, and other dependencies. ```python !pip install -q diffusers transformers accelerate omegaconf torchvision imagehash huggingface_hub datasets ``` -------------------------------- ### Install OpenCV Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit1/feature-extraction/feature-matching.mdx Installs the OpenCV library, which is necessary for image processing and feature matching tasks. ```bash !pip install opencv-python ``` -------------------------------- ### Install Required Libraries Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit3/vision-transformers/vision-transformer-for-object-detection.mdx Installs the necessary dependencies including Hugging Face Transformers, PyTorch, and related utilities. ```bash !pip install -U -q datasets transformers[torch] evaluate timm albumentations accelerate ``` -------------------------------- ### Install OpenVINO and NNCF dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 9 - Model Optimization/openvino.ipynb Install the required OpenVINO, NNCF, and PyTorch packages via pip. ```python %pip install -q "openvino>=2023.1.0" torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu %pip install -q "nncf>=2.6.0" ``` -------------------------------- ### Install Optimum Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit9/tools_and_frameworks.mdx Install the Optimum package using pip. This package extends Transformers for optimized model performance on specific hardware. ```bash pip install optimum ``` -------------------------------- ### Install Natten library Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit3/vision-transformers/oneformer.mdx Required dependency for the Dinat backbone used by the OneFormer model. ```bash !pip install -q natten ``` -------------------------------- ### Run Camera Sampling Example Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 10 - Synthetic Data Creation/blenderproc_examples.ipynb Execute the BlenderProc camera sampling example. Specify the main script, scene object file, output directory, and the path to your Blender installation. ```bash !blenderproc run examples/basics/camera_sampling/main.py examples/resources/scene.obj examples/basics/camera_sampling/output --blender-install-path ./ ``` -------------------------------- ### Install ipykernel and Blender Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 10 - Synthetic Data Creation/blenderproc_examples.ipynb Installs ipykernel within the Blender environment, which also triggers the initial installation of Blender. ```python !blenderproc pip install ipykernel --blender-install-path ./ ``` -------------------------------- ### Clone Repository and Download Weights Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit8/monocular_depth_estimation.mdx Initializes the environment by cloning the Depth Anything V2 repository and downloading the pre-trained ViT-S encoder checkpoint. ```bash !git clone https://github.com/DepthAnything/Depth-Anything-V2 !wget -O depth_anything_v2_vits.pth https://huggingface.co/depth-anything/Depth-Anything-V2-Small/resolve/main/depth_anything_v2_vits.pth?download=true ``` -------------------------------- ### Install PyTorch Dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 9 - Model Optimization/torch.ipynb Install the necessary torch and torchvision packages. ```python %pip install torch torchvision ``` -------------------------------- ### Train and Evaluate Model Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 2 - Convolutional Neural Networks/transfer_learning_vgg19.ipynb Set up the device, loss function, optimizer, and training parameters before executing the training loop. ```python # Send earlier defined model to device device = torch.device("cuda:0") pre_vgg19 = pre_vgg19.to(device) # Loss function, optimizer, LR scheduler loss_func = nn.CrossEntropyLoss(reduction="sum") optimizer = optim.Adam(pre_vgg19.parameters(), lr=learning_rate) lr_scheduler = CosineAnnealingLR(optimizer, T_max=5, eta_min=1e-6) # Set Training Parameters training_params = { "epochs": 10, "optimizer": optimizer, "loss_func": loss_func, "train_dl": train_loader, "val_dl": validation_loader, "check_id": False, "lr_scheduler": lr_scheduler, "path": "pre_vgg19.pt", } # Train and validate the model pre_vgg19, loss_history, metric_history = train_val( pre_vgg19, training_params, verbose=False ) ``` -------------------------------- ### Install Diffusers Library Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit5/generative-models/diffusion-models/simple-explanation.mdx Install the required diffusers library via pip. ```bash pip install diffusers ``` -------------------------------- ### Initialize OWL-ViT v2 environment Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 10 - Synthetic Data Creation/OWLV2_labeled_image_dataset_with_annotations.ipynb Sets up the necessary imports, configuration, and directory structure for running object detection. ```python import os import requests from PIL import Image from io import BytesIO from transformers import Owlv2Processor, Owlv2ForObjectDetection # We will grab some images from the hf-vison course-assets url = "https://huggingface.co/datasets/hf-vision/course-assets/resolve/main/label_dataset_owlv2" # Alternately, you can load images from a local folder # path = "" # Set the text queries text_queries = ["dog", "table", "chair", "book", "magazine", "bookcase", "fireplace", "plant", "tree", "mountain", "lake", "light", "window", "basketball", "soccer ball", "football", "volleyball", "hola hoop", "car"] # Set the number of images to generate num_images = 10 # Set the score threshold (a lower value makes it more likely that an object is detected) score_threshold = 0.20 # Create a directory for the annotated images annotated_images_dir = "/content/annotated_images" os.makedirs(annotated_images_dir, exist_ok=True) ``` -------------------------------- ### Install BlenderProc Package Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 10 - Synthetic Data Creation/blenderproc_examples.ipynb Installs the BlenderProc package in editable mode using pip. ```python !pip install -e . ``` -------------------------------- ### Initialize CLIP model and components Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 4 - Multimodal Models/CLIP and relatives/Image_retrieval_with_prompts.ipynb Load the CLIP model, processor, and tokenizer, and set the compute device. ```python #Import packages import torch from PIL import Image from transformers import AutoProcessor, CLIPModel, AutoTokenizer from datasets import load_dataset import faiss import numpy as np from tqdm import tqdm #Define device (GPU or CPU) device = torch.device('cuda' if torch.cuda.is_available() else "cpu") #Load CLIP model, processor and tokenizer processor = AutoProcessor.from_pretrained("openai/clip-vit-base-patch32") model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32").to(device) tokenizer = AutoTokenizer.from_pretrained("openai/clip-vit-base-patch32") ``` -------------------------------- ### Install ONNX Runtime Dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 9 - Model Optimization/onnx.ipynb Install the necessary packages for PyTorch and ONNX Runtime. ```python %pip install torch torchvision %pip install onnx onnxruntime ``` -------------------------------- ### Launch training with notebook_launcher Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/fine-tuning-multilabel-image-classification.ipynb Initiate the training process in a notebook environment using the specified model and hyperparameters. ```python model_name = 'swin_s3_base_224' notebook_launcher(train, (model_name,8,5,5e-5), num_processes = 2) ``` -------------------------------- ### Install timm library Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/DETR.ipynb Install the timm library required for the DETR model backbone. ```python %pip install timm ``` -------------------------------- ### Launch Training with Accelerate Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit8/monocular_depth_estimation.mdx Uses the notebook_launcher to initiate the training function with a specified number of processes. ```python # You can run this code with 1 gpu. Just set num_processes=1 notebook_launcher(train_fn, num_processes=2) ``` -------------------------------- ### Install TensorRT and Dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 9 - Model Optimization/tensorrt.ipynb Install necessary libraries including PyTorch, TensorRT, ONNX, and PyCUDA. ```python %pip install torch torchvision %pip install tensorrt==8.6.1 %pip install pycuda onnx onnxruntime %pip install --no-cache-dir --extra-index-url https://pypi.nvidia.com pytorch-quantization==2.1.2 ``` -------------------------------- ### Import libraries and configure environment Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 2 - Convolutional Neural Networks/transfer_learning_vgg19.ipynb Initializes necessary libraries for data processing, visualization, and PyTorch model training. Enables CuDNN benchmarking and selects the compute device. ```python # General imports import os import time import copy import numpy as np import collections # Plotting imports from PIL import Image import matplotlib.pyplot as plt import plotly.graph_objects as go from plotly.subplots import make_subplots import plotly.express as px # Torch imports import torch import torch.nn as nn import torch.backends.cudnn as cudnn import torch.optim as optim from torch.optim.lr_scheduler import CosineAnnealingLR # Torchvision imports import torchvision from torchvision import datasets, models from torchvision.transforms import v2 # Enable CuDNN benchmark mode for improved performance on compatible GPUs cudnn.benchmark = True # Turn on interactive mode for matplotlib plt.ion() # selecting the available device device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') print(device) ``` -------------------------------- ### Install Kornia dependencies Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit1/feature-extraction/feature-matching.mdx Install the necessary packages for Kornia and OpenCV to perform feature matching. ```bash !pip install kornia kornia-rs kornia_moons opencv-python --upgrade ``` -------------------------------- ### Initialize and Run Trainer Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/Fine-tuning Vision Transformers for Object detection.ipynb Configures the Trainer instance with the model, arguments, and datasets, then executes the training loop. ```python from transformers import Trainer trainer = Trainer( model=model, args=training_args, data_collator=collate_fn, train_dataset=train_dataset_transformed, eval_dataset=test_dataset_transformed, tokenizer=image_processor, ) trainer.train() ``` -------------------------------- ### Install BlenderProc via pip Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit10/blenderProc.mdx Use this command to install the BlenderProc library in your Python environment. ```bash pip install blenderProc ``` -------------------------------- ### Prepare Image Processor Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/LoRA-Image-Classification.ipynb Instantiates the image processor from the model repository. ```python image_processor = AutoImageProcessor.from_pretrained(model_checkpoint) ``` -------------------------------- ### Initialize CLIP model Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 4 - Multimodal Models/CLIP and relatives/Image_similarity.ipynb Load the CLIP model and processor, and set the computation device. ```python #Import packages import torch from PIL import Image from transformers import AutoProcessor, CLIPModel import faiss import numpy as np import requests from datasets import load_dataset, Dataset from tqdm import tqdm #Define device (GPU or CPU) device = torch.device('cuda' if torch.cuda.is_available() else "cpu") #Load CLIP model, processor and tokenizer processor = AutoProcessor.from_pretrained("openai/clip-vit-base-patch32") model = CLIPModel.from_pretrained("openai/clip-vit-base-patch32").to(device) ``` -------------------------------- ### Install git-lfs Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 10 - Synthetic Data Creation/OWLV2_labeled_image_dataset_with_annotations.ipynb Installs git-lfs, a Git extension for versioning large files. This is recommended for generating large datasets. ```bash !apt-get install git-lfs ``` -------------------------------- ### Initialize VivitForVideoClassification Model Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 7 - Video and Video Processing/Vivit_Fine_tuned_Video_Classification.ipynb Instantiates the `VivitForVideoClassification` model from a pre-trained checkpoint. Use `ignore_mismatched_sizes=True` if fine-tuning an already fine-tuned checkpoint. ```python from transformers import VivitForVideoClassification model = VivitForVideoClassification.from_pretrained( model_checkpt, id2label=my_id2label, label2id=my_label2id, ignore_mismatched_sizes=True, # provide this in case you're planning to fine-tune an already fine-tuned checkpoint ) ``` -------------------------------- ### Install OpenVINO Source: https://github.com/huggingface/computer-vision-course/blob/main/chapters/en/unit9/tools_and_frameworks.mdx Install the OpenVINO package using pip. This is the primary method for integrating OpenVINO into your Python projects. ```bash pip install openvino ``` -------------------------------- ### Initialize teacher model Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/KnowledgeDistillation.ipynb Load the pre-trained teacher model and evaluation tools. ```python device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') teacher_model_name = "asusevski/vit-base-patch16-224-oxford-pets" teacher_model = AutoModelForImageClassification.from_pretrained(teacher_model_name).to(device) teacher_model.eval() processor = ViTImageProcessor.from_pretrained("google/vit-base-patch16-224") accuracy = evaluate.load("accuracy") ``` -------------------------------- ### Configure Data Preprocessing and Dataloader Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 10 - Synthetic Data Creation/Synthetic_lung_images_hf_course.ipynb Sets up environment parameters, image transformation pipelines, and creates a DataLoader for training. ```python batch_size = 128 nb_gpu = 1 nb_workers = 2 # based on system resources # GPU or CPU (Not having at least 1 GPU can prevent code from working) device = torch.device("cuda:0" if (torch.cuda.is_available() and nb_gpu > 0) else "cpu") n_channels = 3 image_size = 64 input_shape = (image_size, image_size) # Set a seed for reproducibility seed = 22 random.seed(seed) torch.manual_seed(seed) torch.backends.cudnn.deterministic = True torch.backends.cudnn.benchmark = False # define the transform transform = Compose( [ Resize(image_size), CenterCrop(image_size), ToTensor(), Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)), ] ) # define function def transforms(examples): examples["image"] = [transform(image.convert("RGB")) for image in examples["image"]] return examples transformed_dataset = dataset.with_transform(transforms) #create dataloader dataloader = DataLoader( transformed_dataset["train"], batch_size=batch_size, shuffle=True, num_workers=nb_workers ) real_batch = next(iter(dataloader)) ``` -------------------------------- ### Import necessary libraries and modules Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/transfer-learning-segmentation.ipynb Initializes the environment by importing required libraries for data processing, model training, and evaluation. ```python import json import torch import datasets import requests import evaluate import numpy as np import huggingface_hub from PIL import Image import albumentations as A from tqdm.auto import tqdm import matplotlib.pyplot as plt from typing import Tuple, Any from dataclasses import dataclass from datasets import load_dataset import matplotlib.patches as mpatches from huggingface_hub import hf_hub_download from torch.utils.data import Dataset, DataLoader from transformers import ( MaskFormerImageProcessor, AutoImageProcessor, MaskFormerForInstanceSegmentation, ) torch.manual_seed(42) ``` -------------------------------- ### Initialize and Configure Discriminator Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 10 - Synthetic Data Creation/Synthetic_lung_images_hf_course.ipynb Instantiates the Discriminator, handles multi-GPU distribution, and initializes weights. ```python # Create the Discriminator disc_net = Discriminator(nb_gpu).to(device) # Handle multi-GPU if desired if (device.type == 'cuda') and (nb_gpu > 1): disc_net = nn.DataParallel(disc_net, list(range(nb_gpu))) # Apply the ``weights_init`` function to randomly initialize all weights # like this: ``to mean=0, stdev=0.2``. disc_net.apply(weights_init) # Print the model print(disc_net) ``` -------------------------------- ### Initialize Trainer Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 3 - Vision Transformers/transfer-learning-image-classification.ipynb Create the Trainer instance with the model, arguments, and dataset components. ```python trainer = Trainer( model=model, args=training_args, data_collator=collate_fn, compute_metrics=compute_metrics, train_dataset=processed_dataset["train"], eval_dataset=processed_dataset["validation"], tokenizer=processor ) ``` -------------------------------- ### Install Required Packages Source: https://github.com/huggingface/computer-vision-course/blob/main/notebooks/Unit 4 - Multimodal Models/CLIP and relatives/Image classification with CLIP.ipynb Installs the necessary libraries for image classification using CLIP, including transformers, PyTorch, datasets, matplotlib, and scikit-learn. ```bash pip install transformers torch datasets matplotlib scikit-learn ```