### Setup Environment Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov5-classification-on-custom-data.ipynb Clones the YOLOv5 repository, installs dependencies, and initializes the notebook environment for YOLOv5 classification tasks. ```python import os HOME = os.getcwd() print(HOME) ``` ```python !git clone https://github.com/ultralytics/yolov5 # clone %cd yolov5 %pip install -qr requirements.txt # install import torch import utils display = utils.notebook_init() # checks ``` -------------------------------- ### Get Example Image Path and Infer Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov5-classification-on-custom-data.ipynb This snippet retrieves the path of an example image from the test or validation set of a dataset, sets an environment variable for the image path, and then runs inference using a pre-trained YOLOv5 model. ```python import os # Assuming 'dataset' object is already defined and has a 'location' attribute # Example: dataset.location = '/path/to/your/dataset' if os.path.exists(os.path.join(dataset.location, "test")): split_path = os.path.join(dataset.location, "test") else: split_path = os.path.join(dataset.location, "valid") example_class = os.listdir(split_path)[0] example_image_name = os.listdir(os.path.join(split_path, example_class))[0] example_image_path = os.path.join(split_path, example_class, example_image_name) os.environ["TEST_IMAGE_PATH"] = example_image_path print(f"Inferring on an example of the class '{example_class}'") # Infer using the predict script # !python classify/predict.py --weights runs/train-cls/exp/weights/best.pt --source $TEST_IMAGE_PATH ``` -------------------------------- ### Install Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/grounded-sam-2-auto-label.ipynb Installs the necessary libraries for using Grounded SAM 2 and Roboflow's groundingdino integration. The '-q' flag ensures a quiet installation process. ```python !pip install git+https://github.com/autodistill/autodistill-grounded-sam-2 rf_groundingdino -q ``` -------------------------------- ### Install Additional Libraries Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-segment-videos-with-sam-2.ipynb Installs the `supervision` library with assets and `jupyter_bbox_widget` for enhanced visualization in Jupyter environments. ```python !pip install -q supervision[assets] jupyter_bbox_widget ``` -------------------------------- ### Download Example Image Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov5-classification-on-custom-data.ipynb Downloads an example image (bananas.jpg) from a URL to be used for inference testing. ```python PATH_TO_IMAGE = f"{HOME}/bananas.jpg" !curl https://i.imgur.com/OczPfaz.jpg -o {PATH_TO_IMAGE} ``` -------------------------------- ### Install Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-train-yolov8-classification-no-labeling.ipynb Installs necessary Python packages for Autodistill, CLIP, YOLOv8, supervision, and Roboflow. The '-q' flag ensures a quiet installation. ```python !pip install autodistill autodistill-clip autodistill-yolov8 supervision roboflow -q ``` -------------------------------- ### Install SAM2 and Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-segment-videos-with-sam-2.ipynb Clones the SAM2 repository, changes the directory, and installs SAM2 and its dependencies using pip. It also builds the extension in-place. ```python !git clone https://github.com/facebookresearch/segment-anything-2.git %cd {HOME}/segment-anything-2 !pip install -e . -q !python setup.py build_ext --inplace ``` -------------------------------- ### Pull RF100 Repository and Setup Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-use-rf100.ipynb Clones the Roboflow 100 benchmark repository from GitHub, updates submodules, and installs the Roboflow Python package. It also changes the current directory to the repository's root. ```bash %cd /content/ !rm -rf roboflow-100-benchmark/ !git clone https://github.com/roboflow-ai/roboflow-100-benchmark.git %cd /content/roboflow-100-benchmark/ !git submodule update --init --recursive !pip install roboflow --quiet ``` -------------------------------- ### Install Roboflow Package Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov5-classification-on-custom-data.ipynb Installs the Roboflow Python package, which is necessary for downloading and managing custom datasets. ```python !pip install roboflow==1.1.48 -q ``` -------------------------------- ### Install Roboflow and Supervision Source: https://github.com/roboflow/notebooks/blob/main/notebooks/dinov2-classification.ipynb Installs the roboflow and supervision Python packages using pip. The '-q' flag ensures a quiet installation process. ```python !pip install roboflow supervision -q ``` -------------------------------- ### Clone YOLOv5 Repository and Install Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/sagemaker-studiolab/yolov5-custom-training.ipynb Clones the official YOLOv5 repository from GitHub and installs all necessary dependencies listed in the requirements.txt file. It also resets the repository to a specific commit for consistency and prints the current working directory. ```bash # Save the working directory path for later use import os HOME = os.getcwd() print(HOME) # clone YOLOv5 repository !git clone https://github.com/ultralytics/yolov5 # clone repo %cd yolov5 !git reset --hard fbe67e465375231474a2ad80a4389efc77ecff99 # install dependencies as necessary !pip install -qr requirements.txt # install dependencies (ignore errors) import torch from IPython.display import Image, clear_output # to display images from utils.downloads import attempt_download # to download models/datasets # clear_output() print('Setup complete. Using torch %s %s' % (torch.__version__, torch.cuda.get_device_properties(0) if torch.cuda.is_available() else 'CPU')) ``` -------------------------------- ### Clone YOLOv7 Repository and Install Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/sagemaker-studiolab/yolov7-custom-training.ipynb Downloads the YOLOv7 repository from GitHub and installs the necessary Python packages and PyTorch version for training. It also sets the working directory. ```python import os HOME = os.getcwd() !git clone https://github.com/WongKinYiu/yolov7 %cd yolov7 !pip install -r requirements.txt --ignore-installed !pip install torch==1.12.1 torchvision==0.13.1 --ignore-installed ``` -------------------------------- ### Setup YOLOv7 Training Environment Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-use-rf100.ipynb Navigates to the YOLOv7 directory within the benchmark repository, downloads pre-trained YOLOv7 weights, and prepares the environment for training. ```bash %cd /content/roboflow-100-benchmark/yolov7-benchmark/yolov7/ !wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7_training.pt ``` -------------------------------- ### Install Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/vector-analysis-with-sklearn-and-bokeh.ipynb Installs the necessary Python libraries: roboflow, scikit-learn, pandas, and bokeh. The '-qqq' flag suppresses most output, and '--upgrade' ensures the latest versions are installed. ```python # Install dependencies !pip install -qqq --upgrade roboflow scikit-learn pandas bokeh ``` -------------------------------- ### Install Vision Transformer Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-vision-transformer-classification-on-custom-data.ipynb Installs the Huggingface Transformers library, which is necessary for using the Vision Transformer model. This command uses pip to install directly from a Git repository. ```python !pip install -q git+https://github.com/huggingface/transformers ``` -------------------------------- ### Start Fine-tuning Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-finetune-paligemma2-on-latex-ocr-dataset.ipynb Initiates the fine-tuning process for the PaliGemma2 model using the configured `Trainer`. ```python trainer.train() ``` -------------------------------- ### Install Roboflow Package Source: https://github.com/roboflow/notebooks/blob/main/notebooks/sagemaker-studiolab/yolov7-custom-training.ipynb Installs the Roboflow Python package, which is used for loading and preparing custom datasets in the format required by YOLOv7. ```python !pip install roboflow --ignore-installed ``` -------------------------------- ### Install Autodistill and Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/dino-gpt4v-autodistill.ipynb Installs the necessary Autodistill libraries, including support for Grounding DINO and GPT-4V, using pip. The '-q' flag ensures a quiet installation. ```python !pip install autodistill autodistill-grounding-dino autodistill-gpt-4v -q ``` -------------------------------- ### Setup Roboflow for Active Learning Source: https://github.com/roboflow/notebooks/blob/main/notebooks/sagemaker-studiolab/yolov7-custom-training.ipynb Initializes the Roboflow client and sets up references to inference and upload projects. This is a prerequisite for implementing active learning workflows. ```python # # setup access to your workspace # rf = Roboflow(api_key="YOUR_API_KEY") # used above to load data # inference_project = rf.workspace().project("YOUR_PROJECT_NAME") # used above to load data; change to your own project if you used a dataset from Roboflow Universe # model = inference_project.version(1).model # upload_project = rf.workspace().project("YOUR_PROJECT_NAME") # print("inference reference point: ", inference_project) # print("upload destination: ", upload_project) ``` -------------------------------- ### Install Roboflow and Download Dataset Source: https://github.com/roboflow/notebooks/blob/main/notebooks/_train-template.ipynb Installs the Roboflow Python library and demonstrates how to download a custom dataset from Roboflow. Requires an API key, workspace, project, and dataset version. ```python # REPLACE with your custom code snippet generated above !pip install roboflow from roboflow import Roboflow rf = Roboflow(api_key="YOUR API KEY") project = rf.workspace("YOUR-WORKSPACE").project("YOUR-PROJECT") dataset = project.version("DATA-SET-VERSION").download("DATA-SET-FORMAT") ``` -------------------------------- ### Install Roboflow Package Source: https://github.com/roboflow/notebooks/blob/main/notebooks/sagemaker-studiolab/yolov5-custom-training.ipynb Installs the `roboflow` Python package, which is used to load datasets prepared in the Roboflow format. This package simplifies the process of integrating custom datasets into the YOLOv5 training pipeline. ```bash !pip install roboflow ``` -------------------------------- ### Install Roboflow and Supervision Libraries Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-finetune-paligemma-on-detection-dataset.ipynb Installs the necessary libraries for interacting with Roboflow and the supervision library for computer vision tasks. ```python !pip install -q roboflow !pip install -q git+https://github.com/roboflow/supervision.git ``` -------------------------------- ### Install CLIP Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-use-openai-clip-classification.ipynb Installs necessary dependencies for CLIP, including PyTorch with CUDA support. It checks the CUDA version to determine the correct PyTorch build and installs `ftfy` and `regex` libraries. The process restarts the notebook kernel after installation. ```python #installing some dependencies, CLIP was release in PyTorch import subprocess CUDA_version = [s for s in subprocess.check_output(["nvcc", "--version"]).decode("UTF-8").split(", ") if s.startswith("release")][0].split(" ")[-1] print("CUDA version:", CUDA_version) if CUDA_version == "10.0": torch_version_suffix = "+cu100" elif CUDA_version == "10.1": torch_version_suffix = "+cu101" elif CUDA_version == "10.2": torch_version_suffix = "" else: torch_version_suffix = "+cu110" !pip install torch==1.7.1{torch_version_suffix} torchvision==0.8.2{torch_version_suffix} -f https://download.pytorch.org/whl/torch_stable.html ftfy regex import numpy as np import torch import os print("Torch version:", torch.__version__) os.kill(os.getpid(), 9) #Your notebook process will restart after these installs ``` -------------------------------- ### Install Evaluate Library Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-finetune-paligemma2-on-latex-ocr-dataset.ipynb This command installs the 'evaluate' library, which is essential for calculating various performance metrics, such as BLEU, for evaluating language models. ```bash !pip install -q evaluate ``` -------------------------------- ### Install Libraries Source: https://github.com/roboflow/notebooks/blob/main/notebooks/sagemaker-studiolab/stable-diffusion-img2img.ipynb Installs the required libraries for the Stable Diffusion img2img pipeline, including transformers, diffusers, accelerate, torch, ipywidgets, and ftfy. ```python !pip install -q transformers diffusers accelerate torch==1.13.1 ``` ```python !pip install -q "ipywidgets>=7,<8" ftfy ``` -------------------------------- ### Install Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-finetune-paligemma2-on-latex-ocr-dataset.ipynb Installs necessary Python libraries for the project, including roboflow for dataset management, supervision for computer vision tasks, and peft/bitsandbytes for efficient model training. ```python !pip install -q roboflow supervision peft bitsandbytes ``` -------------------------------- ### Install YOLOv8 from Source (for Development) Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov8-classification-on-custom-dataset.ipynb Installs the Ultralytics YOLOv8 library by cloning the repository and installing it in editable mode. This is useful for developers contributing to the library or needing the latest unreleased features. ```python # Git clone method (for development) # %cd {HOME} # !git clone github.com/ultralytics/ultralytics # %cd {HOME}/ultralytics # !pip install -e . # from IPython import display # display.clear_output() # import ultralytics # ultralytics.checks() ``` -------------------------------- ### Install YOLOv7 Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov7-object-detection-on-custom-data.ipynb This code snippet installs the necessary dependencies for training YOLOv7. It clones the YOLOv7 repository (a patched version for compatibility), checks out a specific branch, and installs requirements. It also includes a check for GPU availability. ```shell !nvidia-smi ``` ```shell # Download YOLOv7 repository and install requirements # !git clone https://github.com/WongKinYiu/yolov7 # %cd yolov7 # !pip install -r requirements.txt # current version of YOLOv7 is not compatible with pytorch>1.12.1 and numpy>1.20.1 # until the appropriate changes get made to the main repository, we will be using a fork containing the patched code # you can track the progress here: https://github.com/roboflow/notebooks/issues/27 !git clone https://github.com/SkalskiP/yolov7.git %cd yolov7 !git checkout fix/problems_associated_with_the_latest_versions_of_pytorch_and_numpy !pip install -r requirements.txt ``` -------------------------------- ### Bug Reporting and Contribution Guide Source: https://github.com/roboflow/notebooks/blob/main/README.md Details how users can report bugs or suggest new features for the Roboflow notebooks. It also provides a guide for users who wish to contribute their own tutorials, including a link to the contribution guidelines. ```Markdown ## 🐞 bugs & 🦸 contribution Computer Vision moves fast! Sometimes our notebooks lag a tad behind the ever-pushing forward libraries. If you notice that any of the notebooks is not working properly, create a [bug report](https://github.com/roboflow-ai/notebooks/issues/new?assignees=&labels=bug%2Ctriage&template=bug-report.yml) and let us know. If you have an idea for a new tutorial we should do, create a [feature request](https://github.com/roboflow-ai/notebooks/issues/new?assignees=&labels=enhancement&template=feature-request.yml). We are constantly looking for new ideas. If you feel up to the task and want to create a tutorial yourself, please take a peek at our [contribution guide](https://github.com/roboflow-ai/notebooks/blob/main/CONTRIBUTING.md). There you can find all the information you need. We are here for you, so don't hesitate to [reach out](https://github.com/roboflow-ai/notebooks/discussions). ``` -------------------------------- ### Download YOLOv7 Checkpoint Source: https://github.com/roboflow/notebooks/blob/main/notebooks/sagemaker-studiolab/yolov7-custom-training.ipynb This command downloads the pre-trained YOLOv7 weights from its official GitHub repository. These weights serve as a starting point for custom training. ```shell # download COCO starting checkpoint %cd {HOME}/yolov7 !wget "https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7.pt" ``` -------------------------------- ### Install Requests Toolbelt Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-generate-segmentation-mask-with-roboflow.ipynb Installs the 'requests_toolbelt' library, which provides utilities for making HTTP requests, including multipart encoding, necessary for uploading images. ```python ! ``` -------------------------------- ### Fetch Big Vision Repository and Install Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-finetune-paligemma-on-detection-dataset.ipynb Clones the Big Vision repository from GitHub and installs essential Python packages like overrides, ml_collections, einops, and sentencepiece. ```python import os import sys # TPUs with if "COLAB_TPU_ADDR" in os.environ: raise "It seems you are using Colab with remote TPUs which is not supported." # Fetch big_vision repository if python doesn't know about it and install # dependencies needed for this notebook. if not os.path.exists("big_vision_repo"): !git clone --quiet --branch=main --depth=1 \ https://github.com/google-research/big_vision big_vision_repo # Append big_vision code to python import path if "big_vision_repo" not in sys.path: sys.path.append("big_vision_repo") # Install missing dependencies. Assume jax~=0.4.25 with GPU available. !pip3 install -q "overrides" "ml_collections" "einops~=0.7" "sentencepiece" ``` -------------------------------- ### YouTube Inference Example Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov5-classification-on-custom-data.ipynb This snippet shows how to run inference directly on a YouTube video using the YOLOv5 predict script by providing the video's URL as the source. ```python # !python classify/predict.py --weights runs/train-cls/exp/weights/best.pt --source 'https://www.youtube.com/watch?v=7AlYA4ItA74' ``` -------------------------------- ### Initialize Roboflow for CLIP Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-use-openai-clip-classification.ipynb Installs the Roboflow Python package and initializes the Roboflow client with the `clip` model format and the `roboflow-clip` notebook identifier. This is used for downloading datasets. ```python #follow the link below to get your download code from from Roboflow !pip install -q roboflow from roboflow import Roboflow rf = Roboflow(model_format="clip", notebook="roboflow-clip") ``` -------------------------------- ### Directory Inference Example Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov5-classification-on-custom-data.ipynb This snippet demonstrates how to perform inference on all images within a specified directory using the YOLOv5 predict script. It first sets an environment variable for the directory path and then executes the prediction command. ```python # Assuming 'test_class_path' is defined or obtained previously # Example: test_class_path = '/path/to/your/test/class' os.environ["TEST_CLASS_PATH"] = test_class_path print(f"Infering on all images from the directory {os.environ['TEST_CLASS_PATH']}") # !python classify/predict.py --weights runs/train-cls/exp/weights/best.pt --source /$TEST_CLASS_PATH/ ``` -------------------------------- ### Image Generation Example Source: https://github.com/roboflow/notebooks/blob/main/notebooks/sagemaker-studiolab/stable-diffusion-image-generation.ipynb Demonstrates how to call the `generate_images` function with specific parameters, including a prompt, total number of images, guidance scale, and enabling image display. ```python # 1000 images takes 2-3 hours on a SageMaker Studio Lab GPU instance. # You can adjust the total image number below generate_images("aerial view of cattle", 12, guidance_scale=4, display_images=True) ``` -------------------------------- ### Download YOLOv7 Training Checkpoint Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov7-object-detection-on-custom-data.ipynb Downloads the pre-trained YOLOv7 weights necessary for custom training. This checkpoint serves as a starting point for fine-tuning the model on a custom dataset. ```bash %cd /content/yolov7 !wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7_training.pt ``` -------------------------------- ### Roboflow Data Download and Preprocessing Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-vision-transformer-classification-on-custom-data.ipynb This section details the steps required to preprocess and download a dataset from Roboflow. Key actions include resizing images to 224x224 pixels and selecting the 'Folder Structure' export format. It also directs users to Roboflow's 'Getting Started Guide' for data integration. ```markdown # Download the Data We'll preprocess and download our dataset from Roboflow. To preprocess the images, change the size of the image to 224x224. To download the dataset, use the "**Folder Structure**" export format. To get your data into Roboflow, follow the [Getting Started Guide](https://blog.roboflow.com/getting-started-with-roboflow/). Note: This data has already been preprocessed through Roboflow; we HIGHLY reccommend you follow the [accompanying blog](blog.roboflow.com/how-to-train-the-huggingface-vision-transformer-on-a-custom-dataset/) as you go through this notebook. ![folder.PNG](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAeoAAAB7CAYAAAC7IMNoAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFiUAABYlAUlSJPAAABGgSURBVHhe7d0NsFRlHcfxnZickkYmLIqwAgox8o1AgquAkHPkEIasyGDEstJ7EUrLa1AKtQKHF96MaIacRTFIsUwLUPHgQYtgyHQEAm6mLy/OAJe3p78Pbv/e8899+ze3b378uzd72fmP/ee5zxnz9mz8vz2vF1TDgAABIugBgAgYAQ1AAABI6gBAAgYQQ0AQMAIagAAAkZQAwAQMIIaAICAEdQAAASMoAYAIGAENQAAASOoAQAIGEENAEDACGoAAAJGUAMAEDCCGgCAgBHUAAAEjKAGACBgBDUAAAEjqAEACBhBDQBAwAhqAAACRlADABCwooL6mmuucalUKmtpfq3Zvn2727Rpk2tubs60AABQfZ0K6qFDh7pJkya1q3vvvTfTs3aMHz/ev6dVq1ZlWgAAqL5OBfWCBQsyLbWPoAYAhKjsQb106VI3aNAg161bN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ydeo1XgpqzZdc4ZWvHTt3+aPp6Gl8hZWdXs8nqJPkG572fu1LTjalDmrb31Fq1/5N2u/aP5qftB+ASomHdblDWoIK6kfuSD/iFK94f12jVn9V9DS4lb1e0qn0xhGt8yx81T/eT/M1z65DW9/4lwIrgrp4uYIoSn1USSxE4uFjYWDXtpPWEe97009u99MdlZQiqKN084lO7es1bXty7R8LyCT5hqe9X1tfNuUO6hc3bvbtHVXSfgAqKRrW5Q5pCSqoO7pGbaXryuqvip7Gtsr1ejZv+W8I6szPvHSVI+qkdcT7xqdzKXVQi53Gt9fMte2lCGp7v6EcUUf7AqGysC53SEtNBvXAvun+w05N/4yf4rbXSwrN9/ZOz9Md4Rb4SWFvN6npCFzTBHX1g1oBoX7FXKOOz4+K97VASrqeHVdMUGt9d9/zQGaqPdtWu4ZbbFDb/uooPO09dOYadb7rkvj+jlI/nfbfs7f9TXVAaHQGrFSPYOVSc0Gtm8jUV9eKdz+Rvlat2vaX1j72evEAtrCNXpPW72pb9s ``` -------------------------------- ### Fine-Tune PaliGemma2 on Object Detection Dataset Source: https://github.com/roboflow/notebooks/blob/main/README.md This notebook guides users through fine-tuning the PaliGemma2 model for object detection tasks. It includes setup for object detection datasets and training procedures. ```Python import tensorflow as tf from official.vision.configs import datasets from official.vision.configs import models # Configuration for PaliGemma2 fine-tuning on object detection # This is a conceptual representation, actual code would involve specific model and dataset loading config = { "model": { "name": "paligemma2", "backbone": "resnet50", "pretrained_weights": "imagenet" }, "dataset": { "type": "object_detection", "path": "/path/to/your/object_detection_dataset" }, "training": { "epochs": 10, "batch_size": 32, "learning_rate": 0.001 } } # Placeholder for model training logic print("Starting PaliGemma2 fine-tuning for object detection...") # model = build_model(config.model) # dataset = load_dataset(config.dataset) # train(model, dataset, config.training) print("Fine-tuning process initiated.") ``` -------------------------------- ### Fine-Tune Florence-2 on Object Detection Dataset Source: https://github.com/roboflow/notebooks/blob/main/README.md This notebook guides users through fine-tuning the Florence-2 model for object detection tasks. It includes setup instructions for Colab and Kaggle, along with links to a Roboflow blog post and YouTube tutorial. ```Python from transformers import AutoProcessor, AutoModelForObjectDetection from datasets import load_dataset # Load dataset dataset = load_dataset("your_dataset_name") # Load Florence-2 model and processor model_name = "microsoft/Florence-2-large" processor = AutoProcessor.from_pretrained(model_name) model = AutoModelForObjectDetection.from_pretrained(model_name) # Prepare data for training (example) def preprocess_data(examples): # ... preprocessing steps ... return processed_examples processed_dataset = dataset.map(preprocess_data, batched=True) # Fine-tune the model # ... training arguments and trainer setup ... # trainer.train() ``` -------------------------------- ### Run Roboflow Notebooks Locally Source: https://github.com/roboflow/notebooks/blob/main/README.md Instructions for setting up a Python environment and running Roboflow notebooks locally using venv and Jupyter. ```console # clone repository and navigate to root directory git clone git@github.com:roboflow-ai/notebooks.git cd notebooks # setup python environment and activate it python3 -m venv venv source venv/bin/activate # install and run jupyter notebook pip install notebook jupyter notebook ``` -------------------------------- ### Prepare Custom Dataset Directory Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov5-classification-on-custom-data.ipynb Creates a 'datasets' directory and changes the current working directory to it, preparing for custom dataset download. ```python import os os.makedirs("../datasets/", exist_ok=True) %cd ../datasets/ ``` -------------------------------- ### Install YOLOv8 via Pip Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov8-classification-on-custom-dataset.ipynb Installs the Ultralytics YOLOv8 library using pip. It specifies a version for reproducibility and disables activity tracking. It also checks the installed version. ```python # Pip install method (recommended) !pip install ultralytics==8.2.103 -q # prevent ultralytics from tracking your activity !yolo settings sync=False from IPython import display display.clear_output() import ultralytics ultralytics.checks() ``` -------------------------------- ### Set Home Directory and Print Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-segment-videos-with-sam-2.ipynb Defines a constant `HOME` for the current working directory and prints it. This is used for managing datasets, images, and models. ```python import os HOME = os.getcwd() print("HOME:", HOME) ``` -------------------------------- ### List Training Results Directories Source: https://github.com/roboflow/notebooks/blob/main/notebooks/sagemaker-studiolab/yolov5-custom-training.ipynb Lists the contents of the 'runs/' directory to show available training results, including saved weights and logs. ```shell %ls runs/ ``` -------------------------------- ### Install Dependencies Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-segformer-segmentation-on-custom-data.ipynb Installs necessary libraries including pytorch-lightning, transformers, datasets, and roboflow. ```python !pip install -q pytorch-lightning==2.4.0 ``` ```python !pip install -q transformers==4.46.2 datasets==2.21.0 roboflow==1.1.49 ``` -------------------------------- ### Prepare and Display Annotation Widget Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-segment-videos-with-sam-2.ipynb Selects a reference frame for annotation, loads its image data, and initializes a BBoxWidget for interactive object bounding box annotation. The widget is then displayed for user input. ```python FRAME_IDX = 0 FRAME_PATH = Path(SOURCE_FRAMES) / f"{FRAME_IDX:05d}.jpeg" widget = BBoxWidget(classes=OBJECTS) widget.image = encode_image(FRAME_PATH) widget ``` -------------------------------- ### Install sacrebleu Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-finetune-paligemma2-on-latex-ocr-dataset.ipynb Installs the sacrebleu library, which is often a dependency for calculating translation metrics like BLEU and TER. ```python !pip install -q sacrebleu ``` -------------------------------- ### Run YOLOv7 Custom Training Source: https://github.com/roboflow/notebooks/blob/main/notebooks/sagemaker-studiolab/yolov7-custom-training.ipynb This command initiates the custom training process for YOLOv7. It specifies the batch size, configuration file, number of epochs, dataset path, pre-trained weights, and the device to use for training. ```shell # run this cell to begin training %cd {HOME}/yolov7 !python train.py --batch 8 --cfg cfg/training/yolov7.yaml --epochs 100 --data {dataset.location}/data.yaml --weights 'yolov7.pt' --device 0 ``` -------------------------------- ### Training Arguments and Trainer Setup Source: https://github.com/roboflow/notebooks/blob/main/notebooks/how-to-finetune-paligemma2-on-latex-ocr-dataset.ipynb Configures the `TrainingArguments` for fine-tuning, including epochs, batch size, learning rate, optimizer, and saving strategies. It then initializes the `Trainer` with the model, datasets, data collator, and arguments. ```python from transformers import Trainer, TrainingArguments args = TrainingArguments( num_train_epochs=3, remove_unused_columns=False, per_device_train_batch_size=3, gradient_accumulation_steps=12, warmup_steps=2, learning_rate=2e-5, weight_decay=1e-6, adam_beta2=0.999, logging_steps=100, optim="paged_adamw_8bit" if USE_QLORA else "adamw_hf", save_strategy="steps", save_steps=1000, save_total_limit=1, output_dir="paligemma2_latex_ocr_v5", bf16=True, report_to=["tensorboard"], dataloader_pin_memory=False ) trainer = Trainer( model=model, train_dataset=train_dataset, eval_dataset=valid_dataset, data_collator=collate_fn, args=args ) ``` -------------------------------- ### Download Custom Dataset with Roboflow Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov5-classification-on-custom-data.ipynb Logs into Roboflow, accesses a specific project ('banana-ripeness-classification-3dyre'), and downloads version 1 of the dataset in folder structure. ```python import roboflow roboflow.login() rf = roboflow.Roboflow() project = rf.workspace("model-examples").project("banana-ripeness-classification-3dyre") dataset = project.version(1).download("folder") ``` -------------------------------- ### Install Roboflow Inference Server (GPU) Source: https://github.com/roboflow/notebooks/blob/main/notebooks/train-yolov7-object-detection-on-custom-data.ipynb This command pulls the Docker image for the Roboflow Inference Server with GPU support. Ensure you have Docker installed and configured for GPU access. ```docker docker pull roboflow/roboflow-inference-server-gpu ```