Skip to content

Commit 69a6784

Browse files
No public description
PiperOrigin-RevId: 852437601
1 parent 8849958 commit 69a6784

File tree

3 files changed

+60
-8
lines changed

3 files changed

+60
-8
lines changed

official/projects/waste_identification_ml/llm_applications/milk_pouch_detection/deploy.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
#
2828
# Arguments:
2929
# --gcp_project_id: Specify the GCP project ID.
30-
# --region: Specify the region for the resources. Default: us-central1.
31-
# --zone: Specify the zone for the resources. Default: us-central1-a.
30+
# --region: Specify the region for the resources. Default: asia-south1.
31+
# --zone: Specify the zone for the resources. Default: asia-south1-a.
3232
# --device: Specify the device type (cpu or gpu). Default: cpu.
3333
# --compute: Specify the compute platform (gce). Default: gce.
3434
# --source_bucket_name: Specify the source GCS bucket name.
@@ -69,8 +69,8 @@ export BQ_TABLE="milk_pouch_classification_results"
6969
# --- Argument Parsing ---
7070
# Set default values for device and compute platform
7171
PROJECT_ID="project-id-placeholder"
72-
REGION="us-central1"
73-
ZONE="us-central1-a" # Zone for the GCE instance
72+
REGION="asia-south1"
73+
ZONE="asia-south1-a" # Zone for the GCE instance
7474
DEVICE="gpu" # Default to GPU
7575
COMPUTE="gce" # Default to gce
7676
SOURCE_BUCKET_NAME=""
@@ -164,14 +164,15 @@ gcloud services enable \
164164
iam.googleapis.com \
165165
bigquery.googleapis.com \
166166
pubsub.googleapis.com \
167-
cloudscheduler.googleapis.com
167+
cloudscheduler.googleapis.com \
168+
cloudresourcemanager.googleapis.com
168169
echo "All APIs have been enabled."
169170
echo ""
170171

171172
# ---
172173

173174
echo "✅ Step 3: Create BigQuery Dataset and Table..."
174-
bq --location=US mk --dataset "${PROJECT_ID}:${BQ_DATASET}" \
175+
bq --location="${REGION}" mk --dataset "${PROJECT_ID}:${BQ_DATASET}" \
175176
|| echo "Dataset '${BQ_DATASET}' already exists."
176177
bq mk --table "${PROJECT_ID}:${BQ_DATASET}.${BQ_TABLE}" \
177178
./src/milk_pouch_results_schema.json \

official/projects/waste_identification_ml/llm_applications/milk_pouch_detection/gce_startup.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ echo "--- Authenticating Docker with gcloud ---"
5454
# Authenticate Docker to pull images from Google Artifact Registry.
5555
# `gcloud` is pre-installed on Deep Learning VM images.
5656
# This command configures Docker to use gcloud credentials for the specified registry domain.
57-
gcloud auth configure-docker us-central1-docker.pkg.dev --quiet
57+
REGISTRY_HOST=$(echo "${IMAGE_URI}" | cut -d'/' -f1)
58+
gcloud auth configure-docker "${REGISTRY_HOST}" --quiet
5859
echo "Docker authenticated."
5960

6061
# Define the Docker image and container name.

official/projects/waste_identification_ml/llm_applications/milk_pouch_detection/src/run_pipeline.sh

100644100755
Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,16 @@ cd milk_pouch_project
2727

2828
# List the image files in the GCS path.
2929
# NOTE: Adjust the grep pattern if other image types are expected.
30+
echo "=== DEBUGGING START ==="
31+
echo "DEBUG: gcs_path variable is: '${gcs_path}'"
32+
echo "DEBUG: Running 'gsutil ls \"${gcs_path}\"' to check accessibility:"
33+
gsutil ls "${gcs_path}" || echo "❌ gsutil ls failed"
34+
echo "DEBUG: Running 'gsutil ls -r \"${gcs_path}\" | head -n 10' to check content:"
35+
gsutil ls -r "${gcs_path}" | head -n 10 || echo "❌ gsutil recursive ls failed"
36+
echo "=== DEBUGGING END ==="
37+
3038
echo "🖨️ Listing image files from GCS bucket: $gcs_path"
31-
mapfile -t all_gcs_files < <(gsutil ls "${gcs_path}*" | grep -iE '\.(png)$' | grep -v "/predictions/")
39+
mapfile -t all_gcs_files < <(gsutil ls -r "${gcs_path}" | grep -iE '\.(png|jpg|jpeg)$' | grep -v "/predictions/" | grep -v "/processed/")
3240
num_files=${#all_gcs_files[@]}
3341

3442
if (( num_files == 0 )); then
@@ -87,6 +95,48 @@ for (( i=0; i<num_files; i+=batch_size )); do
8795
echo "⚠️ No predictions generated for this batch."
8896
fi
8997

98+
# --- Move processed input files to 'processed/' directory preserving structure ---
99+
100+
# Ensure clean_gcs_path ends with / for correct substitution
101+
clean_gcs_path="$gcs_path"
102+
[[ "$clean_gcs_path" != */ ]] && clean_gcs_path="$clean_gcs_path/"
103+
104+
target_root="${clean_gcs_path}processed/"
105+
106+
# Group files by their destination directory to optimize gsutil calls
107+
declare -a current_move_batch
108+
current_move_dir=""
109+
110+
echo "📦 Moving processed files to ${target_root}..."
111+
112+
for file_url in "${current_batch[@]}"; do
113+
# Get the directory of the file (e.g., gs://bucket/dev/2025-12-24/)
114+
dir_url="$(dirname "$file_url")/"
115+
116+
# Calculate destination directory by injecting 'processed/'
117+
# 1. Remove the base gcs_path from the file's dir to get the relative subdir (e.g., 2025-12-24/)
118+
relative_dir="${dir_url#$clean_gcs_path}"
119+
# 2. Append this relative dir to the processed root
120+
dest_dir="${target_root}${relative_dir}"
121+
122+
# If the destination directory changes, flush the current batch
123+
if [[ "$dest_dir" != "$current_move_dir" ]]; then
124+
if (( ${#current_move_batch[@]} > 0 )); then
125+
gsutil -m mv "${current_move_batch[@]}" "$current_move_dir"
126+
current_move_batch=()
127+
fi
128+
current_move_dir="$dest_dir"
129+
fi
130+
current_move_batch+=("$file_url")
131+
done
132+
133+
# Flush any remaining files
134+
if (( ${#current_move_batch[@]} > 0 )); then
135+
gsutil -m mv "${current_move_batch[@]}" "$current_move_dir"
136+
fi
137+
138+
unset current_move_batch
139+
90140
done
91141

92142
echo "🧹 Deactivating virtual environment..."

0 commit comments

Comments
 (0)