|
149 | 149 | "\n", |
150 | 150 | "models, endpoints = {}, {}\n", |
151 | 151 | "\n", |
| 152 | + "# @markdown Set use_dedicated_endpoint to False if you don't want to use [dedicated endpoint](https://cloud.google.com/vertex-ai/docs/general/deployment#create-dedicated-endpoint). Note that [dedicated endpoint does not support VPC Service Controls](https://cloud.google.com/vertex-ai/docs/predictions/choose-endpoint-type), uncheck the box if you are using VPC-SC.\n", |
| 153 | + "use_dedicated_endpoint = True # @param {type:\"boolean\"}\n", |
| 154 | + "\n", |
152 | 155 | "# @markdown Click \"Show Code\" to see more details." |
153 | 156 | ] |
154 | 157 | }, |
|
185 | 188 | "ACCELERATOR_COUNT = 1\n", |
186 | 189 | "\n", |
187 | 190 | "\n", |
188 | | - "def deploy_model(model_id, task, accelerator_type, machine_type, accelerator_count):\n", |
| 191 | + "def deploy_model(\n", |
| 192 | + " model_id: str,\n", |
| 193 | + " task: str,\n", |
| 194 | + " machine_type: str = \"n1-standard-8\",\n", |
| 195 | + " accelerator_type: str = \"NVIDIA_TESLA_T4\",\n", |
| 196 | + " accelerator_count: int = 1,\n", |
| 197 | + " use_dedicated_endpoint: bool = False,\n", |
| 198 | + "):\n", |
189 | 199 | " model_name = \"owl-vit\"\n", |
190 | | - " endpoint = aiplatform.Endpoint.create(display_name=f\"{model_name}-endpoint\")\n", |
| 200 | + " endpoint = aiplatform.Endpoint.create(\n", |
| 201 | + " display_name=f\"{model_name}-endpoint\",\n", |
| 202 | + " dedicated_endpoint_enabled=use_dedicated_endpoint,\n", |
| 203 | + " )\n", |
191 | 204 | " serving_env = {\n", |
192 | 205 | " \"MODEL_ID\": model_id,\n", |
193 | 206 | " \"TASK\": task,\n", |
|
225 | 238 | ")\n", |
226 | 239 | "\n", |
227 | 240 | "\n", |
228 | | - "models[\"model\"], endpoints[\"endpoint\"] = deploy_model(\n", |
| 241 | + "LABEL = \"owl-vit\"\n", |
| 242 | + "models[LABEL], endpoints[LABEL] = deploy_model(\n", |
229 | 243 | " model_id=\"google/owlvit-base-patch32\",\n", |
230 | 244 | " task=\"zero-shot-object-detection\",\n", |
231 | | - " accelerator_type=ACCELERATOR_TYPE,\n", |
232 | 245 | " machine_type=MACHINE_TYPE,\n", |
| 246 | + " accelerator_type=ACCELERATOR_TYPE,\n", |
233 | 247 | " accelerator_count=ACCELERATOR_COUNT,\n", |
| 248 | + " use_dedicated_endpoint=use_dedicated_endpoint,\n", |
234 | 249 | ")\n", |
235 | 250 | "\n", |
| 251 | + "endpoint = endpoints[LABEL]\n", |
| 252 | + "model = models[LABEL]\n", |
| 253 | + "\n", |
236 | 254 | "# @markdown Click \"Show Code\" to see more details." |
237 | 255 | ] |
238 | 256 | }, |
|
266 | 284 | "instances = [\n", |
267 | 285 | " {\"image\": common_util.image_to_base64(image), \"text\": text},\n", |
268 | 286 | "]\n", |
269 | | - "preds = endpoints[\"endpoint\"].predict(instances=instances).predictions\n", |
| 287 | + "preds = endpoint.predict(\n", |
| 288 | + " instances=instances, use_dedicated_endpoint=use_dedicated_endpoint\n", |
| 289 | + ").predictions\n", |
270 | 290 | "\n", |
271 | 291 | "\n", |
272 | 292 | "def draw_image_with_boxes(image, boxes):\n", |
|
0 commit comments