### Setup Environment and Dependencies Source: https://github.com/tensorflow/models/blob/master/official/projects/movinet/movinet_streaming_model_training_and_inference.ipynb Installs the necessary TensorFlow model packages, media processing tools, and documentation utilities required for the MoViNet tutorial. ```bash !pip install -U -q "tf-models-official" !command -v ffmpeg >/dev/null || (apt update && apt install -y ffmpeg) !pip install -q mediapy remotezip !pip install -U -q git+https://github.com/tensorflow/docs ``` -------------------------------- ### Setup Environment and Dependencies Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/fine_tuning/Pytorch_Image_Classifier/Train_ImageClassifier_TransferLearning.ipynb Initializes the environment by mounting Google Drive, installing necessary libraries like torchinfo, and cloning the required repository for helper functions. ```python from google.colab import drive drive.mount('/content/gdrive') !ln -s /content/gdrive/My\ Drive/ /mydrive !pip install torchinfo !git clone https://github.com/AarohiSingla/Image-Classification-Using-Vision-transformer.git %cd Image-Classification-Using-Vision-transformer ``` -------------------------------- ### Custom Training Driver Main Method Example Source: https://github.com/tensorflow/models/blob/master/official/vision/docs/customize_training_launcher.md An example of a custom launch script's main method. It shows how to set up mixed precision, get the distribution strategy, initialize a task, run the experiment using train_lib.run_experiment, and save the configuration using train_utils.save_gin_config. ```python def main(_): ……… if params.runtime.mixed_precision_dtype: performance.set_mixed_precision_policy( params.runtime.mixed_precision_dtype) distribution_strategy = \ distribute_utils.get_distribution_strategy( dist_strategy=params.runtime.distribution_strategy, all_reduce_alg=params.runtime.all_reduce_alg, num_gpus=params.runtime.num_gpus, tpu_address=params.runtime.tpu) with distribution_strategy.scope(): task = task_factory.get_task(params.task, logging_dir=model_dir) ……… train_lib.run_experiment( distribution_strategy=distribution_strategy, task=task, mode=FLAGS.mode, params=params, model_dir=model_dir) train_utils.save_gin_config(FLAGS.mode, model_dir) ……… if __name__ == '__main__': tfm_flags.define_flags() flags.mark_flags_as_required(['experiment', 'mode','model_dir']) app.run(main) ``` -------------------------------- ### Setup TensorFlow Models Environment Source: https://github.com/tensorflow/models/blob/master/official/projects/unified_detector/README.md Commands to clone the repository, install necessary dependencies, and compile protocol buffers for the Unified Detector project. ```bash pip3 install --user virtualenv virtualenv -p python3 unified_detector source ./unified_detector/bin/activate git clone https://github.com/tensorflow/models.git cd models pip3 install -r official/requirements.txt pip3 install -r official/projects/unified_detector/requirements.txt export PYTHONPATH=${PYTHONPATH}:${PWD}/research/ cd research/object_detection/ protoc protos/string_int_label_map.proto --python_out=. ``` -------------------------------- ### Setup for GPU Detection with Ollama Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/llm_applications/milk_pouch_detection_using_groundingdino-sam2-gemma3.ipynb Installs necessary utilities for Ollama to detect GPUs and installs the Ollama Python library. This is crucial for leveraging GPU acceleration in machine learning tasks. ```bash # Required for Ollama to detect GPUs. !sudo apt-get install -y pciutils lshw !pip install ollama ``` -------------------------------- ### Setup Detectron2 and Supervision Environment Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/model_conversion/detectron2_inference_and_trt_conversion.ipynb Installs the necessary Detectron2 and supervision libraries to enable instance segmentation and post-processing of model outputs. ```python !git clone -q 'https://github.com/facebookresearch/detectron2' !pip install -q 'git+https://github.com/facebookresearch/detectron2.git' !pip install -q supervision ``` -------------------------------- ### Setup Environment and Dependencies Source: https://github.com/tensorflow/models/blob/master/official/projects/yolo/darknet_image_calssification.ipynb Clones the official TensorFlow models repository and installs the necessary Python dependencies for the Model Garden project. ```bash ! git clone -q https://github.com/tensorflow/models.git ! pip install -q -U tensorflow_datasets ! pip install -q --user -r models/official/requirements.txt ``` -------------------------------- ### Setup Environment and Clone TensorFlow Models Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/model_conversion/checkpoints_to_savedModel_to_tflite.ipynb Installs necessary dependencies, mounts Google Drive for storage access, and clones the official TensorFlow models repository to the local environment. ```python !pip install tf-models-official import os from google.colab import drive import yaml import tensorflow as tf drive.mount('/content/gdrive') !ln -s /content/gdrive/My\ Drive/ /mydrive !git clone --depth 1 https://github.com/tensorflow/models %cd models ``` -------------------------------- ### Setup Ollama and Run LLM Inference Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/llm_applications/milk_pouch_detection_using_florence2-sam2-gemma3.ipynb Installs Ollama, pulls the Gemma3 model, and performs inference on the extracted object crops to classify packaging content. ```bash curl https://ollama.ai/install.sh | sh ollama serve ``` ```python !ollama pull gemma3:12b-it-qat images = glob.glob('tempdir/*.png') for path in images: response: ChatResponse = chat(model='gemma3:12b-it-qat', messages=[{'role': 'user', 'content': prompt, 'images': [path]}]) image = cv2.imread(path) plt.imshow(image) plt.show() print(f"\n{response.message.content}") ``` -------------------------------- ### Install TensorFlow and Object Detection API Source: https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/inference_tf2_colab.ipynb Installs the required version of TensorFlow and clones the models repository, followed by compiling Protobuf files and installing the API package. ```shell !pip install -U --pre tensorflow=="2.2.0" !git clone --depth 1 https://github.com/tensorflow/models cd models/research/ protoc object_detection/protos/*.proto --python_out=. cp object_detection/packages/tf2/setup.py . python -m pip install . ``` -------------------------------- ### Compile Protobufs and Install Package Source: https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/object_detection_tutorial.ipynb Compiles the protocol buffers required for the object detection API and installs the research package. ```bash cd models/research/ protoc object_detection/protos/*.proto --python_out=. pip install . ``` -------------------------------- ### Install object detection package Source: https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/context_rcnn_tutorial.ipynb Installs the object detection package from the local research directory. ```bash cd models/research pip install . ``` -------------------------------- ### Install Detectron2 and Dependencies Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/pre_processing/visualize_instance_segmentation_annotations.ipynb Installs the Detectron2 library from GitHub and restarts the runtime. This is a prerequisite for using Detectron2 functionalities. ```bash !git clone 'https://github.com/facebookresearch/detectron2' !pip install 'git+https://github.com/facebookresearch/detectron2.git' ``` -------------------------------- ### Install Gemini Python SDK Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/llm_applications/Quality_Control_Geimini.ipynb Installs the required Google GenAI library to enable interaction with Gemini models. ```bash !pip install --upgrade --quiet google-genai ``` -------------------------------- ### Install Object Detection API Source: https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/inference_from_saved_model_tf2_colab.ipynb Installs the TensorFlow Object Detection API. This involves navigating to the research directory, compiling protocol buffers, copying the setup file, and installing the package using pip. ```bash cd models/research/ protoc object_detection/protos/*.proto --python_out=. cp object_detection/packages/tf2/setup.py . python -m pip install . ``` -------------------------------- ### Install TensorFlow Object Detection API Source: https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/deepmac_colab.ipynb Installs the TensorFlow Object Detection API by compiling protocol buffers, copying setup files, and installing the package. It specifically restricts the TensorFlow version to 2.8 or below to avoid CuDNN compatibility issues. ```bash cd models/research/ protoc object_detection/protos/*.proto --python_out=. cp object_detection/packages/tf2/setup.py . # The latest tf-models-official installs tensorflow 2.9 which has an # incompatible CuDNN dependency. Here we restrict ourselves to versions 2.8 and # below. python -m pip install "tf-models-official<=2.8" . ``` -------------------------------- ### Install Grounded-SAM-2 Dependencies Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/llm_applications/milk_pouch_detection_using_groundingdino_sam2_gemini.ipynb Sets up the environment by cloning the Grounded-SAM-2 repository and installing necessary packages including Grounding DINO and supervision tools. ```bash !git clone 'https://github.com/IDEA-Research/Grounded-SAM-2' !pip install 'git+https://github.com/IDEA-Research/Grounded-SAM-2' %cd 'Grounded-SAM-2' !pip install --no-build-isolation -e grounding_dino !pip install addict yapf supervision>=0.22.0 ``` -------------------------------- ### Install Dependencies and Download YAMNet Model Source: https://github.com/tensorflow/models/blob/master/research/audioset/yamnet/yamnet_visualization.ipynb Installs the necessary 'soundfile' package, clones the TensorFlow models repository, changes the directory to the YAMNet research folder, and downloads the YAMNet model weights and an example audio file. ```python # Install required packages. !pip install soundfile !git clone https://github.com/tensorflow/models.git %cd models/research/audioset/yamnet # Download YAMNet data !curl -O https://storage.googleapis.com/audioset/yamnet.h5 # Download audio for testing !curl -O https://storage.googleapis.com/audioset/speech_whistling2.wav !ls -l ``` -------------------------------- ### Setup Oxford Dataset Environment Source: https://github.com/tensorflow/models/blob/master/research/delf/delf/python/training/README.md Commands to create the necessary directory structure and download the Oxford buildings dataset for testing. ```bash mkdir data && cd data wget http://www.robots.ox.ac.uk/~vgg/data/oxbuildings/oxbuild_images.tgz mkdir oxford5k_images oxford5k_features tar -xvzf oxbuild_images.tgz -C oxford5k_images/ cd ../ echo data/oxford5k_images/hertford_000056.jpg >> list_images.txt echo data/oxford5k_images/oxford_000317.jpg >> list_images.txt ``` -------------------------------- ### Setup TensorBoard for Training Visualization Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/fine_tuning/RF-DETR/Train_RF-DETR.ipynb Configures and launches TensorBoard to visualize training metrics. It requires specifying the output directory where training logs are saved. ```python model_output_path = "/mydrive/LLM/rf-detr/data/output/" # @param {type: "string", placeholder: "[path to the model]", isTemplate: true} %load_ext tensorboard %tensorboard --logdir $model_output_path ``` -------------------------------- ### Install Dependencies and Configure Environment Source: https://github.com/tensorflow/models/blob/master/official/recommendation/ranking/preprocessing/README.md Sets up the required Python environment and configures necessary Google Cloud environment variables for data processing. ```bash python3 setup.py install export STORAGE_BUCKET=gs://bucket-name export PROJECT=my-gcp-project export REGION=us-central1 ``` -------------------------------- ### Setup Environment for CircularNet Training Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/fine_tuning/TF-Mask-RCNN/README.md Commands to create and activate a Conda environment and install the necessary TensorFlow and Model Garden dependencies. ```bash conda create -n circularnet-train python=3.11 conda activate circularnet-train pip install tensorflow[and-cuda] tf-models-official ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/llm_applications/milk_pouch_detection_using_groundingdino-sam2-gemma3.ipynb Installs the necessary libraries and clones the Grounded-SAM-2 repository. This includes setting up the environment for Grounding Dino and SAM2, along with other required packages like addict, yapf, and supervision. ```bash !git clone 'https://github.com/IDEA-Research/Grounded-SAM-2' !pip install 'git+https://github.com/IDEA-Research/Grounded-SAM-2' %cd 'Grounded-SAM-2' # Install SAM2 !pip install -e . # Install Grounding Dino !pip install --no-build-isolation -e grounding_dino !pip install addict yapf supervision>=0.22.0 ``` -------------------------------- ### Setup Bazel and seq_flow_lite Source: https://github.com/tensorflow/models/blob/master/research/seq_flow_lite/demo/colab/emotion_colab.ipynb Configures the environment by installing Bazel for custom TensorFlow ops and cloning the seq_flow_lite repository to enable the PRADO architecture. ```bash !sudo apt install curl gnupg !curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add - !echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list !sudo apt update !sudo apt install bazel=5.4.0 !git clone https://www.github.com/tensorflow/models !models/research/seq_flow_lite/demo/colab/setup_workspace.sh !pip install models/research/seq_flow_lite ``` -------------------------------- ### Download and Initialize FastSAM Model (Shell) Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/data_generation/Auto_Annotation_FastSAM.ipynb This snippet downloads the FastSAM model weights to a 'weights' directory and lists the downloaded files. It then initializes the FastSAM model using the downloaded checkpoint. ```bash !mkdir weights !wget -P weights -q https://huggingface.co/spaces/An-619/FastSAM/resolve/main/weights/FastSAM.pt !ls -lh weights ``` ```python FAST_SAM_CHECKPOINT_PATH = "weights/FastSAM.pt" fast_sam = FastSAM(FAST_SAM_CHECKPOINT_PATH) ``` -------------------------------- ### Download and Prepare Sample Image (Python) Source: https://github.com/tensorflow/models/blob/master/official/projects/qat/vision/docs/qat_tutorial.ipynb Demonstrates how to use the `load_image_into_numpy_array` function to download a sample image from a URL and prepare it for model inference. It shows the resulting shape of the image array and how to convert it back to an image object. ```python image_path = "https://djl.ai/examples/src/test/resources/dog_bike_car.jpg" image_array = load_image_into_numpy_array(image_path, 256, 256) print(image_array.shape) # Displaying the image (requires Pillow) # from PIL import Image # Image.fromarray(image_array[0]) ``` -------------------------------- ### Install and Import Libraries for Waste Identification Pipeline Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/model_inference_with_tracking/Inference_Tensorflow_Pipeline_with_Tracking.ipynb Installs the 'trackpy' library and imports various essential Python libraries for data manipulation, image processing, and machine learning tasks within the TensorFlow ecosystem. This setup is crucial for the subsequent steps of the waste identification pipeline. ```python #@title Imports and Setup !pip install -q trackpy import sys import tensorflow as tf import csv from typing import Any, TypedDict, Callable import cv2 import logging import numpy as np import matplotlib.pyplot as plt import glob import natsort import tqdm import os from PIL import Image from scipy import ndimage import pandas as pd import skimage import datetime import trackpy as tp import shutil logging.disable(logging.WARNING) %matplotlib inline ``` -------------------------------- ### Import Libraries and Setup Environment Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/fine_tuning/RF-DETR/Inference_RF-DETR.ipynb Imports essential libraries for object detection, data handling, and visualization. It also sets up environment variables for CUDA and connects to Google Drive for model weights and data storage. ```python # Import libraries. from rfdetr.util.coco_classes import COCO_CLASSES from rfdetr import RFDETRLarge from google.colab import drive import natsort import io import requests import supervision as sv from PIL import Image import warnings from typing import Dict, List, Optional, Tuple, Any import json import glob import os warnings.filterwarnings("ignore") !export CUDA_LAUNCH_BLOCKING=1 !export PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True # Connect to the google drive. drive.mount('/content/gdrive') try: !ln -s /content/gdrive/My\ Drive/ /mydrive print('Successful') except Exception as e: print(e) print('Not successful') ``` -------------------------------- ### Install Dependencies for Video SSL Tutorial Source: https://github.com/tensorflow/models/blob/master/official/projects/video_ssl/video_ssl.ipynb Installs essential Python packages required for the video SSL tutorial, including TensorFlow, TensorFlow Addons, TensorFlow Datasets, and other utility libraries for data handling and visualization. ```python !pip install -U -q "tensorflow" "tensorflow_addons" "immutabledict" "tensorflow_datasets" !pip install -U -q remotezip tqdm opencv-python einops !pip install -U -q git+https://github.com/tensorflow/docs ``` -------------------------------- ### Configure Learning Rate Schedules Source: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/tpu_compatibility.md Provides examples for implementing learning rate schedules with warmup. Options include cosine decay or manual step-based scheduling to ensure stable training. ```protobuf learning_rate: { cosine_decay_learning_rate { learning_rate_base: .04 total_steps: 25000 warmup_learning_rate: .013333 warmup_steps: 2000 } } learning_rate: { manual_step_learning_rate { warmup: true initial_learning_rate: .01333 schedule { step: 2000 learning_rate: 0.04 } schedule { step: 15000 learning_rate: 0.004 } } } ``` -------------------------------- ### Monitor Training with Tensorboard Source: https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/running_pets.md Sets up local access to Google Cloud Storage and launches Tensorboard to visualize training progress. This allows for real-time monitoring of metrics and example detections during the training process. ```bash # This command needs to be run once to allow your local machine to access your # GCS bucket. gcloud auth application-default login tensorboard --logdir=gs://${YOUR_GCS_BUCKET}/model_dir ``` -------------------------------- ### Setup Cloud TPU Environment Source: https://github.com/tensorflow/models/blob/master/official/nlp/docs/train.md Commands to set up a Cloud TPU environment and install Model Garden with its dependencies. This includes creating a TPU instance and configuring the Python environment. ```shell export TPU_NAME=YOUR_TPU_NAME ctpu up -name $TPU_NAME --tf-version=nightly --tpu-size=YOUR_TPU_SIZE --project=YOUR_PROJECT ``` ```shell git clone https://github.com/tensorflow/models.git export PYTHONPATH=$PYTHONPATH:/path/to/models pip3 install --user -r official/requirements.txt ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/llm_applications/Milk_pouch_detection_using_GroundingDino_Sam2_ImageClassifier.ipynb Installs the necessary libraries and clones the Grounding-SAM-2 repository. This includes Grounding Dino, SAM2, and other utility packages like supervision and addict. ```python !git clone 'https://github.com/IDEA-Research/Grounded-SAM-2' !pip install 'git+https://github.com/IDEA-Research/Grounded-SAM-2' %cd 'Grounded-SAM-2' # Install Grounding Dino !pip install --no-build-isolation -e grounding_dino !pip install addict yapf supervision>=0.22.0 ``` -------------------------------- ### Clone GitHub Repository Source: https://github.com/tensorflow/models/blob/master/research/delf/INSTALL_INSTRUCTIONS.md Clones a GitHub repository. The example shows cloning using SSH, but HTTPS is also supported and may be preferable depending on your setup. Refer to GitHub documentation for choosing the correct remote URL. ```bash git clone git@github.com:tensorflow/models.git git clone https://github.com/tensorflow/models.git ``` -------------------------------- ### Fine-tuning Inception-v3 on Flowers Dataset Source: https://github.com/tensorflow/models/blob/master/research/slim/README.md Fine-tune the Inception-v3 model on the flowers dataset, starting from an ImageNet pre-trained checkpoint. This example focuses on training only the new classification layers while freezing others, suitable for smaller datasets or transfer learning tasks. ```shell DATASET_DIR=/tmp/flowers TRAIN_DIR=/tmp/flowers-models/inception_v3 CHECKPOINT_PATH=/tmp/my_checkpoints/inception_v3.ckpt python train_image_classifier.py \ --train_dir=${TRAIN_DIR} \ --dataset_dir=${DATASET_DIR} \ --dataset_name=flowers \ --dataset_split_name=train \ --model_name=inception_v3 \ --checkpoint_path=${CHECKPOINT_PATH} \ --checkpoint_exclude_scopes=InceptionV3/Logits,InceptionV3/AuxLogits \ --trainable_scopes=InceptionV3/Logits,InceptionV3/AuxLogits ``` -------------------------------- ### Extract and Visualize CenterNet Class Center Heatmaps Source: https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/inference_tf2_colab.ipynb This snippet demonstrates how to extract class center heatmap predictions from a CenterNet model, apply an inverse logit transform, and then unpad and resize the heatmap to match the original image dimensions for visualization. It includes functions for getting the heatmap and unpadding it, followed by example usage for 'kite' and 'person' classes. ```Python if detection_model.__class__.__name__ != 'CenterNetMetaArch': raise AssertionError('The meta-architecture for this section ' 'is assumed to be CenterNetMetaArch!') def get_heatmap(predictions_dict, class_name): """Grabs class center logits and apply inverse logit transform. Args: predictions_dict: dictionary of tensors containing a `object_center` field of shape [1, heatmap_width, heatmap_height, num_classes] class_name: string name of category (e.g., `horse`) Returns: heatmap: 2d Tensor heatmap representing heatmap of centers for a given class (For CenterNet, this is 128x128 or 256x256) with values in [0,1] """ class_index = label_map_dict[class_name] class_center_logits = predictions_dict['object_center'][0] class_center_logits = class_center_logits[0][ :, :, class_index - label_id_offset] heatmap = tf.exp(class_center_logits) / (tf.exp(class_center_logits) + 1) return heatmap def unpad_heatmap(heatmap, image_np): """Reshapes/unpads heatmap appropriately. Reshapes/unpads heatmap appropriately to match image_np. Args: heatmap: Output of `get_heatmap`, a 2d Tensor image_np: uint8 numpy array with shape (img_height, img_width, 3). Note that due to padding, the relationship between img_height and img_width might not be a simple scaling. Returns: resized_heatmap_unpadded: a resized heatmap (2d Tensor) that is the same size as `image_np` """ heatmap = tf.tile(tf.expand_dims(heatmap, 2), [1, 1, 3]) * 255 pre_strided_size = detection_model._stride * heatmap.shape[0] resized_heatmap = tf.image.resize( heatmap, [pre_strided_size, pre_strided_size], method=tf.image.ResizeMethod.NEAREST_NEIGHBOR) resized_heatmap_unpadded = tf.slice(resized_heatmap, begin=[0,0,0], size=shapes) return tf.image.resize( resized_heatmap_unpadded, [image_np.shape[0], image_np.shape[1]], method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)[:,:,0] class_name = 'kite' heatmap = get_heatmap(predictions_dict, class_name) resized_heatmap_unpadded = unpad_heatmap(heatmap, image_np) plt.figure(figsize=(12,16)) plt.imshow(image_np_with_detections) plt.imshow(resized_heatmap_unpadded, alpha=0.7, vmin=0, vmax=160, cmap='viridis') plt.title('Object center heatmap (class: ' + class_name + ')') plt.show() class_name = 'person' heatmap = get_heatmap(predictions_dict, class_name) resized_heatmap_unpadded = unpad_heatmap(heatmap, image_np) plt.figure(figsize=(12,16)) plt.imshow(image_np_with_detections) plt.imshow(resized_heatmap_unpadded, alpha=0.7, vmin=0, vmax=160, cmap='viridis') plt.title('Object center heatmap (class: ' + class_name + ')') plt.show() ``` -------------------------------- ### Prepare Input and Output Directories Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/pre_processing/labelme_to_coco.ipynb Creates directories for storing LabelMe annotations and images (input) and for the output COCO JSON file. It then moves the downloaded sample files into the input directory. ```bash %%bash # set input directory that contains labelme annotations and image files mkdir labelme_folder # set output dir mkdir export_dir # put all the annotation files exported from "labelme" tool and their corresponding images!ls in the labelme_folder mv ffdeb4cd-43ba-4ca0-a1e6-aa5824005f44.json labelme_folder/ mv ffdeb4cd-43ba-4ca0-a1e6-aa5824005f44.jpg labelme_folder/ ``` -------------------------------- ### Install DELF Package (Bash) Source: https://github.com/tensorflow/models/blob/master/research/delf/INSTALL_INSTRUCTIONS.md Installs the DELF Python package using pip. This command installs the library in editable mode, allowing for direct use and testing. It may also install other necessary dependencies. ```bash # From tensorflow/models/research/delf/ pip3 install -e . # Install "delf" package. ``` -------------------------------- ### Install TensorFlow Recommenders Library Source: https://github.com/tensorflow/models/blob/master/official/recommendation/ranking/README.md Installs the TensorFlow Recommenders library. For tf-nightly, it's recommended to install without dependencies using '--no-deps'. For stable TensorFlow releases (2.4+), a standard installation is sufficient. ```bash pip install tensorflow-recommenders --no-deps ``` ```bash pip install tensorflow-recommenders ``` -------------------------------- ### Download and Extract Pre-trained Checkpoints Source: https://github.com/tensorflow/models/blob/master/research/slim/README.md Demonstrates how to create a directory, download a pre-trained model checkpoint archive, extract the contents, and move the checkpoint file to the target directory. ```shell CHECKPOINT_DIR=/tmp/checkpoints mkdir ${CHECKPOINT_DIR} wget http://download.tensorflow.org/models/inception_v3_2016_08_28.tar.gz tar -xvf inception_v3_2016_08_28.tar.gz mv inception_v3.ckpt ${CHECKPOINT_DIR} rm inception_v3_2016_08_28.tar.gz ``` -------------------------------- ### Install TensorFlow Object Detection API Source: https://github.com/tensorflow/models/blob/master/research/object_detection/colab_tutorials/generate_ssd_anchor_box_aspect_ratios_using_k_means_clustering.ipynb Installs the TensorFlow Object Detection API by cloning the models repository, checking out a specific commit, compiling protocol buffers, and installing the API package. It also includes a test to verify the installation. ```python # Install the tensorflow Object Detection API... # If you're running this offline, you also might need to install the protobuf-compiler: # apt-get install protobuf-compiler ! git clone -n https://github.com/tensorflow/models.git %cd models !git checkout 461b3587ef38b42cda151fa3b7d37706d77e4244 %cd research ! protoc object_detection/protos/*.proto --python_out=. # Install TensorFlow Object Detection API %cp object_detection/packages/tf2/setup.py . ! python -m pip install --upgrade pip ! python -m pip install --use-feature=2020-resolver . # Test the installation ! python object_detection/builders/model_builder_tf2_test.py ``` -------------------------------- ### Initialize AI Platform and Create Tensorboard - Python Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/model_retraining/CircularNET_Vertex_AI_ReTraining_v1.ipynb Initializes the AI Platform with project, region, and staging bucket details. It also creates a Tensorboard instance for experiment tracking. ```python PROJECT_ID = "waste-identification-ml-330916" # @param {type:"string"} BUCKET_URI = "gs://circularnet" # @param {type:"string"} REGION = "us-central1" # @param {type:"string"} model_dir = os.path.join(BUCKET_URI, train_job_name) STAGING_BUCKET = os.path.join(BUCKET_URI, "temporal") CHECKPOINT_BUCKET = os.path.join(BUCKET_URI, "ckpt") tensorboard_name = get_job_name_with_datetime("tensorboard") tensorboard = aiplatform.Tensorboard.create( display_name=tensorboard_name, project=PROJECT_ID, location=REGION, ) aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=STAGING_BUCKET, experiment_tensorboard=tensorboard) ``` -------------------------------- ### Install labelme2coco Library Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/pre_processing/labelme_to_coco.ipynb Installs the necessary labelme2coco library using pip. It's recommended to restart the runtime after installation for the changes to take effect. ```python # install the library and RESTART runtime !pip install labelme2coco ``` -------------------------------- ### Install Project Requirements Source: https://github.com/tensorflow/models/blob/master/official/projects/movinet/README.md Installs the necessary Python packages for the MoViNets project using pip. Ensure you have Python 3.6+ and TensorFlow 2.4+ installed. ```shell pip install -r requirements.txt ``` -------------------------------- ### Calculate Training Parameters Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/fine_tuning/Detectron2-Mask-RCNN/README.md Provides an example of how to calculate training parameters like batch size, epochs, and checkpoint frequency based on dataset size. These calculations help in setting up an effective training regime. ```python dataset_size = 347 # replace with your actual number IMS_PER_BATCH = 32 # total across all GPUs epochs = 300 checkpoint_every_n_epochs = 50 ``` -------------------------------- ### Verify DELF Installation (Python) Source: https://github.com/tensorflow/models/blob/master/research/delf/INSTALL_INSTRUCTIONS.md Verifies the successful installation of the DELF package by attempting to import it in a Python interpreter. If the import is successful without any errors, the installation is confirmed. ```python python3 -c 'import delf' ``` -------------------------------- ### Configure Cosine Decay with Linear Warmup Source: https://github.com/tensorflow/models/blob/master/official/nlp/docs/optimization.md Example configuration dictionary demonstrating how to specify a cosine learning rate decay with 20,000 steps and a linear warmup phase for the first 500 steps. ```python params = {'learning_rate': {'type': 'cosine', 'cosine': {'decay_steps': 20000}}, 'warmup': {'type': 'linear', 'linear': {'warmup_steps': 500}}} ``` -------------------------------- ### Install pyodi Library and Restart Runtime Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/pre_processing/merge_coco_files.ipynb Installs the 'pyodi' library, which is required for merging COCO annotation files. A runtime restart is necessary after installation for the library to be recognized. ```python # install python object detection insights library to merge multiple COCO annotation files !pip install pyodi # RESTART THE RUNTIME in order to use this library ``` -------------------------------- ### Install Dependencies for RF-DETR Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/fine_tuning/RF-DETR/Inference_RF-DETR.ipynb Installs the necessary Python packages for running RF-DETR models, including rfdetr, supervision, and roboflow. The '-q' flag ensures quiet installation. ```python !pip install -q rfdetr supervision roboflow ``` -------------------------------- ### Verify TF-Slim Installation Source: https://github.com/tensorflow/models/blob/master/research/slim/README.md This Python command checks if the TF-Slim library is installed correctly by importing it and accessing a specific evaluation function. It should run without errors if the installation is successful. ```python python -c "import tf_slim as slim; eval = slim.evaluation.evaluate_once" ``` -------------------------------- ### Install Git on Linux Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/circularnet-docs/content/deploy-cn/clone-repo.md Installs the Git version control system using the apt package manager. This is a prerequisite for cloning the repository. ```bash sudo apt-get install git ``` -------------------------------- ### Install Project Requirements Source: https://github.com/tensorflow/models/blob/master/official/projects/deepmac_maskrcnn/README.md Shell commands to clone the TensorFlow models repository and install necessary Python packages for the project. This includes installing dependencies from the official requirements.txt file. ```shell git clone https://github.com/tensorflow/models.git cd models pip3 install -r official/requirements.txt ``` -------------------------------- ### Install TensorFlow Models Package Source: https://github.com/tensorflow/models/blob/master/docs/orbit/index.ipynb Installs the necessary packages for TensorFlow models, including the official models and Orbit library. It also installs opencv-python for image processing capabilities. ```python #@title Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ``` ```python !pip install -q opencv-python !pip install tensorflow>=2.9.0 tf-models-official ``` -------------------------------- ### Initialize Environment and Load Labels Source: https://github.com/tensorflow/models/blob/master/official/projects/waste_identification_ml/pre_processing/deprecated_JSON_Generation_for_Training.ipynb Imports essential Python libraries for file manipulation and image processing, then initializes category lists for material, material form, and plastic types using the pre-downloaded configuration. ```python import glob import tqdm import json from PIL import Image import subprocess import copy import os from google.colab import files from categories_list_of_dictionaries import * images_folder_path = 'image_folder/' list_of_material = build_material(MATERIAL_LIST,'material-types') list_of_material_form = build_material(MATERIAL_FORM_LIST,'material-form-types') list_of_plastic_type = build_material(PLASTICS_SUBCATEGORY_LIST,'plastic-types') ``` -------------------------------- ### Install TensorFlow Model Garden and Dependencies Source: https://context7.com/tensorflow/models/llms.txt Installs the stable or nightly release of TensorFlow Model Garden and the necessary tensorflow-text library for NLP models. Ensure you have pip3 installed. ```bash pip3 install tf-models-official # For NLP models, also install tensorflow-text pip3 install tensorflow-text # Or install nightly build for latest features pip3 install tf-models-nightly pip3 install tensorflow-text-nightly ```