|
32 | 32 | "# Vertex AI SDK : AutoML training image object detection model for batch prediction\n",
|
33 | 33 | "\n",
|
34 | 34 | "<table align=\"left\">\n",
|
| 35 | + " \n", |
35 | 36 | " <td>\n",
|
36 |
| - " <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/automl/sdk_automl_image_object_detection_batch.ipynb\">\n", |
| 37 | + " <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_image_object_detection_batch.ipynb\">\n", |
37 | 38 | " <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
|
38 | 39 | " </a>\n",
|
39 | 40 | " </td>\n",
|
40 | 41 | " <td>\n",
|
41 |
| - " <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/automl/sdk_automl_image_object_detection_batch.ipynb\">\n", |
| 42 | + " <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_image_object_detection_batch.ipynb\">\n", |
42 | 43 | " <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
|
43 | 44 | " View on GitHub\n",
|
44 | 45 | " </a>\n",
|
45 | 46 | " </td>\n",
|
46 | 47 | " <td>\n",
|
47 |
| - " <a href=\"https://console.cloud.google.com/ai/platform/notebooks/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/master/notebooks/official/automl/sdk_automl_image_object_detection_batch.ipynb\">\n", |
48 |
| - " <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n", |
| 48 | + " <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/automl/sdk_automl_image_object_detection_batch.ipynb\">\n", |
| 49 | + " <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n", |
49 | 50 | " Open in Vertex AI Workbench\n",
|
50 | 51 | " </a>\n",
|
51 |
| - " </td>\n", |
| 52 | + " </td> \n", |
52 | 53 | "</table>\n",
|
53 | 54 | "<br/><br/><br/>"
|
54 | 55 | ]
|
|
168 | 169 | "cell_type": "code",
|
169 | 170 | "execution_count": null,
|
170 | 171 | "metadata": {
|
171 |
| - "id": "install_aip:mbsdk" |
| 172 | + "id": "hw7H6ADSv5mI" |
172 | 173 | },
|
173 | 174 | "outputs": [],
|
174 | 175 | "source": [
|
|
189 | 190 | "id": "install_storage"
|
190 | 191 | },
|
191 | 192 | "source": [
|
192 |
| - "Install the latest GA version of *google-cloud-storage* library as well." |
| 193 | + "Install the latest GA version of *google-cloud-storage* library." |
193 | 194 | ]
|
194 | 195 | },
|
195 | 196 | {
|
196 | 197 | "cell_type": "code",
|
197 | 198 | "execution_count": null,
|
198 | 199 | "metadata": {
|
199 |
| - "id": "install_storage" |
| 200 | + "id": "d6Pa6Sybv5mK" |
200 | 201 | },
|
201 | 202 | "outputs": [],
|
202 | 203 | "source": [
|
203 | 204 | "! pip3 install -U google-cloud-storage $USER_FLAG"
|
204 | 205 | ]
|
205 | 206 | },
|
| 207 | + { |
| 208 | + "cell_type": "markdown", |
| 209 | + "metadata": { |
| 210 | + "id": "9_zWlX10v5mL" |
| 211 | + }, |
| 212 | + "source": [ |
| 213 | + "Install the latest version of *tensorflow* library." |
| 214 | + ] |
| 215 | + }, |
206 | 216 | {
|
207 | 217 | "cell_type": "code",
|
208 | 218 | "execution_count": null,
|
|
211 | 221 | },
|
212 | 222 | "outputs": [],
|
213 | 223 | "source": [
|
214 |
| - "if os.getenv(\"IS_TESTING\"):\n", |
215 |
| - " ! pip3 install --upgrade tensorflow $USER_FLAG" |
| 224 | + "! pip3 install --upgrade tensorflow $USER_FLAG" |
216 | 225 | ]
|
217 | 226 | },
|
218 | 227 | {
|
|
230 | 239 | "cell_type": "code",
|
231 | 240 | "execution_count": null,
|
232 | 241 | "metadata": {
|
233 |
| - "id": "restart" |
| 242 | + "id": "D-ZBOjErv5mM" |
234 | 243 | },
|
235 | 244 | "outputs": [],
|
236 | 245 | "source": [
|
|
282 | 291 | },
|
283 | 292 | "outputs": [],
|
284 | 293 | "source": [
|
285 |
| - "PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}" |
| 294 | + "import os\n", |
| 295 | + "\n", |
| 296 | + "PROJECT_ID = \"\"" |
286 | 297 | ]
|
287 | 298 | },
|
288 | 299 | {
|
|
293 | 304 | },
|
294 | 305 | "outputs": [],
|
295 | 306 | "source": [
|
296 |
| - "if PROJECT_ID == \"\" or PROJECT_ID is None or PROJECT_ID == \"[your-project-id]\":\n", |
297 |
| - " # Get your GCP project id from gcloud\n", |
298 |
| - " shell_output = ! gcloud config list --format 'value(core.project)' 2>/dev/null\n", |
| 307 | + "# Get your Google Cloud project ID from gcloud\n", |
| 308 | + "if not os.getenv(\"IS_TESTING\"):\n", |
| 309 | + " shell_output = !gcloud config list --format 'value(core.project)' 2>/dev/null\n", |
299 | 310 | " PROJECT_ID = shell_output[0]\n",
|
300 |
| - " print(\"Project ID:\", PROJECT_ID)" |
| 311 | + " print(\"Project ID: \", PROJECT_ID)" |
| 312 | + ] |
| 313 | + }, |
| 314 | + { |
| 315 | + "cell_type": "markdown", |
| 316 | + "metadata": { |
| 317 | + "id": "W2F5WRyhv5mO" |
| 318 | + }, |
| 319 | + "source": [ |
| 320 | + "Otherwise, set your project ID here." |
| 321 | + ] |
| 322 | + }, |
| 323 | + { |
| 324 | + "cell_type": "code", |
| 325 | + "execution_count": null, |
| 326 | + "metadata": { |
| 327 | + "id": "d7-MjQafv5mO" |
| 328 | + }, |
| 329 | + "outputs": [], |
| 330 | + "source": [ |
| 331 | + "if PROJECT_ID == \"\" or PROJECT_ID is None:\n", |
| 332 | + " PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}" |
301 | 333 | ]
|
302 | 334 | },
|
303 | 335 | {
|
|
335 | 367 | "cell_type": "code",
|
336 | 368 | "execution_count": null,
|
337 | 369 | "metadata": {
|
338 |
| - "id": "region" |
| 370 | + "id": "kAfG6tDAv5mQ" |
339 | 371 | },
|
340 | 372 | "outputs": [],
|
341 | 373 | "source": [
|
342 |
| - "REGION = \"us-central1\" # @param {type: \"string\"}" |
| 374 | + "REGION = \"[your-region]\" # @param {type:\"string\"}\n", |
| 375 | + "\n", |
| 376 | + "if REGION == \"[your-region]\":\n", |
| 377 | + " REGION = \"us-central1\"" |
343 | 378 | ]
|
344 | 379 | },
|
345 | 380 | {
|
|
357 | 392 | "cell_type": "code",
|
358 | 393 | "execution_count": null,
|
359 | 394 | "metadata": {
|
360 |
| - "id": "timestamp" |
| 395 | + "id": "PzKW-zT_v5mR" |
361 | 396 | },
|
362 | 397 | "outputs": [],
|
363 | 398 | "source": [
|
|
397 | 432 | "cell_type": "code",
|
398 | 433 | "execution_count": null,
|
399 | 434 | "metadata": {
|
400 |
| - "id": "gcp_authenticate" |
| 435 | + "id": "FvQeFm3Gv5mR" |
401 | 436 | },
|
402 | 437 | "outputs": [],
|
403 | 438 | "source": [
|
|
475 | 510 | "cell_type": "code",
|
476 | 511 | "execution_count": null,
|
477 | 512 | "metadata": {
|
478 |
| - "id": "create_bucket" |
| 513 | + "id": "09kHSsKmv5mT" |
479 | 514 | },
|
480 | 515 | "outputs": [],
|
481 | 516 | "source": [
|
|
495 | 530 | "cell_type": "code",
|
496 | 531 | "execution_count": null,
|
497 | 532 | "metadata": {
|
498 |
| - "id": "validate_bucket" |
| 533 | + "id": "N9JY-esPv5mU" |
499 | 534 | },
|
500 | 535 | "outputs": [],
|
501 | 536 | "source": [
|
|
540 | 575 | "cell_type": "code",
|
541 | 576 | "execution_count": null,
|
542 | 577 | "metadata": {
|
543 |
| - "id": "init_aip:mbsdk" |
| 578 | + "id": "w2Oa_jZSv5mV" |
544 | 579 | },
|
545 | 580 | "outputs": [],
|
546 | 581 | "source": [
|
|
597 | 632 | "cell_type": "code",
|
598 | 633 | "execution_count": null,
|
599 | 634 | "metadata": {
|
600 |
| - "id": "quick_peek:csv" |
| 635 | + "id": "ITshYFagv5mZ" |
601 | 636 | },
|
602 | 637 | "outputs": [],
|
603 | 638 | "source": [
|
|
629 | 664 | "cell_type": "code",
|
630 | 665 | "execution_count": null,
|
631 | 666 | "metadata": {
|
632 |
| - "id": "create_dataset:image,iod" |
| 667 | + "id": "FYyaPzfRv5mc" |
633 | 668 | },
|
634 | 669 | "outputs": [],
|
635 | 670 | "source": [
|
|
677 | 712 | "cell_type": "code",
|
678 | 713 | "execution_count": null,
|
679 | 714 | "metadata": {
|
680 |
| - "id": "create_automl_pipeline:image,iod" |
| 715 | + "id": "vtAgY1Nmv5md" |
681 | 716 | },
|
682 | 717 | "outputs": [],
|
683 | 718 | "source": [
|
|
719 | 754 | "cell_type": "code",
|
720 | 755 | "execution_count": null,
|
721 | 756 | "metadata": {
|
722 |
| - "id": "run_automl_pipeline:image" |
| 757 | + "id": "SvV1nFDTv5md" |
723 | 758 | },
|
724 | 759 | "outputs": [],
|
725 | 760 | "source": [
|
|
750 | 785 | "cell_type": "code",
|
751 | 786 | "execution_count": null,
|
752 | 787 | "metadata": {
|
753 |
| - "id": "evaluate_the_model:mbsdk" |
| 788 | + "id": "RcpDJMgev5me" |
754 | 789 | },
|
755 | 790 | "outputs": [],
|
756 | 791 | "source": [
|
|
833 | 868 | "cell_type": "code",
|
834 | 869 | "execution_count": null,
|
835 | 870 | "metadata": {
|
836 |
| - "id": "copy_test_items:batch_prediction" |
| 871 | + "id": "JXpg67zjv5mf" |
837 | 872 | },
|
838 | 873 | "outputs": [],
|
839 | 874 | "source": [
|
|
869 | 904 | "cell_type": "code",
|
870 | 905 | "execution_count": null,
|
871 | 906 | "metadata": {
|
872 |
| - "id": "make_batch_file:automl,image" |
| 907 | + "id": "hFjX62hvv5mg" |
873 | 908 | },
|
874 | 909 | "outputs": [],
|
875 | 910 | "source": [
|
|
901 | 936 | "- `job_display_name`: The human readable name for the batch prediction job.\n",
|
902 | 937 | "- `gcs_source`: A list of one or more batch request input files.\n",
|
903 | 938 | "- `gcs_destination_prefix`: The Cloud Storage location for storing the batch prediction resuls.\n",
|
| 939 | + "- `machine_type`: The type of machine for running batch prediction on dedicated resources. Not specifying machine type will result in batch prediction job being run with automatic resources.\n", |
| 940 | + "- `starting_replica_count`: The number of machine replicas used at the start of the batch operation. If not set, Vertex AI decides starting number, not greater than `max_replica_count`. Only used if `machine_type` is set.\n", |
| 941 | + "- `max_replica_count`: The maximum number of machine replicas the batch operation may be scaled to. Only used if `machine_type` is set. Default is 10.\n", |
904 | 942 | "- `sync`: If set to True, the call will block while waiting for the asynchronous batch job to complete."
|
905 | 943 | ]
|
906 | 944 | },
|
| 945 | + { |
| 946 | + "cell_type": "markdown", |
| 947 | + "metadata": { |
| 948 | + "id": "axn-CW7xv5mg" |
| 949 | + }, |
| 950 | + "source": [ |
| 951 | + "For AutoML models, only manual scaling is supported. In manual scaling both starting_replica_count and max_replica_count have the same value.\n", |
| 952 | + "For this batch job we are using manual scaling. Here we are setting both starting_replica_count and max_replica_count to the same value that is 1. " |
| 953 | + ] |
| 954 | + }, |
907 | 955 | {
|
908 | 956 | "cell_type": "code",
|
909 | 957 | "execution_count": null,
|
910 | 958 | "metadata": {
|
911 |
| - "id": "batch_request:mbsdk" |
| 959 | + "id": "5VMMaJhbv5mh" |
912 | 960 | },
|
913 | 961 | "outputs": [],
|
914 | 962 | "source": [
|
915 | 963 | "batch_predict_job = model.batch_predict(\n",
|
916 | 964 | " job_display_name=\"salads_\" + TIMESTAMP,\n",
|
917 | 965 | " gcs_source=gcs_input_uri,\n",
|
918 | 966 | " gcs_destination_prefix=BUCKET_URI,\n",
|
| 967 | + " machine_type=\"n1-standard-4\",\n", |
| 968 | + " starting_replica_count=1,\n", |
| 969 | + " max_replica_count=1,\n", |
919 | 970 | " sync=False,\n",
|
920 | 971 | ")\n",
|
921 | 972 | "\n",
|
|
937 | 988 | "cell_type": "code",
|
938 | 989 | "execution_count": null,
|
939 | 990 | "metadata": {
|
940 |
| - "id": "batch_request_wait:mbsdk" |
| 991 | + "id": "Yc3YaEqGv5mh" |
941 | 992 | },
|
942 | 993 | "outputs": [],
|
943 | 994 | "source": [
|
|
967 | 1018 | "cell_type": "code",
|
968 | 1019 | "execution_count": null,
|
969 | 1020 | "metadata": {
|
970 |
| - "id": "get_batch_prediction:mbsdk,iod" |
| 1021 | + "id": "UGGJxFjEv5mh" |
971 | 1022 | },
|
972 | 1023 | "outputs": [],
|
973 | 1024 | "source": [
|
|
986 | 1037 | " with tf.io.gfile.GFile(name=gfile_name, mode=\"r\") as gfile:\n",
|
987 | 1038 | " for line in gfile.readlines():\n",
|
988 | 1039 | " line = json.loads(line)\n",
|
989 |
| - " print(line)\n", |
990 |
| - " break" |
| 1040 | + " print(line)" |
991 | 1041 | ]
|
992 | 1042 | },
|
993 | 1043 | {
|
|
1014 | 1064 | "cell_type": "code",
|
1015 | 1065 | "execution_count": null,
|
1016 | 1066 | "metadata": {
|
1017 |
| - "id": "cleanup:mbsdk" |
| 1067 | + "id": "_Olkhs6xv5mi" |
1018 | 1068 | },
|
1019 | 1069 | "outputs": [],
|
1020 | 1070 | "source": [
|
1021 |
| - "delete_all = True\n", |
| 1071 | + "delete_bucket = False\n", |
1022 | 1072 | "\n",
|
1023 |
| - "if delete_all:\n", |
1024 |
| - " # Delete the dataset using the Vertex dataset object\n", |
1025 |
| - " dataset.delete()\n", |
| 1073 | + "# Delete the dataset using the Vertex dataset object\n", |
| 1074 | + "dataset.delete()\n", |
1026 | 1075 | "\n",
|
1027 |
| - " # Delete the model using the Vertex model object\n", |
1028 |
| - " model.delete()\n", |
| 1076 | + "# Delete the model using the Vertex model object\n", |
| 1077 | + "model.delete()\n", |
1029 | 1078 | "\n",
|
1030 |
| - " # Delete the AutoML or Pipeline trainig job\n", |
1031 |
| - " job.delete()\n", |
| 1079 | + "# Delete the AutoML or Pipeline trainig job\n", |
| 1080 | + "job.delete()\n", |
1032 | 1081 | "\n",
|
1033 |
| - " # Delete the batch prediction job using the Vertex batch prediction object\n", |
1034 |
| - " batch_predict_job.delete()\n", |
| 1082 | + "# Delete the batch prediction job using the Vertex batch prediction object\n", |
| 1083 | + "batch_predict_job.delete()\n", |
1035 | 1084 | "\n",
|
1036 |
| - " if os.getenv(\"IS_TESTING\"):\n", |
1037 |
| - " ! gsutil rm -r $BUCKET_URI" |
| 1085 | + "if delete_bucket or os.getenv(\"IS_TESTING\"):\n", |
| 1086 | + " ! gsutil rm -r $BUCKET_URI" |
1038 | 1087 | ]
|
1039 | 1088 | }
|
1040 | 1089 | ],
|
|
0 commit comments