Skip to content

Commit 08654a5

Browse files
No public description
PiperOrigin-RevId: 929873126
1 parent f78cdc6 commit 08654a5

4 files changed

Lines changed: 166 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2026 The TensorFlow Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Constants for the pet grading cloud deployment."""
16+
17+
# Specify all the input paths
18+
DINOV3_REPO_DIR = './dinov3'
19+
CLASSIFIER_CHECKPOINT_PATH = './model_weights/best_pet_grading_model.pth'
20+
SAM3_CHECKPOINT_PATH = './model_weights/sam3_original_weights_sam3.pt'
21+
22+
# SAM3 configurations.
23+
BATCH_SIZE = 10
24+
DETECTION_PROMPT = 'bottles and containers'
25+
BOTTLE_EXTRACTION_CONFIDENCE_THRESHOLD = 0.5
26+
BOTTLE_EXTRACTION_SCORE_THRESHOLD = 0.20
27+
BOTTLE_EXTRACTION_CONTAINMENT_THRESHOLD = 0.98
28+
BOTTLE_EXTRACTION_MAX_SHORT_SIDE = 1024
29+
BOTTLE_EXTRACTION_CROP_SIZE = (256, 256)
30+
31+
32+
# Tracking configurations.
33+
BYTETRACK_MINIMUM_IOU_THRESHOLD = 0.1
34+
BYTETRACK_MINIMUM_CONSECUTIVE_FRAMES = 2
35+
36+
# Classifier configuration. Must match what was used at training time.
37+
DINOV3_MODEL_NAME = 'dinov3_vitl16'
38+
CLASSIFICATION_THRESHOLD = 50
39+
CLASS_NAMES = (
40+
'brown_bottles_grade3',
41+
'clean_PET_cold_drink_bottles_with_label_cap_ring_grade1',
42+
'clean_PET_cold_drink_bottles_without_label_cap_ring_grade1',
43+
'clean_PET_mango_juice_bottles_without_label_cap_ring_grade1',
44+
'clean_PET_water_bottles_with_label_cap_ring_grade1',
45+
'clean_PET_water_bottles_without_label_cap_ring_grade1',
46+
'clean_jars_grade1',
47+
'clean_liquor_bottles_without_label_cap_ring_grade1',
48+
'coloured_PET_bottles_grade3',
49+
'dirt_PET_cold_drink_bottles_with_label_cap_ring_grade3',
50+
'dirt_PET_cold_drink_bottles_without_label_cap_ring_grade3',
51+
'dirt_PET_mango_juice_bottles_without_label_cap_ring_grade3',
52+
'dirt_PET_water_bottles_with_label_cap_ring_grade3',
53+
'dirt_PET_water_bottles_without_label_cap_ring_grade3',
54+
'dirt_jars_grade3',
55+
'dirt_liquor_bottles_without_label_cap_ring_grade3',
56+
'full_sleeved_bottles_grade3',
57+
'green_bottles_grade3',
58+
'liquor_bottles_with_label_cap_ring_grade3',
59+
'non_food_bottles_grade3',
60+
'partially_sleeved_mango_juice_bottles_with_label_cap_ring_grade3',
61+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
# Summary
4+
cat << EOF
5+
This script sets up the environment for running ML models by ensuring Bash
6+
execution, installing system dependencies, setting up a virtual environment,
7+
installing ML packages, and cloning TensorFlow Model Garden.
8+
EOF
9+
10+
# Ensure the script is executed with /bin/bash
11+
if [ -z "$BASH_VERSION" ]; then
12+
exec /bin/bash "$0" "$@"
13+
fi
14+
15+
# update linux packages
16+
sudo apt-get update -y
17+
18+
# Create a virtual environment and install packages
19+
sudo apt-get install -y python3-venv python3-pip
20+
21+
# Clone dinvov3 repo
22+
git clone https://github.com/facebookresearch/dinov3.git
23+
24+
# Download Model weights
25+
mkdir -p ./model_weights
26+
[ -f ./model_weights/sam3_original_weights_sam3.pt ] || wget -P ./model_weights https://storage.googleapis.com/tf_model_garden/vision/waste_identification_ml/dairy_product_packet_detection/sam3_original_weights_sam3.pt
27+
[ -f ./model_weights/best_pet_grading_model.pth ] || wget -P ./model_weights https://storage.googleapis.com/tf_model_garden/vision/waste_identification_ml/dairy_product_packet_detection/best_pet_grading_model.pth
28+
29+
python3.10 -m venv myenv
30+
source myenv/bin/activate
31+
32+
echo "Activated python environment, installing dependencies."
33+
34+
pip install -r requirements.txt
35+
pip install numpy==1.26.4
36+
37+
deactivate
38+
echo "Environment setup is complete."
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--extra-index-url https://download.pytorch.org/whl/cu124
2+
sam3 @ git+https://github.com/facebookresearch/sam3.git@967fdd651f71ca14949122fed4c918a778ca9334
3+
natsort
4+
absl-py==2.4.0
5+
einops==0.8.2
6+
google-api-core==2.30.3
7+
google-auth==2.49.2
8+
google-auth-oauthlib==1.3.1
9+
google-cloud-bigquery==3.41.0
10+
google-cloud-core==2.5.1
11+
google-cloud-storage==3.10.1
12+
huggingface_hub==1.11.0
13+
opencv-python>=4.8.0,<4.10.0
14+
pandas==2.3.3
15+
pandas-gbq==0.35.0
16+
pycocotools
17+
scikit-image
18+
scikit-learn
19+
scipy
20+
seaborn
21+
supervision
22+
matplotlib
23+
termcolor
24+
torch==2.6.0+cu124
25+
torchvision==0.21.0+cu124
26+
torchmetrics
27+
trackers
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
cat << EOF
4+
This script automates the execution of an Circularnet pipeline for image
5+
processing.
6+
Steps Performed:
7+
1. Activates the Python virtual environment named 'myenv'.
8+
2. Validates successful activation of the virtual environment.
9+
3. Executes the 'pipeline_images.py' script with the following parameters:
10+
Parameters:
11+
--input_directory : GCS directory where the input images are stored for
12+
inference.
13+
--output_directory : GCS directory where the model inference outputs will be
14+
saved.
15+
--model_name : Name of the model to download and use for inference.
16+
--threshold : Confidence threshold for detections during
17+
inference.
18+
--project_id : Google Cloud Project ID for BigQuery operations.
19+
--bq_dataset_id : BigQuery Dataset ID where results will be stored.
20+
--bq_table_id : BigQuery Table ID where results will be stored.
21+
--overwrite : If set to True, overwrites the pre-existing
22+
BigQuery table.
23+
EOF
24+
#Activate the virtual environment
25+
source myenv/bin/activate
26+
# Check if the virtual environment is activated
27+
if [[ "$VIRTUAL_ENV" != "" ]]; then
28+
echo "Virtual environment 'myenv' activated successfully."
29+
else
30+
echo "Failed to activate virtual environment. Exiting."
31+
exit 1
32+
fi
33+
34+
python inference_pipeline.py \
35+
--input_directory=gs://circularnet_data/tmp/pet_pipeline_test \
36+
--output_directory=gs://circularnet_data/tmp/pet_pipeline_test \
37+
--project_id=waste-identification-ml-330916 \
38+
--bq_dataset_id=pet_dataset \
39+
--bq_table_id=pet_pipeline_test \
40+
--overwrite=True

0 commit comments

Comments
 (0)