├── .gitattributes ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── RELEASE_HISTORY.md ├── __init__.py ├── cloud_nas_utils.py ├── gcs_utils ├── __init__.py ├── gcs_path_utils.py ├── gcs_utils_using_cloud_storage.py ├── gcs_utils_using_gcsfuse.py └── gcs_utils_using_tf_gfile.py ├── global_variables.py ├── metrics_reporter.py ├── model_metrics_evaluator.py ├── nas_architecture ├── __init__.py ├── tunable_autoaugment.py ├── tunable_autoaugment_search_space.py ├── tunable_autoaugment_tf2.py ├── tunable_efficientnetv2.py ├── tunable_efficientnetv2_search_space.py ├── tunable_mnasnet.py ├── tunable_mnasnet_search_space.py ├── tunable_nasfpn.py ├── tunable_nasfpn_search_space.py ├── tunable_spinenet.py └── tunable_spinenet_search_space.py ├── nas_lib ├── __init__.py ├── augmentation_2d │ ├── __init__.py │ ├── ops.py │ ├── ops_tf2.py │ ├── policies.py │ ├── policies_search_space.py │ └── policies_tf2.py ├── lib │ ├── __init__.py │ └── layers │ │ ├── __init__.py │ │ └── nn_ops.py └── nasfpn │ ├── __init__.py │ └── nasfpn.py ├── notebooks ├── __init__.py ├── augmentation2d_tutorial.ipynb ├── vertex_nas_classification_tfvision.ipynb ├── vertex_nas_detection_tfvision.ipynb ├── vertex_nas_pointpillars_tfvision.ipynb └── vertex_pytorch_mnasnet_tutorial.ipynb ├── proxy_task ├── __init__.py ├── proxy_task_controller_utils.py ├── proxy_task_controller_utils_constants.py ├── proxy_task_model_selection.Dockerfile ├── proxy_task_model_selection.py ├── proxy_task_model_selection_lib.py ├── proxy_task_model_selection_lib_constants.py ├── proxy_task_search_controller.Dockerfile ├── proxy_task_search_controller.py ├── proxy_task_search_controller_lib.py ├── proxy_task_search_controller_lib_constants.py ├── proxy_task_search_spaces.py ├── proxy_task_utils.py ├── proxy_task_variance_measurement.Dockerfile ├── proxy_task_variance_measurement.py ├── proxy_task_variance_measurement_lib.py └── proxy_task_variance_measurement_lib_constants.py ├── pytorch ├── __init__.py ├── classification │ ├── __init__.py │ ├── base_config.py │ ├── classification.Dockerfile │ ├── cloud_search_main.py │ ├── mnasnet.py │ ├── mnasnet_constants.py │ ├── mnasnet_fast_test.yaml │ ├── mnasnet_finetune_gpu.yaml │ ├── mnasnet_search_gpu.yaml │ ├── params_dict.py │ ├── search_space.py │ ├── shard_imagenet.py │ ├── test_data │ │ ├── __init__.py │ │ ├── test-0000.tar │ │ └── test-0001.tar │ └── tunable_mnasnet.py └── logging_utils.py ├── search_spaces.py ├── tf1 ├── __init__.py ├── cloud_search_main.py ├── configs │ ├── __init__.py │ ├── auto_augmentation_detection_search_tpu.yaml │ ├── fast_mnasnet_detection_search_for_testing.yaml │ ├── fast_nas_classification_search_for_testing.yaml │ ├── fast_nas_detection_nasfpn_search_for_testing.yaml │ ├── fast_nas_detection_spinenet_mbconv_search_for_testing.yaml │ ├── fast_nas_detection_spinenet_search_for_testing.yaml │ ├── fast_nas_segmentation_aug_search_for_testing.yaml │ ├── fast_nas_segmentation_nasfpn_search_for_testing.yaml │ ├── fast_nas_segmentation_spinenet_search_for_testing.yaml │ ├── latency_calculator_config.yaml │ ├── mnasnet_detection_search_tpu.yaml │ ├── mnasnet_search_finetune_gpu.yaml │ ├── mnasnet_search_finetune_tpu.yaml │ ├── mnasnet_search_gpu.yaml │ ├── mnasnet_search_tpu.yaml │ ├── nasfpn_search_image_segmentation_finetune_tpu.yaml │ ├── nasfpn_search_image_segmentation_tpu.yaml │ ├── nasfpn_search_tpu.yaml │ ├── spinenet_mbconv_search_tpu.yaml │ ├── spinenet_search_finetune_tpu.yaml │ ├── spinenet_search_gpu.yaml │ ├── spinenet_search_tpu.yaml │ ├── spinenet_seg_search_finetune_tpu.yaml │ └── spinenet_seg_search_tpu.yaml ├── detection │ ├── __init__.py │ ├── configs │ │ ├── __init__.py │ │ ├── base_config.py │ │ ├── classification_config.py │ │ ├── detection_config.py │ │ ├── factory.py │ │ ├── maskrcnn_config.py │ │ ├── retinanet_config.py │ │ ├── segmentation_config.py │ │ └── shapemask_config.py │ ├── dataloader │ │ ├── __init__.py │ │ ├── anchor.py │ │ ├── classification_parser.py │ │ ├── extract_objects_parser.py │ │ ├── factory.py │ │ ├── input_reader.py │ │ ├── input_reader_util.py │ │ ├── maskrcnn_parser.py │ │ ├── maskrcnn_parser_with_copy_paste.py │ │ ├── mode_keys.py │ │ ├── retinanet_parser.py │ │ ├── segmentation_parser.py │ │ ├── shapemask_parser.py │ │ └── tf_example_decoder.py │ ├── evaluation │ │ ├── __init__.py │ │ ├── coco_evaluator.py │ │ ├── coco_utils.py │ │ └── factory.py │ ├── executor │ │ ├── __init__.py │ │ └── tpu_executor.py │ ├── modeling │ │ ├── __init__.py │ │ ├── architecture │ │ │ ├── __init__.py │ │ │ ├── efficientnet.py │ │ │ ├── efficientnet_constants.py │ │ │ ├── factory.py │ │ │ ├── fpn.py │ │ │ ├── heads.py │ │ │ ├── identity.py │ │ │ ├── mnasnet.py │ │ │ ├── mnasnet_constants.py │ │ │ ├── nasfpn.py │ │ │ ├── nn_blocks.py │ │ │ ├── nn_ops.py │ │ │ ├── resnet.py │ │ │ ├── spinenet.py │ │ │ └── spinenet_mbconv.py │ │ ├── base_model.py │ │ ├── cascade_maskrcnn_model.py │ │ ├── classification_model.py │ │ ├── factory.py │ │ ├── learning_rates.py │ │ ├── losses.py │ │ ├── maskrcnn_model.py │ │ ├── model_builder.py │ │ ├── retinanet_model.py │ │ ├── segmentation_model.py │ │ └── shapemask_model.py │ ├── ops │ │ ├── __init__.py │ │ ├── nms.py │ │ ├── postprocess_ops.py │ │ ├── roi_ops.py │ │ ├── spatial_transform_ops.py │ │ └── target_ops.py │ ├── projects │ │ ├── __init__.py │ │ └── vild │ │ │ ├── __init__.py │ │ │ ├── configs │ │ │ ├── __init__.py │ │ │ └── vild_config.py │ │ │ ├── dataloader │ │ │ ├── __init__.py │ │ │ ├── tf_example_decoder.py │ │ │ └── vild_parser.py │ │ │ ├── modeling │ │ │ ├── __init__.py │ │ │ ├── vild_head.py │ │ │ ├── vild_losses.py │ │ │ └── vild_model.py │ │ │ └── ops │ │ │ ├── __init__.py │ │ │ └── postprocess_ops.py │ ├── serving │ │ ├── __init__.py │ │ ├── classification.py │ │ ├── detection.py │ │ ├── inputs.py │ │ └── segmentation.py │ └── utils │ │ ├── __init__.py │ │ ├── autoaugment_utils.py │ │ ├── benchmark_utils.py │ │ ├── box_utils.py │ │ ├── class_utils.py │ │ ├── config_utils.py │ │ ├── dataloader_utils.py │ │ ├── input_utils.py │ │ ├── mask_utils.py │ │ ├── object_detection │ │ ├── __init__.py │ │ ├── argmax_matcher.py │ │ ├── balanced_positive_negative_sampler.py │ │ ├── box_coder.py │ │ ├── box_list.py │ │ ├── box_list_ops.py │ │ ├── faster_rcnn_box_coder.py │ │ ├── matcher.py │ │ ├── minibatch_sampler.py │ │ ├── ops.py │ │ ├── preprocessor.py │ │ ├── region_similarity_calculator.py │ │ ├── shape_utils.py │ │ ├── target_assigner.py │ │ └── visualization_utils.py │ │ ├── saved_model_benchmark.py │ │ └── shape_utils.py ├── efficientnet │ ├── __init__.py │ ├── condconv │ │ ├── README.md │ │ ├── __init__.py │ │ ├── condconv_layers.py │ │ └── efficientnet_condconv_builder.py │ ├── efficientnet_builder.py │ ├── efficientnet_model.py │ ├── lars_optimizer.py │ └── utils.py ├── export_saved_model.py ├── export_tensorrt_model.py ├── hyperparameters │ ├── __init__.py │ ├── common_hparams_flags.py │ ├── common_tpu_flags.py │ ├── flags_to_params.py │ └── params_dict.py ├── latency_computation_using_saved_model.Dockerfile ├── latency_computation_using_saved_model.py └── nas_multi_trial.Dockerfile ├── tf_utils.py ├── tf_vision ├── __init__.py ├── cloud_search_main.py ├── config_utils.py ├── configs │ ├── __init__.py │ ├── backbones.py │ ├── decoders.py │ ├── experiments │ │ ├── __init__.py │ │ ├── mnasnet_gpu_proxy_task_search.yaml │ │ ├── mnasnet_search_finetune_gpu.yaml │ │ ├── mnasnet_search_finetune_tpu.yaml │ │ ├── mnasnet_search_gpu.yaml │ │ ├── mnasnet_search_gpu_proxy_task_test.yaml │ │ ├── mnasnet_search_tpu.yaml │ │ ├── nasfpn_search_finetune_gpu.yaml │ │ ├── nasfpn_search_finetune_tpu.yaml │ │ ├── nasfpn_search_gpu.yaml │ │ ├── nasfpn_search_tpu.yaml │ │ ├── pointpillars_search_finetune_gpu.yaml │ │ ├── pointpillars_search_gpu.yaml │ │ ├── spinenet_search_finetune_gpu.yaml │ │ ├── spinenet_search_finetune_tpu.yaml │ │ ├── spinenet_search_gpu.yaml │ │ └── spinenet_search_tpu.yaml │ ├── factory.py │ ├── image_classification.py │ ├── pointpillars.py │ ├── retinanet.py │ └── semantic_segmentation.py ├── dataloaders │ ├── __init__.py │ ├── retinanet_input.py │ └── segmentation_input.py ├── latency_computation_using_saved_model.Dockerfile ├── latency_computation_using_saved_model.py ├── latency_utils.py ├── modeling │ ├── __init__.py │ ├── mnasnet.py │ ├── tunable_mnasnet.py │ ├── tunable_nasfpn.py │ ├── tunable_pointpillars.py │ └── tunable_spinenet.py ├── nas_multi_trial.Dockerfile ├── pointpillars.Dockerfile ├── pointpillars │ ├── README.md │ ├── __init__.py │ ├── configs │ │ ├── __init__.py │ │ ├── pointpillars.py │ │ └── vehicle │ │ │ ├── __init__.py │ │ │ ├── pointpillars_3d_baseline_gpu.yaml │ │ │ ├── pointpillars_3d_baseline_local.yaml │ │ │ └── pointpillars_3d_baseline_tpu.yaml │ ├── dataloaders │ │ ├── __init__.py │ │ ├── decoders.py │ │ └── parsers.py │ ├── modeling │ │ ├── __init__.py │ │ ├── backbones.py │ │ ├── decoders.py │ │ ├── factory.py │ │ ├── featurizers.py │ │ ├── heads.py │ │ ├── layers.py │ │ └── models.py │ ├── registry_imports.py │ ├── tasks │ │ ├── __init__.py │ │ └── pointpillars.py │ ├── tools │ │ ├── __init__.py │ │ ├── export_model.py │ │ └── process_wod.py │ ├── train.py │ └── utils │ │ ├── __init__.py │ │ ├── model_exporter.py │ │ ├── utils.py │ │ ├── wod_detection_evaluator.py │ │ └── wod_processor.py ├── registry_imports.py ├── search_spaces │ ├── __init__.py │ └── tunable_pointpillars_search_space.py ├── tasks │ ├── __init__.py │ ├── pointpillars.py │ ├── retinanet.py │ └── semantic_segmentation.py ├── test_files │ ├── __init__.py │ ├── fast_mnasnet_detection_search_for_testing.yaml │ ├── fast_nas_classification_search_for_testing.yaml │ ├── fast_nas_detection_nasfpn_search_for_testing.yaml │ ├── fast_nas_detection_spinenet_mbconv_search_for_testing.yaml │ ├── fast_nas_detection_spinenet_search_for_testing.yaml │ ├── fast_nas_segmentation_aug_search_for_testing.yaml │ ├── fast_nas_segmentation_nasfpn_search_for_testing.yaml │ ├── fast_nas_segmentation_spinenet_search_for_testing.yaml │ └── fast_pointpillars_search_for_testing.yaml ├── train.py ├── train_lib.py └── utils.py ├── third_party ├── __init__.py ├── medical_3d │ ├── LICENSE │ ├── __init__.py │ ├── basic_unet.py │ ├── configs │ │ ├── __init__.py │ │ ├── fast_unet_3d_nasfpn_search_for_testing.yaml │ │ ├── fast_unet_3d_search_for_testing.yaml │ │ ├── unet_3d_nasfpn_finetune.yaml │ │ ├── unet_3d_nasfpn_search.yaml │ │ └── unet_3d_search.yaml │ ├── dataset_utils.py │ ├── medical_3d.Dockerfile │ ├── medical_3d_main.py │ ├── medical_3d_search_spaces.py │ ├── monai_trainer.py │ ├── msd_brats_dataset.py │ ├── msd_pancreas_dataset.py │ ├── nasfpn.py │ ├── static_unet.py │ ├── tunable_unet.py │ ├── tunable_unet_nasfpn.py │ └── unet_encoder.py └── tutorial │ ├── LICENSE │ ├── __init__.py │ ├── dummy_input.txt │ ├── images │ ├── __init__.py │ ├── cloud_shell_open.png │ ├── create_bucket.png │ ├── create_folder.png │ ├── device_latency_search_ui.png │ ├── download_log_drop_down.png │ ├── flops_search_analysis.png │ ├── flops_search_ui.png │ ├── gcp.png │ ├── gcp_storage.png │ ├── job_ui_page.png │ ├── open_tensorboard.png │ ├── open_tensorboard_alternative.png │ ├── tensorboard.png │ ├── test_search_job_ui.png │ ├── test_search_job_ui_finished.png │ ├── training_input_ui.png │ ├── ui_page_analysis.png │ └── view_logs_drop_down.png │ ├── mnist_train.py │ ├── search_spaces.py │ ├── tutorial1.Dockerfile │ ├── tutorial1_mnist_search.py │ ├── tutorial2.Dockerfile │ ├── tutorial2_search_spaces.py │ ├── tutorial3.Dockerfile │ ├── tutorial3_mnist_search.py │ ├── tutorial4.Dockerfile │ ├── tutorial4_latency_calculation.Dockerfile │ ├── tutorial4_latency_computation.py │ ├── tutorial4_mnist_search_with_latency_constraint.py │ ├── vertex_images │ ├── __init__.py │ ├── back_to_job_list.png │ ├── cancel_job_ui.png │ ├── cloud_shell_open.png │ ├── custom_latency_setup.png │ ├── device_latency_search_ui.png │ ├── flops_search_ui.png │ ├── job_ui_page.png │ ├── local_device_latency_search_ui.png │ ├── model_evaluator_flow.png │ ├── test_search_job_ui_finished.png │ ├── train_only_job_ui.png │ ├── training_input_ui.png │ ├── ui_page_analysis.png │ ├── vertex_ui_custom_job.png │ └── view_logs_drop_down.png │ ├── vertex_tutorial1.md │ ├── vertex_tutorial2.md │ ├── vertex_tutorial3.md │ └── vertex_tutorial4.md ├── vertex_client_utils.py ├── vertex_nas_cli.py └── vertex_nas_cli_parser.py /.gitattributes: -------------------------------------------------------------------------------- 1 | *.nii filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Community Guidelines 26 | 27 | This project follows 28 | [Google's Open Source Community Guidelines](https://opensource.google/conduct/). 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is the Vertex AI Neural Architecture Search (NAS) code repository. 2 | With Vertex AI NAS, you can search for 3 | optimal neural architectures in terms of accuracy, latency, memory, 4 | a combination of these, or a custom metric. 5 | 6 | ## Getting started 7 | Visit [Vertex AI NAS web documentation for list of features and 8 | instructions to use](https://cloud.google.com/vertex-ai/docs/training/neural-architecture-search/overview) 9 | and follow the [Documentation reading order.](https://cloud.google.com/vertex-ai/docs/training/neural-architecture-search/overview#reading_order) 10 | 11 | ## License 12 | This code is released under [Apache 2.0 license](https://github.com/google/vertex-ai-nas/blob/main/LICENSE) 13 | except for the files under the **third_party/tutorial** folder 14 | which are released under a combined [MIT and Apache 2.0 license.](https://github.com/google/vertex-ai-nas/blob/main/third_party/tutorial/LICENSE) 15 | 16 | ## Updates 17 | Check out the [RELEASE HISTORY](https://github.com/google/vertex-ai-nas/blob/main/RELEASE_HISTORY.md) 18 | for latest updates. 19 | -------------------------------------------------------------------------------- /RELEASE_HISTORY.md: -------------------------------------------------------------------------------- 1 | # Vertex AI NAS code release history 2 | 3 | ## Release on 10/12/2023 4 | ### Tutorial updates 5 | * Added troubleshooting and support instructions to tutorial 1. 6 | 7 | ### Dependency updates 8 | * Removal of 3d augmentation examples. 9 | 10 | ### Fixed issues 11 | * Fixed file path of prebuilt latency calculator dockers. 12 | 13 | ## Release on 04/11/2023 14 | Check out README and 15 | [Use cases and features.](https://cloud.google.com/vertex-ai/docs/training/neural-architecture-search/overview.md#features) 16 | 17 | -------------------------------------------------------------------------------- /__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/__init__.py -------------------------------------------------------------------------------- /gcs_utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/gcs_utils/__init__.py -------------------------------------------------------------------------------- /gcs_utils/gcs_path_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 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 | """Functions to convert GCS paths.""" 16 | 17 | 18 | def gcs_fuse_path(path): 19 | """Try to convert path to gcsfuse path if it starts with gs:// else do not modify it.""" 20 | path = path.strip() 21 | if path.startswith("gs://"): 22 | return "/gcs/" + path[5:] 23 | return path 24 | 25 | 26 | def gs_path(path): 27 | """Try to convert path to gs:// path if it starts with /gcs/ else do not modify it.""" 28 | path = path.strip() 29 | if path.startswith("/gcs/"): 30 | return "gs://" + path[5:] 31 | return path 32 | 33 | 34 | def is_gs_path(path): 35 | """Return True if path is for cloud GCS location.""" 36 | path = gs_path(path) 37 | if path.startswith("gs://"): 38 | return True 39 | else: 40 | return False 41 | -------------------------------------------------------------------------------- /global_variables.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 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 | """Global variables lib.""" 16 | 17 | # pylint: disable=line-too-long 18 | 19 | # The url path to NAS webdoc. 20 | NAS_DOC_PATH = "https://cloud.google.com/vertex-ai/docs/training/neural-architecture-search/" 21 | -------------------------------------------------------------------------------- /nas_architecture/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/nas_architecture/__init__.py -------------------------------------------------------------------------------- /nas_lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/nas_lib/__init__.py -------------------------------------------------------------------------------- /nas_lib/augmentation_2d/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/nas_lib/augmentation_2d/__init__.py -------------------------------------------------------------------------------- /nas_lib/augmentation_2d/policies_search_space.py: -------------------------------------------------------------------------------- 1 | # Lint: python3 2 | # Copyright 2020 Google Research. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | """Image augmentation search-space. 17 | 18 | NOTE: These classes decouple implementation of search-space from its 19 | definition. This way it is only dependent on PyGlove and not on 20 | TensorFlow etc. 21 | """ 22 | 23 | import pyglove as pg 24 | 25 | 26 | @pg.members([ 27 | ("num_ops", pg.typing.Int(min_value=1), "Number of augmentation ops."), 28 | ("magnitude", pg.typing.Int(min_value=0, max_value=10), 29 | "Magnitude of augmentation ops.") 30 | ]) 31 | class RandAugmentDetectionSpecBuilder(pg.Object): 32 | """Define the spec for RandAugment detection search-space.""" 33 | pass 34 | 35 | 36 | @pg.members([ 37 | ("num_ops", pg.typing.Int(min_value=1), "Number of augmentation ops."), 38 | ("magnitude", pg.typing.Int(min_value=0, max_value=10), 39 | "Magnitude of augmentation ops.") 40 | ]) 41 | class RandAugmentSegmentationSpecBuilder(pg.Object): 42 | """Define the spec for RandAugment segmentation search-space.""" 43 | pass 44 | -------------------------------------------------------------------------------- /nas_lib/lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/nas_lib/lib/__init__.py -------------------------------------------------------------------------------- /nas_lib/lib/layers/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/nas_lib/lib/layers/__init__.py -------------------------------------------------------------------------------- /nas_lib/nasfpn/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/nas_lib/nasfpn/__init__.py -------------------------------------------------------------------------------- /notebooks/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/notebooks/__init__.py -------------------------------------------------------------------------------- /proxy_task/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/proxy_task/__init__.py -------------------------------------------------------------------------------- /proxy_task/proxy_task_controller_utils_constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Proxy-task controller utils constants.""" 16 | 17 | # Duration in seconds for which trial monitoring function sleeps. 18 | TRIAL_MONITOR_SLEEP_SECS = 60 19 | 20 | # Max training step-pct. 21 | MAX_TRAINING_STEP_PCT = 100.0 22 | # Min training step-pct. 23 | MIN_TRAINING_STEP_PCT = 0.0 24 | # Training-step pct to complete training. 25 | TRAINING_STEP_PCT_TO_COMPLETE_TRAINING = 101.0 26 | # Controller alive timestamp filename. 27 | CONTROLLER_ALIVE_TIMESTAMP_FILE = "controller_alive_timestamp.json" 28 | # Controller alive timestamp key. 29 | CONTROLLER_ALIVE_TIMESTAMP_KEY = "timestamp" 30 | # Controller alive threshold in seconds. 31 | # In case the controller restarts, it needs around 10 mins to come back up. 32 | # Therefore set this check to 15 mins to give it time. 33 | CONTROLLER_ALIVE_TIMESTAMP_THRESHOLD = 15 * 60 34 | # Controller current child nas-job name file. 35 | CONTROLLER_CURRENT_NAS_JOB_NAME_FILE = "current_nas_job_name.json" 36 | CONTROLLER_CURRENT_NAS_JOB_NAME_KEY = "current_nas_job_name" 37 | # Controller job name. 38 | CONTROLLER_JOB_NAME_FILE = "controller_job_name.json" 39 | CONTROLLER_JOB_NAME_KEY = "controller_job_name" 40 | -------------------------------------------------------------------------------- /proxy_task/proxy_task_model_selection.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:2.7.0-gpu 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | 5 | # This is added to fix docker build error related to Nvidia key update. 6 | RUN rm -f /etc/apt/sources.list.d/cuda.list 7 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 8 | 9 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ 10 | | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ 11 | | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y 12 | 13 | RUN pip install --upgrade pip==21.3.1 && \ 14 | pip install Pillow==8.4.0 && \ 15 | pip install absl-py==1.1.0 && \ 16 | pip install scipy==1.7.2 && \ 17 | pip install matplotlib==3.5.2 && \ 18 | pip install pyglove==0.1.0 \ 19 | pip install google-cloud-storage==2.6.0 20 | 21 | # Make sure gsutil will use the default service account 22 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 23 | 24 | RUN mkdir /root/training 25 | COPY . /root/training/ 26 | ENV PATH="/root/training/:${PATH}" 27 | 28 | WORKDIR /root/training 29 | RUN mv proxy_task/proxy_task_model_selection.py proxy_task_model_selection.py 30 | ENTRYPOINT ["python", "proxy_task_model_selection.py"] 31 | -------------------------------------------------------------------------------- /proxy_task/proxy_task_model_selection.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Proxy-task model selection main file.""" 16 | 17 | from collections.abc import Sequence 18 | 19 | from absl import app 20 | from absl import flags 21 | import cloud_nas_utils 22 | from proxy_task import proxy_task_model_selection_lib as model_selection 23 | 24 | FLAGS = flags.FLAGS 25 | 26 | _MODEL_SELECTION_DIR = flags.DEFINE_string( 27 | 'model_selection_dir', 28 | default='', 29 | help='Input and output directory for the model-selection job.') 30 | _SERVICE_ENDPOINT = flags.DEFINE_string( 31 | 'service_endpoint', default='', help='Service endpoint for cloud job.') 32 | _REGION = flags.DEFINE_string( 33 | 'region', default='', help='Region for cloud job.') 34 | _PROJECT_ID = flags.DEFINE_string('project_id', default='', help='Project id.') 35 | _ACCURACY_METRIC_ID = flags.DEFINE_string( 36 | 'accuracy_metric_id', 37 | default='', 38 | help='The accuracy metric-id based on which the models will be selected.') 39 | _LATENCY_METRIC_ID = flags.DEFINE_string( 40 | 'latency_metric_id', 41 | default='', 42 | help='The latency metric-id based on which the models will be ' 43 | 'selected. This is not required if the training job does not ' 44 | 'compute latency.') 45 | 46 | 47 | def main(argv): 48 | if len(argv) > 1: 49 | raise app.UsageError('Too many command-line arguments.') 50 | cloud_nas_utils.setup_logging() 51 | model_selection.run_model_selection_loop( 52 | model_selection_dir=_MODEL_SELECTION_DIR.value, 53 | service_endpoint=_SERVICE_ENDPOINT.value, 54 | region=_REGION.value, 55 | project_id=_PROJECT_ID.value, 56 | accuracy_metric_id=_ACCURACY_METRIC_ID.value, 57 | latency_metric_id=_LATENCY_METRIC_ID.value) 58 | 59 | 60 | if __name__ == '__main__': 61 | app.run(main) 62 | -------------------------------------------------------------------------------- /proxy_task/proxy_task_model_selection_lib_constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Proxy-task model selection constants.""" 16 | 17 | # Initial number of models to begin with. 18 | START_NUM_MODELS = 30 19 | # Final number of models to end with. 20 | FINAL_NUM_MODELS = 10 21 | # Max allowed failed models: 20% of start num models. 22 | MAX_ALLOWED_FAILURES = int(START_NUM_MODELS / 5.0) 23 | # Number of models to remove per iteration. 24 | NUM_MODELS_TO_REMOVE_PER_ITER = 5 25 | 26 | # Desired ratio of valid trial scores to total trials. 27 | VALID_TRIALS_RATIO_THRESHOLD = 0.7 28 | 29 | # A numpy array stores the trial-id, accuracy, and latency keys. 30 | TRIAL_ID = "trial_id" 31 | ACCURACY = "accuracy" 32 | LATENCY = "latency" 33 | 34 | FILTERED_TRIAL_SCORES_PLOT_FILENAME = "filtered_trial_scores.png" 35 | 36 | # Maximum distance between trial scores. 37 | MAX_TRIAL_SCORE_DISTANCE = 100.0 38 | 39 | # Invalid trial id. 40 | INVALID_TRIAL_ID = "Invalid" 41 | 42 | # Minimum number of required models. 43 | MIN_NUM_FILTERED_TRIALS = 2 44 | 45 | # Model-selection-state filename. 46 | MODEL_SELECTION_STATE_FILENAME = "MODEL_SELECTION_STATE.json" 47 | -------------------------------------------------------------------------------- /proxy_task/proxy_task_search_controller.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:2.7.0-gpu 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | 5 | # This is added to fix docker build error related to Nvidia key update. 6 | RUN rm -f /etc/apt/sources.list.d/cuda.list 7 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 8 | 9 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ 10 | | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ 11 | | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y 12 | 13 | RUN pip install --upgrade pip==21.3.1 && \ 14 | pip install Pillow==8.4.0 && \ 15 | pip install absl-py==1.1.0 && \ 16 | pip install scipy==1.7.2 && \ 17 | pip install matplotlib==3.5.2 && \ 18 | pip install pyglove==0.1.0 \ 19 | pip install google-cloud-storage==2.6.0 20 | 21 | # Make sure gsutil will use the default service account 22 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 23 | 24 | RUN mkdir /root/training 25 | COPY . /root/training/ 26 | ENV PATH="/root/training/:${PATH}" 27 | 28 | WORKDIR /root/training 29 | RUN mv proxy_task/proxy_task_search_controller.py proxy_task_search_controller.py 30 | ENTRYPOINT ["python", "proxy_task_search_controller.py"] 31 | -------------------------------------------------------------------------------- /proxy_task/proxy_task_search_controller_lib_constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Proxy-task search controller constants.""" 16 | 17 | INVALID_ACCURACY = -1.0 18 | INVALID_TRAINING_TIME = -1.0 19 | INVALID_TRAINING_STEP = -1 20 | INVALID_CORRELATION = -5.0 21 | INVALID_P_VALUE = -5.0 22 | NUM_SECS_IN_ONE_HOUR = 3600 23 | 24 | # Minimum number of values needed to compute a correlation score. 25 | MIN_REQUIRED_NUM_CORRELATION_METRICS = 5 26 | # Minimum ratio of valid trials to total trials to compute 27 | # a correlation score. For example, need 7 out of 10 models with valid scores. 28 | MIN_RATIO_OF_VALID_TRIALS_TO_TOTAL_TRIALS = 0.7 29 | 30 | # Search-controller-state filename. 31 | SEARCH_CONTROLLER_STATE_FILENAME = "SEARCH_CONTROLLER_STATE.json" 32 | -------------------------------------------------------------------------------- /proxy_task/proxy_task_variance_measurement.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:2.7.0-gpu 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | 5 | # This is added to fix docker build error related to Nvidia key update. 6 | RUN rm -f /etc/apt/sources.list.d/cuda.list 7 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 8 | 9 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ 10 | | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ 11 | | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y 12 | 13 | RUN pip install --upgrade pip==21.3.1 && \ 14 | pip install Pillow==8.4.0 && \ 15 | pip install absl-py==1.1.0 && \ 16 | pip install scipy==1.7.2 && \ 17 | pip install matplotlib==3.5.2 && \ 18 | pip install pyglove==0.1.0 \ 19 | pip install google-cloud-storage==2.6.0 20 | 21 | # Make sure gsutil will use the default service account 22 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 23 | 24 | RUN mkdir /root/training 25 | COPY . /root/training/ 26 | ENV PATH="/root/training/:${PATH}" 27 | 28 | WORKDIR /root/training 29 | RUN mv proxy_task/proxy_task_variance_measurement.py proxy_task_variance_measurement.py 30 | ENTRYPOINT ["python", "proxy_task_variance_measurement.py"] 31 | -------------------------------------------------------------------------------- /proxy_task/proxy_task_variance_measurement.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Proxy-task variance and smoothness measurement main file.""" 16 | 17 | from collections.abc import Sequence 18 | 19 | from absl import app 20 | from absl import flags 21 | import cloud_nas_utils 22 | from proxy_task import proxy_task_variance_measurement_lib as variance_measurement 23 | 24 | _VARIANCE_MEASUREMENT_DIR = flags.DEFINE_string( 25 | 'variance_measurement_dir', 26 | default='', 27 | help='Input and output directory for the variance measurement job.') 28 | _SERVICE_ENDPOINT = flags.DEFINE_string( 29 | 'service_endpoint', default='', help='Service endpoint for cloud job.') 30 | _REGION = flags.DEFINE_string( 31 | 'region', default='', help='Region for cloud job.') 32 | _PROJECT_ID = flags.DEFINE_string('project_id', default='', help='Project id.') 33 | 34 | 35 | def main(argv): 36 | if len(argv) > 1: 37 | raise app.UsageError('Too many command-line arguments.') 38 | cloud_nas_utils.setup_logging() 39 | variance_measurement.run_measurement( 40 | measurement_dir=_VARIANCE_MEASUREMENT_DIR.value, 41 | service_endpoint=_SERVICE_ENDPOINT.value, 42 | region=_REGION.value, 43 | project_id=_PROJECT_ID.value) 44 | 45 | 46 | if __name__ == '__main__': 47 | app.run(main) 48 | -------------------------------------------------------------------------------- /proxy_task/proxy_task_variance_measurement_lib_constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Proxy-task variance measurement constants.""" 16 | 17 | # File name for storing MeasurementState json data. 18 | MEASUREMENT_STATE_FILE_NAME = 'measurement_state.json' 19 | 20 | # File name for storing measurement results. 21 | MEASUREMENT_RESULT_FILE_NAME = 'variance_and_smoothness.json' 22 | 23 | # Number of trials to run for measuring variance and smoothness. 24 | NUM_TRIALS_FOR_MEASUREMENT = 5 25 | 26 | # The measurement job will abort if failed models are more than this number. 27 | MAX_FAILED_MODELS_TO_ABORT = 10 28 | 29 | # Model variance is calculated using Coefficient of variation: 30 | # https://en.wikipedia.org/wiki/Coefficient_of_variation 31 | # If model variance is no more than this value, the variance is good. 32 | MAX_VARIANCE_TO_BE_GOOD = 0.4 33 | 34 | # Model smoothness is calculated by summing up derivatives of points sampled 35 | # from interpolated spline curve: 36 | # https://en.wikipedia.org/wiki/Spline_(mathematics) 37 | # If model smoothness is no more than this value, the smoothness is good. 38 | MAX_SMOOTHNESS_TO_BE_GOOD = 10 39 | # Percentage steps for sampling points, the numbers are empirically picked from 40 | # step-wise learning rate decay strategy. 41 | SMOOTHNESS_SAMPLE_SECTIONS = [0.0, 0.7, 0.9, 1.0] 42 | # Number of points to be sampled from each section. 43 | SMOOTHNESS_POINTS_PER_SECTION = 10 44 | -------------------------------------------------------------------------------- /pytorch/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/pytorch/__init__.py -------------------------------------------------------------------------------- /pytorch/classification/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/pytorch/classification/__init__.py -------------------------------------------------------------------------------- /pytorch/classification/base_config.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | """Base config template that defines train, eval and backbones.""" 16 | 17 | from pytorch.classification import params_dict 18 | 19 | # pylint: disable=line-too-long 20 | _base_config_dict = { 21 | 'runtime': { 22 | 'accelerator': 'gpu', 23 | 'data_type': 'float32', 24 | 'strategy': 'ddp', 25 | 'num_processes': None, 26 | 'dataloader_num_workers': 0, 27 | }, 28 | 'type': 'classification', 29 | 'architecture': { 30 | 'backbone': 'tunable_mnasnet', 31 | # Note that `num_classes` is the total number of classes including one 32 | # background class whose index is 0. 33 | 'num_classes': 1001, 34 | }, 35 | 'batch_norm_activation': { 36 | 'batch_norm_momentum': 0.9, 37 | 'batch_norm_epsilon': 1e-5, 38 | 'batch_norm_trainable': True, 39 | 'use_sync_bn': False, 40 | 'activation': 'relu', 41 | }, 42 | 'tunable_mnasnet': { 43 | 'block_specs': None, 44 | }, 45 | 'classification_head': { 46 | 'endpoints_num_filters': 0, 47 | 'aggregation': 'top', # `top` or `all`. 48 | 'dropout_rate': 0.0, 49 | }, 50 | 'train': { 51 | 'data_path': None, 52 | 'data_file_type': 'tar', 53 | 'data_size': 1281167, 54 | 'batch_size': 32, 55 | 'num_epochs': 90, 56 | 'random_erase': 0.0, 57 | 'shard_shuffle_size': 8, 58 | 'sample_shuffle_size': 256, 59 | 'optimizer': { 60 | 'type': 'SGD', 61 | 'learning_rate': 0.1, 62 | 'momentum': 0.9, 63 | 'weight_decay': 0.0001, 64 | }, 65 | 'lr_scheduler': { 66 | 'type': 'cosine', 67 | 'min_lr': 0, 68 | 'warmup_epochs': 0, 69 | 'warmup_decay': 0.01, 70 | }, 71 | }, 72 | 'eval': { 73 | 'data_path': None, 74 | 'data_file_type': 'tar', 75 | 'data_size': 5000, 76 | 'batch_size': 32, 77 | }, 78 | 'predict': { 79 | 'predict_batch_size': 8, 80 | }, 81 | 'checkpoint': { 82 | 'load_path': None, 83 | 'save_file_prefix': 'checkpoint', 84 | }, 85 | } 86 | 87 | BASE_CONFIG = params_dict.ParamsDict(_base_config_dict) 88 | # pylint: enable=line-too-long 89 | -------------------------------------------------------------------------------- /pytorch/classification/classification.Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 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.\n", 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 | # Install pytorch-1.12.1 with cuda-11.3. 16 | FROM pytorch/pytorch:1.12.1-cuda11.3-cudnn8-devel 17 | 18 | # Install additional libraries. 19 | RUN pip install pyglove==0.1.0 20 | RUN pip install torchmetrics==0.10.0 21 | RUN pip install webdataset==0.2.26 22 | RUN pip install google-cloud-storage==1.42.3 23 | 24 | RUN mkdir /root/training 25 | COPY . /root/training/ 26 | ENV PATH="/root/training/:${PATH}" 27 | 28 | WORKDIR /root/training 29 | RUN mv pytorch/classification/cloud_search_main.py pytorch_classification.py 30 | ENTRYPOINT ["python", "pytorch_classification.py"] 31 | -------------------------------------------------------------------------------- /pytorch/classification/mnasnet_constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | """MNASNET constants.""" 16 | 17 | MNASNET_NUM_BLOCKS = 7 18 | 19 | MNASNET_STRIDES = [1, 2, 2, 2, 1, 2, 1] # Same as MobileNet-V2. 20 | 21 | # The fixed MnasNet-A1 architecture discovered by NAS. 22 | # Each element represents a specification of a building block: 23 | # (num_repeats, block_fn, expand_ratio, kernel_size, se_ratio, output_filters) 24 | MNASNET_A1_BLOCK_SPECS = [ 25 | (1, 'mbconv', 1, 3, 0.0, 16), 26 | (2, 'mbconv', 6, 3, 0.0, 24), 27 | (3, 'mbconv', 3, 5, 0.25, 40), 28 | (4, 'mbconv', 6, 3, 0.0, 80), 29 | (2, 'mbconv', 6, 3, 0.25, 112), 30 | (3, 'mbconv', 6, 5, 0.25, 160), 31 | (1, 'mbconv', 6, 3, 0.0, 320), 32 | ] 33 | -------------------------------------------------------------------------------- /pytorch/classification/mnasnet_fast_test.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 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 | runtime: 16 | # When 0, only main process will be used to load data. 17 | dataloader_num_workers: 0 18 | train: 19 | data_path: '/root/training/pytorch/classification/test_data/test-{0000..0001}.tar' 20 | data_size: 16 21 | # global_batch_size = batch_size_per_gpu * num_gpus 22 | batch_size: 4 23 | num_epochs: 2 24 | optimizer: 25 | learning_rate: 0.032 26 | lr_scheduler: 27 | warmup_epochs: 1 28 | eval: 29 | data_path: '/root/training/pytorch/classification/test_data/test-{0000..0001}.tar' 30 | data_size: 16 31 | # global_batch_size = batch_size_per_gpu * num_gpus 32 | batch_size: 4 33 | -------------------------------------------------------------------------------- /pytorch/classification/mnasnet_finetune_gpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 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 | runtime: 16 | dataloader_num_workers: 2 17 | train: 18 | data_path: 'gs://cloud-ml-nas-public/classification/imagenet_tar/train-{000000..000466}.tar' 19 | data_size: 1281167 20 | # global_batch_size = batch_size_per_gpu * num_gpus 21 | # 256 * 8 22 | batch_size: 2048 23 | num_epochs: 350 24 | optimizer: 25 | learning_rate: 0.032 26 | lr_scheduler: 27 | warmup_epochs: 5 28 | eval: 29 | data_path: 'gs://cloud-ml-nas-public/classification/imagenet_tar/validation-{000000..000021}.tar' 30 | data_size: 50000 31 | # global_batch_size = batch_size_per_gpu * num_gpus 32 | batch_size: 512 33 | -------------------------------------------------------------------------------- /pytorch/classification/mnasnet_search_gpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 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 | runtime: 16 | dataloader_num_workers: 8 17 | train: 18 | data_path: 'gs://cloud-ml-nas-public/classification/imagenet_tar/train-{000000..000420}.tar' 19 | # 1281167 * 0.9 = 1153050 20 | data_size: 1153050 21 | # global_batch_size = batch_size_per_gpu * num_gpus, 256 * 2 22 | batch_size: 512 23 | num_epochs: 5 24 | optimizer: 25 | learning_rate: 0.032 26 | lr_scheduler: 27 | warmup_epochs: 1 28 | eval: 29 | data_path: 'gs://cloud-ml-nas-public/classification/imagenet_tar/train-{000421..000466}.tar' 30 | # 1281167 * 0.1 = 128116 31 | data_size: 128116 32 | # global_batch_size = batch_size_per_gpu * num_gpus, 256 * 2 33 | batch_size: 512 34 | -------------------------------------------------------------------------------- /pytorch/classification/test_data/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/pytorch/classification/test_data/__init__.py -------------------------------------------------------------------------------- /pytorch/classification/test_data/test-0000.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/pytorch/classification/test_data/test-0000.tar -------------------------------------------------------------------------------- /pytorch/classification/test_data/test-0001.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/pytorch/classification/test_data/test-0001.tar -------------------------------------------------------------------------------- /pytorch/logging_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | """Util functions for logging set up.""" 16 | import logging 17 | import sys 18 | 19 | 20 | def setup_logging(): 21 | """Sets up logging.""" 22 | root_logger = logging.getLogger() 23 | root_logger_previous_handlers = list(root_logger.handlers) 24 | for h in root_logger_previous_handlers: 25 | root_logger.removeHandler(h) 26 | root_logger.setLevel(logging.INFO) 27 | root_logger.propagate = False 28 | 29 | # Set tf logging to avoid duplicate logging. If the handlers are not removed, 30 | # then we will have duplicate logging : 31 | # From tf loggging written to stderr stream, and 32 | # From python logger written to stdout stream. 33 | tf_logger = logging.getLogger("tensorflow") 34 | while tf_logger.handlers: 35 | tf_logger.removeHandler(tf_logger.handlers[0]) 36 | 37 | # Redirect INFO logs to stdout 38 | stdout_handler = logging.StreamHandler(sys.stdout) 39 | stdout_handler.setLevel(logging.INFO) 40 | root_logger.addHandler(stdout_handler) 41 | -------------------------------------------------------------------------------- /tf1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf1/__init__.py -------------------------------------------------------------------------------- /tf1/configs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf1/configs/__init__.py -------------------------------------------------------------------------------- /tf1/configs/fast_mnasnet_detection_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 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 | # ---------- Search NAS-FPN nodes based on NAS-FPN paper ---------- 15 | 16 | train: 17 | train_batch_size: 1 18 | total_steps: 1 19 | frozen_variable_prefix: null 20 | checkpoint: 21 | path: '' 22 | prefix: '' 23 | 24 | eval: 25 | eval_samples: 1 26 | eval_batch_size: 1 27 | 28 | architecture: 29 | # NOTE: If you change the 'min_level' and 'max_level' 30 | # search-space related parameters here, then you also need 31 | # to change them in the 'search_spaces.py' file. 32 | min_level: 3 33 | max_level: 7 34 | multilevel_features: 'fpn' 35 | backbone: 'tunable_mnasnet' 36 | # Note that `num_classes` is the total number of classes including 37 | # one background class with an index value of 0. 38 | num_classes: 91 39 | 40 | anchor: 41 | # The intermediate scales added on each level. 42 | # For instance, num_scales=2 adds one additional intermediate anchor scales 43 | # [2^0, 2^0.5] on each level. 44 | num_scales: 3 45 | aspect_ratios: [1.0, 2.0, 0.5] 46 | # A float number representing the scale of size of the base 47 | # anchor to the feature stride 2^level. 48 | anchor_size: 4.0 49 | 50 | tunable_nasfpn_v2: 51 | fpn_feat_dims: 256 52 | num_repeats: 3 53 | use_separable_conv: False 54 | 55 | retinanet_head: 56 | # This number should be the same as anchor.num_scales * len(anchor.aspect_ratios). 57 | anchors_per_location: 9 58 | num_filters: 256 59 | num_convs: 4 60 | 61 | retinanet_parser: 62 | aug_scale_min: 0.8 63 | aug_scale_max: 1.2 64 | # Controls the effective image-size for training. 65 | output_size: [512, 512] 66 | # The maximum number of bboxes in one image. 67 | max_num_instances: 100 68 | aug_rand_hflip: True 69 | 70 | resnet: 71 | resnet_depth: 10 72 | -------------------------------------------------------------------------------- /tf1/configs/fast_nas_classification_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # Imagenet search config. 16 | 17 | train: 18 | train_batch_size: 1 19 | total_steps: 1 20 | frozen_variable_prefix: null 21 | checkpoint: 22 | path: '' 23 | prefix: '' 24 | label_smoothing: 0.1 25 | 26 | eval: 27 | eval_samples: 1 28 | eval_batch_size: 1 29 | 30 | architecture: 31 | backbone: 'tunable_mnasnet' 32 | # Note that `num_classes` is the total number of classes including 33 | # one background class with an index value of 0. 34 | num_classes: 1001 35 | use_bfloat16: false 36 | 37 | classification_parser: 38 | output_size: [224, 224] 39 | 40 | classification_head: 41 | dropout_rate: 0.2 42 | endpoints_num_filters: 256 43 | 44 | batch_norm_activation: 45 | batch_norm_momentum: 0.99 46 | batch_norm_epsilon: 0.001 47 | use_sync_bn: true 48 | -------------------------------------------------------------------------------- /tf1/configs/fast_nas_detection_nasfpn_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # ---------- Search NAS-FPN nodes based on NAS-FPN paper ---------- 15 | 16 | 17 | train: 18 | train_file_pattern: "" 19 | total_steps: 1 20 | learning_rate: 21 | init_learning_rate: 0.08 22 | learning_rate_levels: [0.008] 23 | # Decay at end of epoch 8. 24 | learning_rate_steps: [13864] 25 | # Warm up in 1 epoch. 26 | warmup_steps: 0 27 | # Backbone is trained from scratch. 28 | checkpoint: 29 | path: null 30 | prefix: null 31 | train_batch_size: 1 32 | 33 | eval: 34 | eval_file_pattern: "" 35 | # Do not use annotation file so the ground truth will be read from dataset loader. 36 | val_json_file: null 37 | eval_samples: 1 38 | eval_batch_size: 1 39 | 40 | architecture: 41 | min_level: 3 42 | max_level: 7 43 | multilevel_features: 'tunable_nasfpn_v2' 44 | use_bfloat16: false 45 | 46 | tunable_nasfpn_v2: 47 | fpn_feat_dims: 64 48 | num_repeats: 1 49 | use_separable_conv: false 50 | 51 | retinanet_parser: 52 | aug_scale_min: 0.8 53 | aug_scale_max: 1.2 54 | output_size: [128, 128] 55 | 56 | resnet: 57 | resnet_depth: 10 58 | -------------------------------------------------------------------------------- /tf1/configs/fast_nas_detection_spinenet_mbconv_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # ---------- Search NAS-FPN nodes based on NAS-FPN paper ---------- 15 | 16 | 17 | train: 18 | train_file_pattern: "" 19 | total_steps: 1 20 | learning_rate: 21 | init_learning_rate: 0.08 22 | learning_rate_levels: [0.008] 23 | # Decay at end of epoch 8. 24 | learning_rate_steps: [13864] 25 | # Warm up in 1 epoch. 26 | warmup_steps: 0 27 | # Backbone is trained from scratch. 28 | checkpoint: 29 | path: null 30 | prefix: null 31 | train_batch_size: 1 32 | 33 | eval: 34 | eval_file_pattern: "" 35 | # Do not use annotation file so the ground truth will be read from dataset loader. 36 | val_json_file: null 37 | eval_samples: 1 38 | eval_batch_size: 1 39 | 40 | architecture: 41 | min_level: 3 42 | max_level: 7 43 | multilevel_features: 'identity' 44 | use_bfloat16: false 45 | backbone: 'tunable_spinenet_mbconv' 46 | 47 | tunable_spinenet_mbconv: 48 | # The multiplier of the number of filters for each block. 49 | filter_size_scale: 0.25 50 | # The number of filters of the output endpoints. 51 | endpoints_num_filters: 64 52 | 53 | retinanet_parser: 54 | aug_scale_min: 0.8 55 | aug_scale_max: 1.2 56 | output_size: [128, 128] 57 | 58 | resnet: 59 | resnet_depth: 10 60 | -------------------------------------------------------------------------------- /tf1/configs/fast_nas_detection_spinenet_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # ---------- Search NAS-FPN nodes based on NAS-FPN paper ---------- 15 | 16 | 17 | train: 18 | train_file_pattern: "" 19 | total_steps: 1 20 | learning_rate: 21 | init_learning_rate: 0.08 22 | learning_rate_levels: [0.008] 23 | # Decay at end of epoch 8. 24 | learning_rate_steps: [13864] 25 | # Warm up in 1 epoch. 26 | warmup_steps: 0 27 | # Backbone is trained from scratch. 28 | checkpoint: 29 | path: null 30 | prefix: null 31 | train_batch_size: 1 32 | 33 | eval: 34 | eval_file_pattern: "" 35 | # Do not use annotation file so the ground truth will be read from dataset loader. 36 | val_json_file: null 37 | eval_samples: 1 38 | eval_batch_size: 1 39 | 40 | architecture: 41 | min_level: 3 42 | max_level: 7 43 | multilevel_features: 'identity' 44 | use_bfloat16: false 45 | backbone: 'tunable_spinenet' 46 | 47 | tunable_spinenet: 48 | # The multiplier of the number of filters for each block. 49 | filter_size_scale: 0.25 50 | # The scaling factor to scale feature dimension before resolution resampling. 51 | resample_alpha: 0.25 52 | # The number of filters of the output endpoints. 53 | endpoints_num_filters: 64 54 | 55 | retinanet_parser: 56 | aug_scale_min: 0.8 57 | aug_scale_max: 1.2 58 | output_size: [128, 128] 59 | 60 | resnet: 61 | resnet_depth: 10 62 | -------------------------------------------------------------------------------- /tf1/configs/fast_nas_segmentation_aug_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # Search for image segmentation. 16 | train: 17 | train_file_pattern: 18 | total_steps: 1 19 | learning_rate: 20 | init_learning_rate: 0.08 21 | learning_rate_levels: [0.008] 22 | # Decay at end of epoch 8. 23 | learning_rate_steps: [13864] 24 | # Warm up in 1 epoch. 25 | warmup_steps: 1733 26 | # Backbone is trained from scratch. 27 | checkpoint: 28 | path: null 29 | prefix: null 30 | train_batch_size: 2 31 | 32 | eval: 33 | eval_samples: 1 34 | eval_batch_size: 1 35 | 36 | architecture: 37 | min_level: 3 38 | max_level: 7 39 | multilevel_features: 'fpn' 40 | backbone: 'efficientnet-b0' 41 | use_bfloat16: false 42 | -------------------------------------------------------------------------------- /tf1/configs/fast_nas_segmentation_nasfpn_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # Search for image segmentation. 16 | train: 17 | train_file_pattern: 18 | total_steps: 1 19 | learning_rate: 20 | init_learning_rate: 0.08 21 | learning_rate_levels: [0.008] 22 | # Decay at end of epoch 8. 23 | learning_rate_steps: [13864] 24 | # Warm up in 1 epoch. 25 | warmup_steps: 1733 26 | # Backbone is trained from scratch. 27 | checkpoint: 28 | path: null 29 | prefix: null 30 | train_batch_size: 2 31 | 32 | eval: 33 | eval_samples: 1 34 | eval_batch_size: 1 35 | 36 | architecture: 37 | min_level: 3 38 | max_level: 7 39 | multilevel_features: 'tunable_nasfpn_v2' 40 | backbone: 'efficientnet-b0' 41 | use_bfloat16: false 42 | 43 | tunable_nasfpn_v2: 44 | fpn_feat_dims: 256 45 | num_repeats: 3 46 | use_separable_conv: false 47 | -------------------------------------------------------------------------------- /tf1/configs/fast_nas_segmentation_spinenet_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # Search for image segmentation. 16 | train: 17 | train_file_pattern: 18 | total_steps: 1 19 | learning_rate: 20 | init_learning_rate: 0.08 21 | learning_rate_levels: [0.008] 22 | # Decay at end of epoch 8. 23 | learning_rate_steps: [13864] 24 | # Warm up in 1 epoch. 25 | warmup_steps: 1733 26 | # Backbone is trained from scratch. 27 | checkpoint: 28 | path: null 29 | prefix: null 30 | train_batch_size: 2 31 | 32 | eval: 33 | eval_samples: 1 34 | eval_batch_size: 1 35 | 36 | architecture: 37 | min_level: 3 38 | max_level: 7 39 | multilevel_features: 'identity' 40 | backbone: 'tunable_spinenet' 41 | use_bfloat16: false 42 | 43 | tunable_spinenet: 44 | # The multiplier of the number of filters for each block. 45 | filter_size_scale: 0.25 46 | # the scaling factor to scale feature dimension before resolution resampling. 47 | resample_alpha: 0.25 48 | # The number of filters of the output endpoints. 49 | endpoints_num_filters: 64 50 | -------------------------------------------------------------------------------- /tf1/configs/latency_calculator_config.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | # Config file for NAS model latency / memory calculator docker. 16 | 17 | # Width of testing image. 18 | image_width: 512 19 | 20 | # Height of testing image. 21 | image_height: 512 22 | 23 | # The Tensorflow SavedModel input_node. Need to update if customized trainer is used. 24 | input_node: "Placeholder:0" 25 | 26 | # The Tensorflow SavedModel output_mode. Need to update if customized trainer is used. 27 | output_nodes: "DetectionBoxes:0,DetectionClasses:0,DetectionScores:0" 28 | 29 | # The number of repetitions to run for latency calculation 30 | num_repetitions_for_latency_computation: 100 31 | 32 | # True to use tensorrt conversion for Nvidia GPU. 33 | use_tensorrt_conversion_on_gpu: True 34 | -------------------------------------------------------------------------------- /tf1/configs/mnasnet_search_finetune_gpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # Imagenet finetuning config. 16 | enable_summary: true 17 | train: 18 | # Train file pattern is provided by the binary flag. 19 | 20 | # Reduce the batch-size if you run into out-of-memory error. 21 | # Out-of-memory error may also be resolved by reducing 22 | # the image-size but at the expense of quality. 23 | # NOTE: The batch-size is per GPU and default setting is 2 GPUs. 24 | train_batch_size: 128 25 | 26 | # Set num-steps to around 350 epochs. 27 | total_steps: 1751592 # ~350 epochs (350*(1281167/(128*2))) 28 | 29 | learning_rate: 30 | type: 'cosine' 31 | # Reduce the learning rate if you get gradients reaching NAN error. 32 | init_learning_rate: 0.016 33 | optimizer: 34 | type: 'rmsprop' 35 | l2_weight_decay: 0.00001 36 | label_smoothing: 0.1 37 | checkpoint: 38 | path: '' 39 | prefix: '' 40 | eval: 41 | # Eval file pattern is provided by the binary flag. 42 | 43 | eval_samples: 50000 44 | 45 | # NOTE: Partial batch will not be used for evaluation. So ideally, 46 | # the total-number of eval-samples should be divisible by 47 | # 'eval_batch_size' if you want all the samples to be used. 48 | # 'eval_batch_size' needs to be divisible by 8 when using TPU. 49 | eval_batch_size: 128 50 | 51 | architecture: 52 | backbone: 'mnasnet' 53 | # Note that `num_classes` is the total number of classes including 54 | # one background class with an index value of 0. 55 | num_classes: 1001 56 | 57 | classification_parser: 58 | # Controls the effective image-size for training. 59 | output_size: [224, 224] 60 | 61 | classification_head: 62 | endpoints_num_filters: 1280 63 | dropout_rate: 0.2 64 | 65 | batch_norm_activation: 66 | batch_norm_momentum: 0.99 67 | batch_norm_epsilon: 0.001 68 | use_sync_bn: true 69 | -------------------------------------------------------------------------------- /tf1/configs/mnasnet_search_finetune_tpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # Imagenet finetuning config. 16 | enable_summary: true 17 | train: 18 | # Train file pattern is provided by the binary flag. 19 | 20 | # Reduce the batch-size if you run into out-of-memory error. 21 | # Out-of-memory error may also be resolved by reducing 22 | # the image-size but at the expense of quality. 23 | train_batch_size: 1024 24 | 25 | # Set num-steps to around 350 epochs. 26 | total_steps: 437898 # ~350 epochs (350*(1281167/1024)) 27 | 28 | learning_rate: 29 | type: 'cosine' 30 | # Reduce the learning rate if you get gradients reaching NAN error. 31 | init_learning_rate: 0.064 32 | optimizer: 33 | type: 'rmsprop' 34 | l2_weight_decay: 0.00001 35 | label_smoothing: 0.1 36 | checkpoint: 37 | path: '' 38 | prefix: '' 39 | eval: 40 | # Eval file pattern is provided by the binary flag. 41 | 42 | eval_samples: 50000 43 | 44 | # NOTE: Partial batch will not be used for evaluation. So ideally, 45 | # the total-number of eval-samples should be divisible by 46 | # 'eval_batch_size' if you want all the samples to be used. 47 | # 'eval_batch_size' needs to be divisible by 8 when using TPU. 48 | eval_batch_size: 1024 49 | 50 | architecture: 51 | backbone: 'mnasnet' 52 | # Note that `num_classes` is the total number of classes including 53 | # one background class with an index value of 0. 54 | num_classes: 1001 55 | 56 | classification_parser: 57 | # Controls the effective image-size for training. 58 | output_size: [224, 224] 59 | 60 | classification_head: 61 | endpoints_num_filters: 1280 62 | dropout_rate: 0.2 63 | 64 | batch_norm_activation: 65 | batch_norm_momentum: 0.99 66 | batch_norm_epsilon: 0.001 67 | use_sync_bn: true 68 | -------------------------------------------------------------------------------- /tf1/configs/mnasnet_search_gpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # Imagenet search config. 16 | train: 17 | # Train file pattern is provided by the binary flag. 18 | 19 | # Reduce the batch-size if you run into out-of-memory error. 20 | # Out-of-memory error may also be resolved by reducing 21 | # the image-size but at the expense of quality. 22 | # NOTE: The batch-size is per GPU and default setting is 2 GPUs. 23 | train_batch_size: 128 24 | 25 | # For training data: train-00[0-8]??-of-01024. 26 | # Set num-steps to around 5 to 10 epochs for search. 27 | # Guideline: total_steps = (num-train-examples/train_batch_size)*10. 28 | # Ideally your individual search-trial should 29 | # finish within 30 mins to 1 hour. 30 | total_steps: 17568 # ~4 epochs. 31 | 32 | learning_rate: 33 | type: 'step' 34 | # Reduce the learning rate if roughly more than 30% of your 35 | # trials fail due to gradients reaching NAN error. 36 | init_learning_rate: 0.016 37 | warmup_steps: 1202 # ~ 0.25 epoch 38 | learning_rate_levels: [0.0016] # decay factor 0.97 39 | learning_rate_steps: [13176] # decay at 3th epoches. 40 | checkpoint: 41 | path: '' 42 | prefix: '' 43 | label_smoothing: 0.1 44 | 45 | eval: 46 | # Eval file pattern is provided by the binary flag. 47 | 48 | eval_samples: 20000 49 | 50 | # NOTE: Partial batch will not be used for evaluation. So ideally, 51 | # the total-number of eval-samples should be divisible by 52 | # 'eval_batch_size' if you want all the samples to be used. 53 | # 'eval_batch_size' needs to be divisible by 8 when using TPU. 54 | eval_batch_size: 128 55 | 56 | architecture: 57 | backbone: 'tunable_mnasnet' 58 | # Note that `num_classes` is the total number of classes including 59 | # one background class with an index value of 0. 60 | num_classes: 1001 61 | 62 | classification_parser: 63 | # Controls the effective image-size for training. 64 | output_size: [224, 224] 65 | 66 | classification_head: 67 | dropout_rate: 0.2 68 | endpoints_num_filters: 256 69 | 70 | batch_norm_activation: 71 | batch_norm_momentum: 0.99 72 | batch_norm_epsilon: 0.001 73 | use_sync_bn: true 74 | -------------------------------------------------------------------------------- /tf1/configs/mnasnet_search_tpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # Imagenet search config. 16 | train: 17 | # Train file pattern is provided by the binary flag. 18 | 19 | # Reduce the batch-size if you run into out-of-memory error. 20 | # Out-of-memory error may also be resolved by reducing 21 | # the image-size but at the expense of quality. 22 | train_batch_size: 1024 23 | 24 | # For training data: train-00[0-8]??-of-01024. 25 | # Set num-steps to around 5 to 10 epochs for search. 26 | # Guideline: total_steps = (num-train-examples/train_batch_size)*10. 27 | # Ideally your individual search-trial should 28 | # finish within 30 mins to 1 hour. 29 | total_steps: 8784 # ~8 epochs. 30 | 31 | learning_rate: 32 | type: 'step' 33 | # Reduce the learning rate if roughly more than 30% of your 34 | # trials fail due to gradients reaching NAN error. 35 | init_learning_rate: 0.064 36 | warmup_steps: 601 # ~ 0.5 epoch 37 | learning_rate_levels: [0.0064] # decay factor 0.97 38 | learning_rate_steps: [6588] # decay at 6th epoches. 39 | checkpoint: 40 | path: '' 41 | prefix: '' 42 | label_smoothing: 0.1 43 | 44 | eval: 45 | # Eval file pattern is provided by the binary flag. 46 | 47 | eval_samples: 20000 48 | 49 | # NOTE: Partial batch will not be used for evaluation. So ideally, 50 | # the total-number of eval-samples should be divisible by 51 | # 'eval_batch_size' if you want all the samples to be used. 52 | # 'eval_batch_size' needs to be divisible by 8 when using TPU. 53 | eval_batch_size: 1024 54 | 55 | architecture: 56 | backbone: 'tunable_mnasnet' 57 | # Note that `num_classes` is the total number of classes including 58 | # one background class with an index value of 0. 59 | num_classes: 1001 60 | 61 | classification_parser: 62 | # Controls the effective image-size for training. 63 | output_size: [224, 224] 64 | 65 | classification_head: 66 | dropout_rate: 0.2 67 | endpoints_num_filters: 256 68 | 69 | batch_norm_activation: 70 | batch_norm_momentum: 0.99 71 | batch_norm_epsilon: 0.001 72 | use_sync_bn: true 73 | -------------------------------------------------------------------------------- /tf1/configs/nasfpn_search_image_segmentation_finetune_tpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # ---------- Search NAS-FPN nodes based on NAS-FPN paper ---------- 16 | train: 17 | # Train file pattern is provided by the binary flag. 18 | 19 | # Reduce the batch-size if you run into out-of-memory error. 20 | # Out-of-memory error may also be resolved by reducing 21 | # the image-size but at the expense of quality. 22 | train_batch_size: 128 23 | 24 | # Set num-steps to around 100 epochs. 25 | total_steps: 90000 26 | 27 | checkpoint: 28 | path: 'gs://pretrained_checkpoints/backbone/noisy-student-efficientnet-b5' 29 | prefix: '' 30 | frozen_variable_prefix: null 31 | 32 | learning_rate: 33 | type: 'cosine' 34 | warmup_learning_rate: 0.0067 35 | warmup_steps: 500 36 | # Reduce the learning rate if you get gradients reaching NAN error. 37 | init_learning_rate: 0.02 38 | gradient_clip_norm: 0.5 39 | 40 | eval: 41 | # Eval file pattern is provided by the binary flag. 42 | 43 | eval_samples: 1449 44 | 45 | # NOTE: Partial batch will not be used for evaluation. So ideally, 46 | # the total-number of eval-samples should be divisible by 47 | # 'eval_batch_size' if you want all the samples to be used. 48 | # 'eval_batch_size' needs to be divisible by 8 when using TPU. 49 | eval_batch_size: 8 50 | 51 | architecture: 52 | # NOTE: If you change the 'min_level' and 'max_level' 53 | # search-space related parameters here, then you also need 54 | # to change them in the 'search_spaces.py' file. 55 | min_level: 3 56 | max_level: 7 57 | multilevel_features: 'tunable_nasfpn_v2' 58 | # Note that `num_classes` is the total number of classes including 59 | # one background class with an index value of 0. 60 | num_classes: 21 61 | 62 | tunable_nasfpn_v2: 63 | fpn_feat_dims: 256 64 | num_repeats: 5 65 | use_separable_conv: False 66 | 67 | segmentation_parser: 68 | aug_rand_hflip: true 69 | aug_scale_max: 1.5 70 | aug_scale_min: 0.75 71 | ignore_label: 255 72 | # Controls the effective image-size for training. 73 | output_size: [512, 512] 74 | 75 | segmentation_head: 76 | # Its value need to be the same as `architecture.min_level`. 77 | level: 3 78 | 79 | enable_summary: true 80 | 81 | segmentation_loss: 82 | ignore_label: 255 83 | -------------------------------------------------------------------------------- /tf1/configs/nasfpn_search_image_segmentation_tpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 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 | # ---------- Search NAS-FPN nodes for image segmentation. ---------- 16 | 17 | train: 18 | # Train file pattern is provided by the binary flag. 19 | 20 | # Reduce the batch-size if you run into out-of-memory error. 21 | # Out-of-memory error may also be resolved by reducing 22 | # the image-size but at the expense of quality. 23 | train_batch_size: 128 24 | 25 | # Set num-steps to around 5-to-10 epochs for search. 26 | # Guideline: total_steps = (num-train-examples/train_batch_size)*5. 27 | # Ideally your individual search-trial should 28 | # finish within 30 mins to 1 hour. 29 | total_steps: 10000 30 | 31 | learning_rate: 32 | type: 'cosine' 33 | warmup_learning_rate: 0.0067 34 | warmup_steps: 500 35 | # Reduce the learning rate if you get gradients reaching NAN error. 36 | init_learning_rate: 0.02 37 | gradient_clip_norm: 0.5 38 | # Backbone is trained from scratch. 39 | checkpoint: 40 | path: null 41 | prefix: null 42 | 43 | eval: 44 | # Eval file pattern is provided by the binary flag. 45 | 46 | eval_samples: 2349 47 | 48 | # NOTE: Partial batch will not be used for evaluation. So ideally, 49 | # the total-number of eval-samples should be divisible by 50 | # 'eval_batch_size' if you want all the samples to be used. 51 | # 'eval_batch_size' needs to be divisible by 8 when using TPU. 52 | eval_batch_size: 8 53 | 54 | architecture: 55 | # NOTE: If you change the 'min_level' and 'max_level' 56 | # search-space related parameters here, then you also need 57 | # to change them in the 'search_spaces.py' file. 58 | min_level: 3 59 | max_level: 7 60 | multilevel_features: 'tunable_nasfpn_v2' 61 | # Note that `num_classes` is the total number of classes including 62 | # one background class with an index value of 0. 63 | num_classes: 21 64 | 65 | tunable_nasfpn_v2: 66 | fpn_feat_dims: 256 67 | num_repeats: 3 68 | use_separable_conv: False 69 | 70 | segmentation_parser: 71 | # Controls the effective image-size for training. 72 | output_size: [512, 512] 73 | 74 | resnet: 75 | resnet_depth: 10 76 | -------------------------------------------------------------------------------- /tf1/detection/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf1/detection/__init__.py -------------------------------------------------------------------------------- /tf1/detection/configs/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | -------------------------------------------------------------------------------- /tf1/detection/configs/factory.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Factory to provide model configs.""" 16 | 17 | from tf1.detection.configs import classification_config 18 | from tf1.detection.configs import maskrcnn_config 19 | from tf1.detection.configs import retinanet_config 20 | from tf1.detection.configs import segmentation_config 21 | from tf1.detection.configs import shapemask_config 22 | from tf1.detection.projects.vild.configs import vild_config 23 | from tf1.hyperparameters import params_dict 24 | 25 | 26 | def config_generator(model): 27 | """Model function generator.""" 28 | if model == 'classification': 29 | default_config = classification_config.CLASSIFICATION_CFG 30 | restrictions = classification_config.CLASSIFICATION_RESTRICTIONS 31 | elif model == 'retinanet': 32 | default_config = retinanet_config.RETINANET_CFG 33 | restrictions = retinanet_config.RETINANET_RESTRICTIONS 34 | elif model == 'mask_rcnn' or model == 'cascade_mask_rcnn': 35 | default_config = maskrcnn_config.MASKRCNN_CFG 36 | restrictions = maskrcnn_config.MASKRCNN_RESTRICTIONS 37 | elif model == 'segmentation': 38 | default_config = segmentation_config.SEGMENTATION_CFG 39 | restrictions = segmentation_config.SEGMENTATION_RESTRICTIONS 40 | elif model == 'shapemask': 41 | default_config = shapemask_config.SHAPEMASK_CFG 42 | restrictions = shapemask_config.SHAPEMASK_RESTRICTIONS 43 | elif model == 'vild': 44 | default_config = vild_config.VILD_CFG 45 | restrictions = vild_config.VILD_RESTRICTIONS 46 | else: 47 | raise ValueError('Model %s is not supported.' % model) 48 | 49 | return params_dict.ParamsDict(default_config, restrictions) 50 | -------------------------------------------------------------------------------- /tf1/detection/configs/retinanet_config.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Config template to train Retinanet.""" 16 | 17 | from tf1.detection.configs import detection_config 18 | from tf1.hyperparameters import params_dict 19 | 20 | # pylint: disable=line-too-long 21 | RETINANET_CFG = params_dict.ParamsDict(detection_config.DETECTION_CFG) 22 | RETINANET_CFG.override( 23 | { 24 | 'type': 'retinanet', 25 | 'architecture': { 26 | 'parser': 'retinanet_parser', 27 | 'backbone': 'resnet', 28 | 'multilevel_features': 'fpn', 29 | 'output_flat_fpn_features': False, 30 | }, 31 | 'retinanet_parser': { 32 | 'output_size': [640, 640], 33 | 'match_threshold': 0.5, 34 | 'unmatched_threshold': 0.5, 35 | 'aug_rand_hflip': True, 36 | 'aug_scale_min': 1.0, 37 | 'aug_scale_max': 1.0, 38 | 'aug_policy': '', 39 | 'skip_crowd_during_training': True, 40 | 'max_num_instances': 100, 41 | 'regenerate_source_id': False, 42 | }, 43 | 'retinanet_head': { 44 | 'anchors_per_location': None, # Param no longer used. 45 | 'num_convs': 4, 46 | 'num_filters': 256, 47 | 'use_separable_conv': False, 48 | 'use_batch_norm': True, 49 | }, 50 | 'retinanet_loss': { 51 | 'focal_loss_alpha': 0.25, 52 | 'focal_loss_gamma': 1.5, 53 | 'huber_loss_delta': 0.1, 54 | 'box_loss_weight': 50, 55 | 'normalizer_momentum': 0.0, 56 | }, 57 | }, 58 | is_strict=False) 59 | 60 | RETINANET_RESTRICTIONS = [ 61 | ] 62 | # pylint: enable=line-too-long 63 | -------------------------------------------------------------------------------- /tf1/detection/dataloader/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | -------------------------------------------------------------------------------- /tf1/detection/dataloader/input_reader_util.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Utility function for input reader.""" 16 | 17 | import tensorflow.compat.v1 as tf 18 | 19 | from tf1.detection.ops import spatial_transform_ops 20 | 21 | 22 | def transform_image_for_tpu(batch_images, 23 | space_to_depth_block_size=1, 24 | transpose_images=True): 25 | """Transforms batched images to optimize memory usage on TPU. 26 | 27 | Args: 28 | batch_images: Batched images in the shape [batch_size, image_height, 29 | image_width, num_channel]. 30 | space_to_depth_block_size: An integer for space-to-depth block size. The 31 | input image's height and width must be divisible by block_size. The block 32 | size also needs to match the stride length of the first conv layer. See 33 | go/auto-space-to-depth and tf.nn.space_to_depth. 34 | transpose_images: Whether or not transpose image dimensions. 35 | 36 | Returns: 37 | transformed batched images. 38 | """ 39 | if space_to_depth_block_size > 1: 40 | return spatial_transform_ops.fused_transpose_and_space_to_depth( 41 | batch_images, space_to_depth_block_size, transpose_images) 42 | elif transpose_images: 43 | # Transpose the input images from [N,H,W,C] to [H,W,C,N] since reshape on 44 | # TPU is expensive. 45 | return tf.transpose(batch_images, [1, 2, 3, 0]) 46 | else: 47 | return batch_images 48 | -------------------------------------------------------------------------------- /tf1/detection/dataloader/mode_keys.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Standard names for input dataloader modes. 16 | 17 | The following standard keys are defined: 18 | 19 | * `TRAIN`: training mode. 20 | * `EVAL`: evaluation mode. 21 | * `PREDICT`: prediction mode. 22 | * `PREDICT_WITH_GT`: prediction mode with groundtruths in returned variables. 23 | """ 24 | 25 | from __future__ import absolute_import 26 | from __future__ import division 27 | from __future__ import print_function 28 | 29 | 30 | TRAIN = 'train' 31 | EVAL = 'eval' 32 | PREDICT = 'predict' 33 | PREDICT_WITH_GT = 'predict_with_gt' 34 | -------------------------------------------------------------------------------- /tf1/detection/evaluation/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | -------------------------------------------------------------------------------- /tf1/detection/evaluation/factory.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Evaluator factory.""" 16 | 17 | from __future__ import absolute_import 18 | from __future__ import division 19 | from __future__ import print_function 20 | 21 | from tf1.detection.evaluation import coco_evaluator 22 | 23 | 24 | def evaluator_generator(params): 25 | """Generator function for various evaluators.""" 26 | if params.type == 'box': 27 | evaluator = coco_evaluator.COCOEvaluator( 28 | annotation_file=params.val_json_file, 29 | include_mask=False, 30 | per_category_metrics=params.per_category_metrics) 31 | elif params.type == 'box_and_mask': 32 | evaluator = coco_evaluator.COCOEvaluator( 33 | annotation_file=params.val_json_file, 34 | include_mask=True, 35 | per_category_metrics=params.per_category_metrics) 36 | elif params.type == 'shapemask_box_and_mask': 37 | evaluator = coco_evaluator.ShapeMaskCOCOEvaluator( 38 | mask_eval_class=params.mask_eval_class, 39 | annotation_file=params.val_json_file, 40 | include_mask=True, 41 | per_category_metrics=params.per_category_metrics) 42 | elif params.type == 'lvis_box': 43 | evaluator = coco_evaluator.LVISEvaluator( 44 | annotation_file=params.val_json_file, include_mask=False) 45 | elif params.type == 'lvis_box_and_mask': 46 | evaluator = coco_evaluator.LVISEvaluator( 47 | annotation_file=params.val_json_file, include_mask=True) 48 | else: 49 | raise ValueError('The detection evaluation type `{}` is not supported.' 50 | .format(params.type)) 51 | 52 | return evaluator 53 | -------------------------------------------------------------------------------- /tf1/detection/executor/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | -------------------------------------------------------------------------------- /tf1/detection/modeling/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | -------------------------------------------------------------------------------- /tf1/detection/modeling/architecture/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | -------------------------------------------------------------------------------- /tf1/detection/modeling/architecture/efficientnet_constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | """EfficientNet (x) model constants.""" 16 | 17 | EFFICIENTNET_NUM_BLOCKS = 7 18 | EFFICIENTNET_STRIDES = [1, 2, 2, 2, 1, 2, 1] # Same as MobileNet-V2. 19 | 20 | # The fixed EFFICIENTNET-B0 architecture discovered by NAS. 21 | # Each element represents a specification of a building block: 22 | # (repeats, block_fn, expand_ratio, kernel_size, se_ratio, filters, activation) 23 | EFFICIENTNET_B0_BLOCK_SPECS = [ 24 | (1, 'mbconv', 1, 3, 0.25, 16, 'swish'), 25 | (2, 'mbconv', 6, 3, 0.25, 24, 'swish'), 26 | (2, 'mbconv', 6, 5, 0.25, 40, 'swish'), 27 | (3, 'mbconv', 6, 3, 0.25, 80, 'swish'), 28 | (3, 'mbconv', 6, 5, 0.25, 112, 'swish'), 29 | (4, 'mbconv', 6, 5, 0.25, 192, 'swish'), 30 | (1, 'mbconv', 6, 3, 0.25, 320, 'swish'), 31 | ] 32 | 33 | # The fixed EFFICIENTNET-X-B0 architecture discovered by NAS. 34 | # Each element represents a specification of a building block: 35 | # (repeats, block_fn, expand_ratio, kernel_size, se_ratio, filters, activation) 36 | EFFICIENTNET_X_B0_BLOCK_SPECS = [ 37 | (1, 'mbconv', 1, 3, 1, 16, 'relu'), 38 | (2, 'fused_mbconv', 6, 3, 0.5, 24, 'swish'), 39 | (2, 'fused_mbconv', 6, 5, 0.25, 40, 'swish'), 40 | (3, 'mbconv', 6, 3, 0.25, 80, 'relu'), 41 | (3, 'mbconv', 6, 5, 0.25, 112, 'relu'), 42 | (4, 'mbconv', 6, 5, 0.25, 192, 'relu'), 43 | (1, 'mbconv', 6, 3, 0.25, 320, 'relu'), 44 | ] 45 | -------------------------------------------------------------------------------- /tf1/detection/modeling/architecture/identity.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Identity Fn that forwards the input features.""" 16 | 17 | from __future__ import absolute_import 18 | from __future__ import division 19 | from __future__ import print_function 20 | 21 | 22 | class Identity(object): 23 | """Identity function that forwards the input features.""" 24 | 25 | def __call__(self, features, is_training=False): 26 | """Only forwards the input features.""" 27 | return features 28 | 29 | -------------------------------------------------------------------------------- /tf1/detection/modeling/architecture/mnasnet_constants.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | """MnasNet model constants.""" 16 | 17 | # NOTE: These constants are used for the tunable-mnasnet-search-space 18 | # as well. The goal here is to keep these in a separate file to avoid 19 | # dependency on any implementation specific details such as the use 20 | # of TensorFlow. 21 | 22 | MNASNET_NUM_BLOCKS = 7 23 | MNASNET_STRIDES = [1, 2, 2, 2, 1, 2, 1] # Same as MobileNet-V2. 24 | 25 | # The fixed MnasNet-A1 architecture discovered by NAS. 26 | # Each element represents a specification of a building block: 27 | # (num_repeats, block_fn, expand_ratio, kernel_size, se_ratio, output_filters) 28 | MNASNET_A1_BLOCK_SPECS = [ 29 | (1, 'mbconv', 1, 3, 0.0, 16), 30 | (2, 'mbconv', 6, 3, 0.0, 24), 31 | (3, 'mbconv', 3, 5, 0.25, 40), 32 | (4, 'mbconv', 6, 3, 0.0, 80), 33 | (2, 'mbconv', 6, 3, 0.25, 112), 34 | (3, 'mbconv', 6, 5, 0.25, 160), 35 | (1, 'mbconv', 6, 3, 0.0, 320), 36 | ] 37 | -------------------------------------------------------------------------------- /tf1/detection/modeling/classification_model.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Model definition for image classification.""" 16 | 17 | from __future__ import absolute_import 18 | from __future__ import division 19 | from __future__ import print_function 20 | 21 | import tensorflow.compat.v1 as tf 22 | 23 | from tf1.detection.dataloader import mode_keys 24 | from tf1.detection.modeling import base_model 25 | from tf1.detection.modeling.architecture import factory 26 | 27 | 28 | class ClassificationModel(base_model.BaseModel): 29 | """Classification model function.""" 30 | 31 | def __init__(self, params): 32 | super(ClassificationModel, self).__init__(params) 33 | 34 | # Architecture generators. 35 | self._backbone_fn = factory.backbone_generator(params) 36 | self._head_fn = factory.classification_head_generator(params) 37 | 38 | self._num_classes = params.architecture.num_classes 39 | self._label_smoothing = params.train.label_smoothing 40 | 41 | def _build_outputs(self, features, labels, mode): 42 | is_training = mode == mode_keys.TRAIN 43 | 44 | backbone_features = self._backbone_fn(features, is_training=is_training) 45 | logits = self._head_fn(backbone_features, is_training=is_training) 46 | 47 | model_outputs = {'logits': logits} 48 | 49 | return model_outputs 50 | 51 | def build_losses(self, outputs, labels): 52 | # Loss. 53 | one_hot_labels = tf.one_hot(labels, self._num_classes) 54 | model_loss = tf.losses.softmax_cross_entropy( 55 | one_hot_labels, 56 | outputs['logits'], 57 | label_smoothing=self._label_smoothing) 58 | self.add_scalar_summary('model_loss', model_loss) 59 | 60 | return model_loss 61 | 62 | def build_metrics(self, outputs, labels): 63 | 64 | def metric_fn(labels, logits): 65 | predictions = tf.argmax(logits, axis=1) 66 | top_1_accuracy = tf.metrics.accuracy(labels, predictions) 67 | in_top_5 = tf.nn.in_top_k(logits, labels, 5) 68 | top_5_accuracy = tf.metrics.mean(tf.cast(in_top_5, tf.float32)) 69 | 70 | return { 71 | 'top_1_accuracy': top_1_accuracy, 72 | 'top_5_accuracy': top_5_accuracy, 73 | } 74 | 75 | return (metric_fn, [labels, outputs['logits']]) 76 | 77 | def build_predictions(self, outputs, labels): 78 | raise NotImplementedError('The `build_predictions` is not implemented.') 79 | -------------------------------------------------------------------------------- /tf1/detection/modeling/factory.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Factory to build different models.""" 16 | 17 | from tf1.detection.modeling import cascade_maskrcnn_model 18 | from tf1.detection.modeling import classification_model 19 | from tf1.detection.modeling import maskrcnn_model 20 | from tf1.detection.modeling import retinanet_model 21 | from tf1.detection.modeling import segmentation_model 22 | from tf1.detection.modeling import shapemask_model 23 | from tf1.detection.projects.vild.modeling import vild_model 24 | 25 | 26 | def model_generator(params): 27 | """Model function generator.""" 28 | if params.type == 'classification': 29 | model_fn = classification_model.ClassificationModel(params) 30 | elif params.type == 'retinanet': 31 | model_fn = retinanet_model.RetinanetModel(params) 32 | elif params.type == 'mask_rcnn': 33 | model_fn = maskrcnn_model.MaskrcnnModel(params) 34 | elif params.type == 'cascade_mask_rcnn': 35 | model_fn = cascade_maskrcnn_model.CascadeMaskrcnnModel(params) 36 | elif params.type == 'shapemask': 37 | model_fn = shapemask_model.ShapeMaskModel(params) 38 | elif params.type == 'segmentation': 39 | model_fn = segmentation_model.SegmentationModel(params) 40 | elif params.type == 'vild': 41 | model_fn = vild_model.ViLDModel(params) 42 | else: 43 | raise ValueError('Model %s is not supported.'% params.type) 44 | 45 | return model_fn 46 | -------------------------------------------------------------------------------- /tf1/detection/modeling/model_builder.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Model builder for detection model.""" 16 | 17 | from tensorflow.compat.v1 import estimator as tf_estimator 18 | 19 | from tf1.detection.modeling import factory 20 | 21 | 22 | class ModelFn(object): 23 | """Model function for tf.Estimator.""" 24 | 25 | def __init__(self, params): 26 | self._model = factory.model_generator(params) 27 | 28 | def __call__(self, features, labels, mode, params): 29 | """Model function for tf.Estimator. 30 | 31 | Args: 32 | features: the input image tensor and auxiliary information, such as 33 | `image_info` and `source_ids`. The image tensor has a shape of 34 | [batch_size, height, width, 3]. The height and width are fixed and 35 | equal. 36 | labels: the input labels in a dictionary. The labels include score targets 37 | and box targets which are dense label maps. The labels are generated 38 | from inputFn in dataloader/input_reader.py 39 | mode: the mode of TPUEstimator including TRAIN, EVAL, and PREDICT. 40 | params: the dictionary defines hyperparameters of model. 41 | 42 | Returns: 43 | tpu_spec: the TPUEstimatorSpec to run training, evaluation, or 44 | prediction.). 45 | """ 46 | if mode == tf_estimator.ModeKeys.TRAIN: 47 | return self._model.train(features, labels) 48 | elif mode == tf_estimator.ModeKeys.EVAL: 49 | return self._model.evaluate(features, labels) 50 | elif mode == tf_estimator.ModeKeys.PREDICT: 51 | return self._model.predict(features) 52 | else: 53 | raise ValueError('%s mode is not supported.' % mode) 54 | 55 | -------------------------------------------------------------------------------- /tf1/detection/ops/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | -------------------------------------------------------------------------------- /tf1/detection/projects/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf1/detection/projects/__init__.py -------------------------------------------------------------------------------- /tf1/detection/projects/vild/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf1/detection/projects/vild/__init__.py -------------------------------------------------------------------------------- /tf1/detection/projects/vild/configs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf1/detection/projects/vild/configs/__init__.py -------------------------------------------------------------------------------- /tf1/detection/projects/vild/dataloader/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf1/detection/projects/vild/dataloader/__init__.py -------------------------------------------------------------------------------- /tf1/detection/projects/vild/modeling/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf1/detection/projects/vild/modeling/__init__.py -------------------------------------------------------------------------------- /tf1/detection/projects/vild/ops/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf1/detection/projects/vild/ops/__init__.py -------------------------------------------------------------------------------- /tf1/detection/serving/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | -------------------------------------------------------------------------------- /tf1/detection/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | -------------------------------------------------------------------------------- /tf1/detection/utils/benchmark_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Benchmark utils for detection models.""" 16 | 17 | from __future__ import absolute_import 18 | from __future__ import division 19 | from __future__ import print_function 20 | 21 | import json 22 | from absl import logging 23 | import numpy as np 24 | import tensorflow.compat.v1 as tf 25 | 26 | 27 | def compute_model_statistics(batch_size, json_file_path=None): 28 | """Compute number of parameters and FLOPS.""" 29 | num_trainable_params = np.sum( 30 | [np.prod(var.get_shape().as_list()) for var in tf.trainable_variables()]) 31 | num_trainable_params_million = num_trainable_params * 1. / 10**6 32 | logging.info('number of trainable params: %f M.', 33 | num_trainable_params_million) 34 | 35 | options = tf.profiler.ProfileOptionBuilder.float_operation() 36 | options['output'] = 'none' 37 | flops = tf.profiler.profile( 38 | tf.get_default_graph(), options=options).total_float_ops 39 | flops_per_image = flops * 1. / batch_size / 10**9 / 2 40 | logging.info('number of FLOPS (multi-adds) per image: %f B.', 41 | flops_per_image) 42 | 43 | if json_file_path: 44 | with tf.gfile.Open(json_file_path, 'w') as fp: 45 | json.dump( 46 | { 47 | 'multi_add_flops_billion': 48 | float(flops_per_image), 49 | 'num_trainable_params_million': 50 | float(num_trainable_params_million) 51 | }, fp) 52 | 53 | return num_trainable_params, flops_per_image 54 | -------------------------------------------------------------------------------- /tf1/detection/utils/class_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Utility functions for handling dataset object categories.""" 16 | 17 | 18 | def coco_split_class_ids(split_name): 19 | """Return the COCO class split ids based on split name and training mode. 20 | 21 | Args: 22 | split_name: The name of dataset split. 23 | 24 | Returns: 25 | class_ids: a python list of integer. 26 | """ 27 | if split_name == 'all': 28 | return [] 29 | 30 | elif split_name == 'voc': 31 | return [ 32 | 1, 2, 3, 4, 5, 6, 7, 9, 16, 17, 18, 19, 20, 21, 44, 62, 63, 64, 67, 72 33 | ] 34 | 35 | elif split_name == 'nonvoc': 36 | return [ 37 | 8, 10, 11, 13, 14, 15, 22, 23, 24, 25, 27, 28, 31, 32, 33, 34, 35, 36, 38 | 37, 38, 39, 40, 41, 42, 43, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 39 | 57, 58, 59, 60, 61, 65, 70, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 40 | 85, 86, 87, 88, 89, 90 41 | ] 42 | 43 | else: 44 | raise ValueError('Invalid split name {}!!!'.format(split_name)) 45 | -------------------------------------------------------------------------------- /tf1/detection/utils/config_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | """Config utils.""" 16 | 17 | import os 18 | 19 | import tensorflow.compat.v1 as tf 20 | 21 | from tf1.hyperparameters import params_dict 22 | 23 | 24 | _PARSERS = [ 25 | 'classification_parser', 26 | 'retinanet_parser', 27 | 'maskrcnn_parser', 28 | 'segmentation_parser', 29 | 'shapemask_parser', 30 | ] 31 | 32 | _BACKBONES = [ 33 | 'resnet', 34 | 'spinenet', 35 | 'spinenet_mbconv', 36 | 37 | 'mnasnet', 38 | 'tunable_mnasnet', 39 | 'tunable_spinenet', 40 | 'tunable_spinenet_mbconv', 41 | 42 | ] 43 | 44 | _MULTILEVEL_FEATURES = [ 45 | 'fpn', 46 | 'nasfpn', 47 | 48 | 'tunable_nasfpn_v1', 49 | 'tunable_nasfpn_v2', 50 | 51 | ] 52 | 53 | 54 | def filter_unused_blocks(params): 55 | """Filters unused architecture params blocks.""" 56 | filtered_params = params_dict.ParamsDict(params) 57 | if 'parser' in params.architecture.as_dict().keys(): 58 | for parser in _PARSERS: 59 | if (parser in params.as_dict().keys() and 60 | parser != params.architecture.parser): 61 | delattr(filtered_params, parser) 62 | if 'backbone' in params.architecture.as_dict().keys(): 63 | for backbone in _BACKBONES: 64 | if (backbone in params.as_dict().keys() and 65 | backbone != params.architecture.backbone): 66 | delattr(filtered_params, backbone) 67 | if 'multilevel_features' in params.architecture.as_dict().keys(): 68 | for features in _MULTILEVEL_FEATURES: 69 | if (features in params.as_dict().keys() and 70 | features != params.architecture.multilevel_features): 71 | delattr(filtered_params, features) 72 | return filtered_params 73 | 74 | 75 | def save_config(params, model_dir): 76 | if model_dir: 77 | params = filter_unused_blocks(params) 78 | if not tf.gfile.Exists(model_dir): 79 | tf.gfile.MakeDirs(model_dir) 80 | params_dict.save_params_dict_to_yaml( 81 | params, os.path.join(model_dir, 'params.yaml')) 82 | -------------------------------------------------------------------------------- /tf1/detection/utils/dataloader_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | """Utility functions for dataloader.""" 16 | 17 | import tensorflow.compat.v1 as tf 18 | 19 | from tf1.detection.utils import input_utils 20 | 21 | 22 | def process_source_id(source_id): 23 | """Processes source_id to the right format.""" 24 | if source_id.dtype == tf.string: 25 | source_id = tf.string_to_number(source_id, out_type=tf.int64) 26 | with tf.control_dependencies([source_id]): 27 | source_id = tf.cond(tf.equal(tf.size(source_id), 0), 28 | lambda: tf.cast(tf.constant(-1), tf.int64), 29 | lambda: tf.identity(source_id)) 30 | return source_id 31 | 32 | 33 | def pad_groundtruths_to_fixed_size(gt, n): 34 | """Pads the first dimension of groundtruths labels to the fixed size.""" 35 | gt['boxes'] = input_utils.clip_or_pad_to_fixed_size(gt['boxes'], n, -1) 36 | gt['is_crowds'] = input_utils.clip_or_pad_to_fixed_size(gt['is_crowds'], n, 0) 37 | gt['areas'] = input_utils.clip_or_pad_to_fixed_size(gt['areas'], n, -1) 38 | gt['classes'] = input_utils.clip_or_pad_to_fixed_size(gt['classes'], n, -1) 39 | return gt 40 | -------------------------------------------------------------------------------- /tf1/detection/utils/object_detection/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2017 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 | -------------------------------------------------------------------------------- /tf1/detection/utils/shape_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 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 | """Utils to manipulate tensor shapes.""" 16 | 17 | import tensorflow.compat.v1 as tf 18 | 19 | 20 | def get_shape(tensor): 21 | """Returns a list containing static and dynamic values for the dimensions. 22 | 23 | Returns a list of static and dynamic values for shape dimensions. This is 24 | useful to preserve static shapes when available in reshape operation. 25 | 26 | Args: 27 | tensor: A tensor of any type. 28 | 29 | Returns: 30 | A list of size tensor.shape.ndims containing integers or a scalar tensor. 31 | """ 32 | static_shape = tensor.get_shape().as_list() 33 | if all(static_shape): 34 | return static_shape 35 | 36 | combined_shape = [] 37 | dynamic_shape = tf.shape(tensor) 38 | for i, d in enumerate(static_shape): 39 | if d is not None: 40 | combined_shape.append(d) 41 | else: 42 | combined_shape.append(dynamic_shape[i]) 43 | return combined_shape 44 | -------------------------------------------------------------------------------- /tf1/efficientnet/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf1/efficientnet/__init__.py -------------------------------------------------------------------------------- /tf1/efficientnet/condconv/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | -------------------------------------------------------------------------------- /tf1/hyperparameters/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019 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 | -------------------------------------------------------------------------------- /tf1/hyperparameters/common_tpu_flags.py: -------------------------------------------------------------------------------- 1 | # Copyright 2018 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 | """Defining common TPU flags used across all the models.""" 16 | 17 | from absl import flags 18 | 19 | 20 | def define_common_tpu_flags(): 21 | """Define the flags related to TPU's.""" 22 | flags.DEFINE_string( 23 | 'tpu', default=None, 24 | help='The Cloud TPU to use for training. This should be either the name ' 25 | 'used when creating the Cloud TPU, or a grpc://ip.address.of.tpu:8470 ' 26 | 'url.') 27 | 28 | flags.DEFINE_string( 29 | 'gcp_project', default=None, 30 | help='Project name for the Cloud TPU-enabled project. If not specified, we ' 31 | 'will attempt to automatically detect the GCE project from metadata.') 32 | 33 | flags.DEFINE_string( 34 | 'tpu_zone', default=None, 35 | help='GCE zone where the Cloud TPU is located in. If not specified, we ' 36 | 'will attempt to automatically detect the GCE project from metadata.') 37 | 38 | flags.DEFINE_string( 39 | 'eval_master', default=None, 40 | help='GRPC URL of the eval master. Set to an appropiate value when running ' 41 | 'on CPU/GPU.') 42 | -------------------------------------------------------------------------------- /tf1/latency_computation_using_saved_model.Dockerfile: -------------------------------------------------------------------------------- 1 | # NOTE: The source for this starting-point is: 2 | # https://docs.nvidia.com/deeplearning/frameworks/support-matrix/index.html#unique_1446644071 3 | FROM nvcr.io/nvidia/tensorflow:20.06-tf1-py3 4 | 5 | ENV DEBIAN_FRONTEND=noninteractive 6 | 7 | # This is added to fix docker build error related to Nvidia key update. 8 | RUN rm -f /etc/apt/sources.list.d/cuda.list 9 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 10 | 11 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ 12 | | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ 13 | | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y 14 | 15 | RUN apt-get update && apt-get install -y --no-install-recommends \ 16 | cmake \ 17 | curl \ 18 | wget \ 19 | sudo \ 20 | gnupg \ 21 | libsm6 \ 22 | libxext6 \ 23 | libxrender-dev \ 24 | lsb-release \ 25 | ca-certificates && \ 26 | pip install --upgrade pip==21.3.1 && \ 27 | pip install google-cloud-storage==1.42.3 && \ 28 | pip install google-api-python-client==2.29.0 && \ 29 | pip install oauth2client==4.1.3 && \ 30 | pip install Cython==0.29.24 && \ 31 | pip install typing==3.7.4.3 && \ 32 | pip install nvgpu==0.9.0 && \ 33 | pip install fsspec==2021.10.1 && \ 34 | pip install gcsfs==2021.10.1 && \ 35 | pip install pyglove==0.1.0 36 | 37 | # Make sure gsutil will use the default service account 38 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 39 | 40 | 41 | RUN mkdir /root/training 42 | COPY . /root/training/ 43 | ENV PATH="/root/training/:${PATH}" 44 | 45 | WORKDIR /root/training 46 | RUN mv tf1/latency_computation_using_saved_model.py tf1_latency_computation_using_saved_model.py 47 | ENTRYPOINT ["python", "tf1_latency_computation_using_saved_model.py"] 48 | -------------------------------------------------------------------------------- /tf1/nas_multi_trial.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:1.15.0-gpu-py3 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | 5 | # This is added to fix docker build error related to Nvidia key update. 6 | RUN rm -f /etc/apt/sources.list.d/cuda.list 7 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 8 | 9 | RUN apt-get update && apt-get install -y --no-install-recommends \ 10 | cmake \ 11 | curl \ 12 | wget \ 13 | sudo \ 14 | gnupg \ 15 | libsm6 \ 16 | libxext6 \ 17 | libxrender-dev \ 18 | lsb-release \ 19 | ca-certificates \ 20 | build-essential \ 21 | git \ 22 | python \ 23 | python-dev \ 24 | python-pip \ 25 | python-setuptools \ 26 | python-tk && \ 27 | export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \ 28 | echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" > /etc/apt/sources.list.d/google-cloud-sdk.list && \ 29 | curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \ 30 | apt-get update && \ 31 | apt-get install -y google-cloud-sdk && \ 32 | apt-get install ffmpeg libsm6 libxext6 -y 33 | 34 | RUN pip install --upgrade pip setuptools wheel 35 | RUN pip install google-cloud-storage==1.42.3 36 | RUN pip install google-api-python-client==2.29.0 37 | RUN pip install oauth2client==4.1.3 38 | RUN pip install Cython==0.29.24 39 | RUN pip install matplotlib==3.3.4 40 | RUN pip install pycocotools==2.0.2 41 | RUN pip install pyyaml==5.4.1 42 | RUN pip install 'git+https://github.com/cocodataset/cocoapi#egg=pycocotools&subdirectory=PythonAPI' 43 | RUN pip install opencv-python-headless==4.1.2.30 44 | RUN pip install opencv-python==4.5.3.56 45 | RUN pip install lvis==0.5.3 46 | RUN pip install cloudml-hypertune==0.1.0.dev6 47 | RUN pip install typing==3.7.4.3 48 | RUN pip install pydot==1.4.2 49 | RUN pip install fsspec==2021.10.1 50 | RUN pip install gcsfs==2021.10.1 51 | RUN pip install pyglove==0.1.0 52 | 53 | 54 | # Make sure gsutil will use the default service account 55 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 56 | 57 | 58 | RUN mkdir /root/training/ 59 | COPY . /root/training/ 60 | ENV PATH="/root/training/:${PATH}" 61 | 62 | WORKDIR /root/training/ 63 | RUN mv tf1/cloud_search_main.py tf1_cloud_search_main.py 64 | ENTRYPOINT ["python", "tf1_cloud_search_main.py"] 65 | -------------------------------------------------------------------------------- /tf_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | """Tensorflow util libraries.""" 16 | import os 17 | 18 | import tensorflow.compat.v1 as tf 19 | 20 | 21 | def suppress_tf_logging(): 22 | """Suppress logging from tensorflow. 23 | 24 | Resolves duplicate logging from tensorflow, sets INFO level for logging. 25 | """ 26 | tf.logging.set_verbosity(tf.logging.INFO) 27 | os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" 28 | -------------------------------------------------------------------------------- /tf_vision/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/__init__.py -------------------------------------------------------------------------------- /tf_vision/configs/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Configs package definition.""" 16 | 17 | from tf_vision.configs import image_classification 18 | from tf_vision.configs import pointpillars as tunable_pointpillars 19 | from tf_vision.configs import retinanet 20 | from tf_vision.configs import semantic_segmentation 21 | 22 | from tf_vision.pointpillars.configs import pointpillars as baseline_pointpillars 23 | -------------------------------------------------------------------------------- /tf_vision/configs/decoders.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | """Decoder configurations.""" 16 | import dataclasses 17 | from typing import Optional 18 | 19 | from official.modeling import hyperparams 20 | from official.vision.beta.configs import decoders 21 | 22 | 23 | @dataclasses.dataclass 24 | class Identity(hyperparams.Config): 25 | """Identity config.""" 26 | 27 | 28 | @dataclasses.dataclass 29 | class TunableNASFPN(hyperparams.Config): 30 | """Tunable NASFPN config.""" 31 | num_filters: int = 256 32 | num_repeats: int = 5 33 | use_separable_conv: bool = False 34 | block_specs_json: Optional[str] = None 35 | 36 | 37 | @dataclasses.dataclass 38 | class Decoder(hyperparams.OneOfConfig): 39 | """Configuration for decoders. 40 | 41 | Attributes: 42 | type: 'str', type of decoder be used, one of the fields below. 43 | identity: identity decoder config. 44 | tunable_nasfpn: tunable NASFPN decoder. 45 | fpn: FPN decoder. 46 | aspp: ASPP decoder. 47 | """ 48 | type: Optional[str] = None 49 | identity: Identity = dataclasses.field(default_factory=Identity) 50 | tunable_nasfpn: TunableNASFPN = dataclasses.field( 51 | default_factory=TunableNASFPN 52 | ) 53 | fpn: decoders.FPN = dataclasses.field(default_factory=decoders.FPN) 54 | aspp: decoders.ASPP = dataclasses.field(default_factory=decoders.ASPP) 55 | -------------------------------------------------------------------------------- /tf_vision/configs/experiments/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/configs/experiments/__init__.py -------------------------------------------------------------------------------- /tf_vision/configs/experiments/mnasnet_search_finetune_tpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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 | # Imagenet finetuning config. 16 | task: 17 | model: 18 | # Note that `num_classes` is the total number of classes including 19 | # one background class with an index value of 0. 20 | num_classes: 1001 21 | # Controls the effective image-size for training. 22 | input_size: [224, 224, 3] 23 | backbone: 24 | type: 'tunable_mnasnet' 25 | tunable_mnasnet: 26 | # The number of filters of the output endpoints. 27 | endpoints_num_filters: 1280 28 | dropout_rate: 0.2 29 | norm_activation: 30 | norm_epsilon: 0.001 31 | norm_momentum: 0.99 32 | use_sync_bn: true 33 | losses: 34 | one_hot: true 35 | label_smoothing: 0.1 36 | l2_weight_decay: 0.00001 37 | train_data: 38 | # Reduce the batch-size if you run into out-of-memory error. Out-of-memory error may also be 39 | # resolved by reducing the image-size but at the expense of quality. 40 | # NOTE: 256 is for 4x4 TPU Pod. May need to adjust batch size and learning rate for 2x2 or 41 | # GPU devices. 42 | global_batch_size: 1024 43 | validation_data: 44 | # NOTE: Partial batch will not be used for evaluation. So ideally, 45 | # the total-number of eval-samples should be divisible by 46 | # 'eval_batch_size' if you want all the samples to be used. 47 | # 'eval_batch_size' needs to be divisible by 8 when using TPU. 48 | global_batch_size: 1024 49 | drop_remainder: false 50 | init_checkpoint: null 51 | init_checkpoint_modules: null 52 | trainer: 53 | # Set num-steps to around 200 epochs. 54 | train_steps: 437898 # ~350 epochs (350*(1281167/1024)) 55 | validation_steps: 49 56 | steps_per_loop: 1251 57 | validation_interval: 1251 58 | summary_interval: 1251 59 | checkpoint_interval: 1251 60 | optimizer_config: 61 | optimizer: 62 | type: 'rmsprop' 63 | rmsprop: 64 | epsilon: 0.002 65 | momentum: 0.9 66 | global_clipnorm: 1 67 | warmup: 68 | linear: 69 | name: linear 70 | warmup_learning_rate: 0 71 | warmup_steps: 6255 72 | type: linear 73 | learning_rate: 74 | cosine: 75 | decay_steps: 437898 76 | # Reduce the learning rate if you get gradients reaching NAN error. 77 | initial_learning_rate: 0.064 78 | type: 'cosine' 79 | -------------------------------------------------------------------------------- /tf_vision/configs/experiments/mnasnet_search_tpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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 | # MNasNet Imagenet search config. 16 | task: 17 | model: 18 | # Note that `num_classes` is the total number of classes including 19 | # one background class with an index value of 0. 20 | num_classes: 1001 21 | # Controls the effective image-size for training. 22 | input_size: [224, 224, 3] 23 | backbone: 24 | type: 'tunable_mnasnet' 25 | tunable_mnasnet: 26 | # The number of filters of the output endpoints. 27 | endpoints_num_filters: 256 28 | dropout_rate: 0.2 29 | norm_activation: 30 | norm_epsilon: 0.001 31 | norm_momentum: 0.99 32 | use_sync_bn: true 33 | losses: 34 | one_hot: true 35 | label_smoothing: 0.1 36 | train_data: 37 | # Reduce the batch-size if you run into out-of-memory error. 38 | # Out-of-memory error may also be resolved by reducing 39 | # the image-size but at the expense of quality. 40 | global_batch_size: 1024 41 | validation_data: 42 | # NOTE: Partial batch will not be used for evaluation. So ideally, 43 | # the total-number of eval-samples should be divisible by 44 | # 'eval_batch_size' if you want all the samples to be used. 45 | # 'eval_batch_size' needs to be divisible by 8 when using TPU. 46 | global_batch_size: 1024 47 | drop_remainder: false 48 | 49 | # Backbone is trained from scratch. 50 | init_checkpoint: null 51 | init_checkpoint_modules: null 52 | trainer: 53 | # Set num-steps to around 5 to 10 epochs for search. 54 | # Guideline: total_steps = (num-train-examples/train_batch_size)*5. 55 | # Ideally your individual search-trial should 56 | # finish within 30 mins to 1 hour. 57 | train_steps: 8784 # ~8 epochs. 58 | validation_steps: 20 # 20000 examples / 1024 (batch_size) = 20 steps 59 | steps_per_loop: 1098 60 | validation_interval: 1098 61 | summary_interval: 1098 62 | checkpoint_interval: 1098 63 | optimizer_config: 64 | optimizer: 65 | type: 'sgd' 66 | sgd: 67 | momentum: 0.9 68 | learning_rate: 69 | stepwise: 70 | boundaries: [6588] # Decay at 6th epoches. 71 | values: [0.064, 0.0064] 72 | type: 'stepwise' 73 | warmup: 74 | type: 'linear' 75 | linear: 76 | warmup_steps: 601 # 0.5 epoch. 77 | 78 | -------------------------------------------------------------------------------- /tf_vision/configs/experiments/pointpillars_search_finetune_gpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 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 | # PointPillars search config. 16 | # Expected best output when run using 8 V100 GPUs per trial: 17 | # mAP: 0.49, mAPH: 0.48 18 | # Duration: 8 days 19 | runtime: 20 | distribution_strategy: 'mirrored' 21 | mixed_precision_dtype: 'float32' 22 | task: 23 | model: 24 | classes: 'vehicle' 25 | num_classes: 2 26 | image: 27 | x_range: [-76.8, 76.8] 28 | y_range: [-76.8, 76.8] 29 | z_range: [-3.0, 3.0] 30 | resolution: 0.3 31 | height: 512 32 | width: 512 33 | pillars: 34 | num_pillars: 24000 35 | num_points_per_pillar: 100 36 | num_features_per_point: 10 37 | min_level: 1 38 | max_level: 3 39 | anchors: 40 | - length: 15.752693 41 | width: 6.930973 42 | anchor_labeler: 43 | match_threshold: 0.6 44 | unmatched_threshold: 0.45 45 | detection_generator: 46 | pre_nms_score_threshold: 0.05 47 | nms_iou_threshold: 0.5 48 | max_num_detections: 200 49 | norm_activation: 50 | use_sync_bn: false 51 | train_data: 52 | global_batch_size: 16 53 | dtype: 'float32' 54 | shuffle_buffer_size: 64 55 | prefetch_buffer_size: 64 56 | validation_data: 57 | global_batch_size: 16 58 | dtype: 'float32' 59 | shuffle_buffer_size: 64 60 | prefetch_buffer_size: 64 61 | init_checkpoint: null 62 | use_wod_metrics: true 63 | trainer: 64 | # (158081 / 16) * 75 = 9880 * 75 = 741000 65 | train_steps: 741000 66 | # 39987 / 16 67 | validation_steps: 2500 68 | validation_interval: 9880 69 | steps_per_loop: 9880 70 | summary_interval: 9880 71 | checkpoint_interval: 9880 72 | optimizer_config: 73 | optimizer: 74 | type: 'sgd' 75 | sgd: 76 | momentum: 0.9 77 | global_clipnorm: 10.0 78 | learning_rate: 79 | type: 'cosine' 80 | cosine: 81 | decay_steps: 741000 82 | initial_learning_rate: 0.0008 83 | warmup: 84 | type: 'linear' 85 | linear: 86 | warmup_learning_rate: 0.00016 87 | warmup_steps: 9880 88 | -------------------------------------------------------------------------------- /tf_vision/configs/experiments/pointpillars_search_gpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 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 | # PointPillars search config. 16 | # Expected best output when run using 4 V100 GPUs per trial: 17 | # mAP: 0.28, mAPH: 0.27 18 | # Duration of each trial: 3 hr 40 mins 19 | runtime: 20 | distribution_strategy: 'mirrored' 21 | mixed_precision_dtype: 'float32' 22 | task: 23 | model: 24 | classes: 'vehicle' 25 | num_classes: 2 26 | image: 27 | x_range: [-76.8, 76.8] 28 | y_range: [-76.8, 76.8] 29 | z_range: [-3.0, 3.0] 30 | resolution: 0.3 31 | height: 512 32 | width: 512 33 | pillars: 34 | num_pillars: 24000 35 | num_points_per_pillar: 100 36 | num_features_per_point: 10 37 | min_level: 1 38 | max_level: 3 39 | anchors: 40 | - length: 15.752693 41 | width: 6.930973 42 | anchor_labeler: 43 | match_threshold: 0.6 44 | unmatched_threshold: 0.45 45 | detection_generator: 46 | pre_nms_score_threshold: 0.05 47 | nms_iou_threshold: 0.5 48 | max_num_detections: 200 49 | norm_activation: 50 | use_sync_bn: false 51 | train_data: 52 | global_batch_size: 8 53 | dtype: 'float32' 54 | shuffle_buffer_size: 64 55 | prefetch_buffer_size: 64 56 | validation_data: 57 | global_batch_size: 8 58 | dtype: 'float32' 59 | shuffle_buffer_size: 64 60 | prefetch_buffer_size: 64 61 | init_checkpoint: null 62 | use_wod_metrics: true 63 | trainer: 64 | # (158081 / 8) * 1 = 19760 65 | train_steps: 19760 66 | # 39987 / 8 67 | validation_steps: 4998 68 | validation_interval: 19760 69 | steps_per_loop: 19760 70 | summary_interval: 19760 71 | checkpoint_interval: 19760 72 | optimizer_config: 73 | optimizer: 74 | type: 'sgd' 75 | sgd: 76 | momentum: 0.9 77 | global_clipnorm: 10.0 78 | learning_rate: 79 | type: 'cosine' 80 | cosine: 81 | decay_steps: 19760 82 | initial_learning_rate: 0.0008 83 | warmup: 84 | type: 'linear' 85 | linear: 86 | warmup_learning_rate: 0.00008 87 | warmup_steps: 1000 88 | -------------------------------------------------------------------------------- /tf_vision/configs/factory.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Factory to create TF Vision experiment config.""" 16 | 17 | from official.core import config_definitions as cfg 18 | from official.core import exp_factory 19 | 20 | 21 | def config_generator(model): 22 | """Generates and returns a default experiment config.""" 23 | if model == 'classification': 24 | default_config = exp_factory.get_exp_config('image_classification_nas') 25 | elif model == 'retinanet': 26 | default_config = exp_factory.get_exp_config('retinanet_nas') 27 | elif model == 'segmentation': 28 | default_config = exp_factory.get_exp_config('semantic_segmentation_nas') 29 | elif model == 'pointpillars': 30 | default_config = exp_factory.get_exp_config('pointpillars_nas') 31 | elif model == 'pointpillars_baseline': 32 | default_config = exp_factory.get_exp_config('pointpillars_baseline') 33 | else: 34 | raise ValueError('Model %s is not supported.' % model) 35 | 36 | return default_config 37 | -------------------------------------------------------------------------------- /tf_vision/dataloaders/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/dataloaders/__init__.py -------------------------------------------------------------------------------- /tf_vision/dataloaders/segmentation_input.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Data parser and processing for segmentation datasets.""" 16 | from typing import Optional 17 | import tensorflow as tf 18 | 19 | from nas_lib.augmentation_2d import policies_tf2 as policies 20 | 21 | from official.vision.beta.dataloaders import segmentation_input 22 | from official.vision.beta.ops import preprocess_ops 23 | 24 | 25 | class Parser(segmentation_input.Parser): 26 | """Parser to parse an image and its annotations into a dictionary of tensors.""" 27 | 28 | def __init__(self, aug_policy = None, **kwargs): 29 | """Initializes parameters for parsing annotations in the dataset. 30 | 31 | Args: 32 | aug_policy: An optional augmentation policy to use. This can be a JSON 33 | string for an pyglove augmentation policy object. An empty string 34 | indicates no augmentation policy. 35 | **kwargs: Additional arguments for base class. 36 | """ 37 | super().__init__(**kwargs) 38 | self._aug_policy = aug_policy 39 | 40 | def _prepare_image_and_label(self, data): 41 | """Prepare normalized image and label.""" 42 | image = tf.io.decode_image(data['image/encoded'], channels=3) 43 | label = tf.io.decode_image( 44 | data['image/segmentation/class/encoded'], channels=1) 45 | height = data['image/height'] 46 | width = data['image/width'] 47 | image = tf.reshape(image, (height, width, 3)) 48 | 49 | # Apply augmentation if aug_policy is present. 50 | if self._aug_policy: 51 | # Perform augmentation according to the pyglove policy. 52 | policy = policies.get_policy_from_str(self._aug_policy) 53 | image, label = policy(image, segmentation_mask=label) 54 | 55 | label = tf.reshape(label, (1, height, width)) 56 | label = tf.cast(label, tf.float32) 57 | # Normalizes image with mean and std pixel values. 58 | image = preprocess_ops.normalize_image(image) 59 | return image, label 60 | -------------------------------------------------------------------------------- /tf_vision/latency_computation_using_saved_model.Dockerfile: -------------------------------------------------------------------------------- 1 | # NOTE: The source for this starting-point is: 2 | # https://docs.nvidia.com/deeplearning/frameworks/support-matrix/index.html#unique_1446644071 3 | FROM nvcr.io/nvidia/tensorflow:22.05-tf2-py3 4 | 5 | ENV DEBIAN_FRONTEND=noninteractive 6 | 7 | # This is added to fix docker build error related to Nvidia key update. 8 | RUN rm -f /etc/apt/sources.list.d/cuda.list 9 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 10 | 11 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ 12 | | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ 13 | | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y 14 | 15 | RUN pip install --upgrade pip==21.3.1 && \ 16 | pip install Pillow==8.4.0 && \ 17 | pip install nvgpu==0.9.0 && \ 18 | pip install fsspec==2021.10.1 && \ 19 | pip install gcsfs==2021.10.1 && \ 20 | pip install pyglove==0.1.0 21 | 22 | # NOTE: Installing protobuf in the very end else it gives error when importing 23 | # tensorflow. 24 | RUN pip install protobuf==3.20.* 25 | 26 | # Make sure gsutil will use the default service account 27 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 28 | 29 | RUN mkdir /root/training 30 | COPY . /root/training/ 31 | ENV PATH="/root/training/:$PATH" 32 | 33 | WORKDIR /root/training 34 | RUN mv tf_vision/latency_computation_using_saved_model.py tf_vision_latency_computation_using_saved_model.py 35 | ENTRYPOINT ["python", "tf_vision_latency_computation_using_saved_model.py"] 36 | -------------------------------------------------------------------------------- /tf_vision/modeling/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Modeling package definition.""" 16 | 17 | from tf_vision.modeling import mnasnet 18 | from tf_vision.modeling import tunable_mnasnet 19 | from tf_vision.modeling import tunable_nasfpn 20 | from tf_vision.modeling import tunable_pointpillars 21 | from tf_vision.modeling import tunable_spinenet 22 | -------------------------------------------------------------------------------- /tf_vision/nas_multi_trial.Dockerfile: -------------------------------------------------------------------------------- 1 | # This Dockerfile runs the TF-Vision cloud-search-main file. 2 | 3 | FROM tensorflow/tensorflow:2.7.0-gpu 4 | 5 | ENV DEBIAN_FRONTEND=noninteractive 6 | 7 | # This is added to fix docker build error related to Nvidia key update. 8 | RUN rm -f /etc/apt/sources.list.d/cuda.list 9 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 10 | 11 | # Install basic libs 12 | RUN apt-get update && apt-get install -y --no-install-recommends \ 13 | cmake \ 14 | curl \ 15 | wget \ 16 | sudo \ 17 | gnupg \ 18 | libsm6 \ 19 | libxext6 \ 20 | libxrender-dev \ 21 | lsb-release \ 22 | ca-certificates \ 23 | build-essential \ 24 | git 25 | 26 | 27 | # Install google cloud SDK 28 | RUN wget -q https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-359.0.0-linux-x86_64.tar.gz 29 | RUN tar xzf google-cloud-sdk-359.0.0-linux-x86_64.tar.gz 30 | RUN ./google-cloud-sdk/install.sh -q 31 | # Make sure gsutil will use the default service account 32 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 33 | 34 | 35 | # Install required libs 36 | RUN pip install --upgrade pip 37 | RUN pip install cloud-tpu-client==0.10 38 | RUN pip install pyyaml==5.4.1 39 | RUN pip install fsspec==2021.10.1 40 | RUN pip install gcsfs==2021.10.1 41 | RUN pip install tensorflow-text==2.7.0 42 | RUN pip install tf-models-official==2.7.1 43 | RUN pip install pyglove==0.1.0 44 | RUN pip install google-cloud-storage==1.42.3 45 | 46 | # Prepare workspace 47 | RUN mkdir /root/training 48 | COPY . /root/training/ 49 | ENV PATH="/root/training/:$PATH" 50 | 51 | WORKDIR /root/training 52 | RUN mv tf_vision/cloud_search_main.py tf_vision_cloud_search_main.py 53 | ENTRYPOINT ["python", "tf_vision_cloud_search_main.py"] 54 | -------------------------------------------------------------------------------- /tf_vision/pointpillars/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/pointpillars/__init__.py -------------------------------------------------------------------------------- /tf_vision/pointpillars/configs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/pointpillars/configs/__init__.py -------------------------------------------------------------------------------- /tf_vision/pointpillars/configs/vehicle/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/pointpillars/configs/vehicle/__init__.py -------------------------------------------------------------------------------- /tf_vision/pointpillars/configs/vehicle/pointpillars_3d_baseline_gpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 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 | # Use this config to train PointPillars baseline on vehicle class. 16 | # experiment type: pointpillars_baseline 17 | # strategy: train and evaluate on 8 V100 GPUs. 18 | # mAP: 0.46 19 | # mAPH: 0.45 20 | # duraing: 4 hrs/epoch, 8 hrs/50 epochs 21 | runtime: 22 | distribution_strategy: 'mirrored' 23 | mixed_precision_dtype: 'float32' 24 | task: 25 | model: 26 | classes: 'vehicle' 27 | num_classes: 2 28 | image: 29 | x_range: [-76.8, 76.8] 30 | y_range: [-76.8, 76.8] 31 | z_range: [-3.0, 3.0] 32 | resolution: 0.3 33 | height: 512 34 | width: 512 35 | pillars: 36 | num_pillars: 24000 37 | num_points_per_pillar: 100 38 | num_features_per_point: 10 39 | min_level: 1 40 | max_level: 1 41 | anchors: 42 | - length: 15.752693 43 | width: 6.930973 44 | anchor_labeler: 45 | match_threshold: 0.6 46 | unmatched_threshold: 0.45 47 | featurizer: 48 | num_blocks: 1 49 | num_channels: 64 # C 50 | backbone: 51 | min_level: 1 52 | max_level: 3 53 | num_convs: 6 54 | detection_generator: 55 | pre_nms_score_threshold: 0.05 56 | nms_iou_threshold: 0.5 57 | max_num_detections: 200 58 | train_data: 59 | global_batch_size: 16 # 2 * 8 60 | dtype: 'float32' 61 | shuffle_buffer_size: 256 62 | prefetch_buffer_size: 256 63 | validation_data: 64 | global_batch_size: 32 # 4 * 8 65 | dtype: 'float32' 66 | shuffle_buffer_size: 256 67 | prefetch_buffer_size: 256 68 | init_checkpoint: null 69 | use_wod_metrics: true 70 | trainer: 71 | # (158081 / 16) = 9880, * 50 72 | train_steps: 494000 73 | # 39987 / 32 74 | validation_steps: 1250 75 | validation_interval: 9880 76 | steps_per_loop: 9880 77 | summary_interval: 9880 78 | checkpoint_interval: 9880 79 | optimizer_config: 80 | optimizer: 81 | type: 'sgd' 82 | sgd: 83 | momentum: 0.9 84 | global_clipnorm: 10.0 85 | learning_rate: 86 | type: 'cosine' 87 | cosine: 88 | decay_steps: 494000 89 | initial_learning_rate: 0.0016 90 | warmup: 91 | type: 'linear' 92 | linear: 93 | warmup_learning_rate: 0.00016 94 | warmup_steps: 9880 # 1 epoch 95 | -------------------------------------------------------------------------------- /tf_vision/pointpillars/configs/vehicle/pointpillars_3d_baseline_local.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 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 | # This config is used to test PointPillars baseline model training pipeline locally. 16 | # It runs a very small amount of epochs to verify the functionality of the training pipeline. 17 | # experiment type: pointpillars_baseline 18 | # strategy: train and evaluate on CPU 19 | runtime: 20 | distribution_strategy: 'mirrored' 21 | mixed_precision_dtype: 'float32' 22 | task: 23 | model: 24 | classes: 'vehicle' 25 | num_classes: 2 26 | image: 27 | x_range: [-76.8, 76.8] 28 | y_range: [-76.8, 76.8] 29 | z_range: [-3.0, 3.0] 30 | resolution: 0.3 31 | height: 512 32 | width: 512 33 | pillars: 34 | num_pillars: 24000 35 | num_points_per_pillar: 100 36 | num_features_per_point: 10 37 | min_level: 1 38 | max_level: 3 39 | anchors: 40 | - length: 15.752693 41 | width: 6.930973 42 | anchor_labeler: 43 | match_threshold: 0.6 44 | unmatched_threshold: 0.45 45 | featurizer: 46 | num_blocks: 1 47 | num_channels: 64 # C 48 | backbone: 49 | min_level: 1 50 | max_level: 3 51 | num_convs: 6 52 | detection_generator: 53 | pre_nms_score_threshold: 0.05 54 | nms_iou_threshold: 0.5 55 | max_num_detections: 200 56 | train_data: 57 | global_batch_size: 4 58 | dtype: 'float32' 59 | shuffle_buffer_size: 10 60 | prefetch_buffer_size: 10 61 | validation_data: 62 | global_batch_size: 2 63 | dtype: 'float32' 64 | shuffle_buffer_size: 10 65 | prefetch_buffer_size: 10 66 | init_checkpoint: null 67 | use_wod_metrics: true 68 | trainer: 69 | train_steps: 2 70 | validation_steps: 2 71 | steps_per_loop: 2 72 | validation_interval: 2 73 | summary_interval: 2 74 | checkpoint_interval: 2 75 | optimizer_config: 76 | optimizer: 77 | type: 'sgd' 78 | sgd: 79 | momentum: 0.9 80 | global_clipnorm: 10.0 81 | learning_rate: 82 | type: 'cosine' 83 | cosine: 84 | decay_steps: 2 85 | initial_learning_rate: 0.0032 86 | warmup: 87 | type: 'linear' 88 | linear: 89 | warmup_learning_rate: 0.00032 90 | warmup_steps: 2 91 | -------------------------------------------------------------------------------- /tf_vision/pointpillars/configs/vehicle/pointpillars_3d_baseline_tpu.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2023 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 | # Use this config to train PointPillars baseline on vehicle class. 16 | # experiment type: pointpillars_baseline 17 | # strategy: train on TPU pod 32 cores, evaluate on 8 V100 GPUs 18 | # mAP: 0.45 19 | # mAPH: 0.44 20 | # duraing: 16 mins/epoch, 15 hrs/50 epochs 21 | runtime: 22 | distribution_strategy: 'tpu' 23 | mixed_precision_dtype: 'float32' 24 | task: 25 | model: 26 | classes: 'vehicle' 27 | num_classes: 2 28 | image: 29 | x_range: [-76.8, 76.8] 30 | y_range: [-76.8, 76.8] 31 | z_range: [-3.0, 3.0] 32 | resolution: 0.3 33 | height: 512 34 | width: 512 35 | pillars: 36 | num_pillars: 24000 37 | num_points_per_pillar: 100 38 | num_features_per_point: 10 39 | min_level: 1 40 | max_level: 1 41 | anchors: 42 | - length: 15.752693 43 | width: 6.930973 44 | anchor_labeler: 45 | match_threshold: 0.6 46 | unmatched_threshold: 0.45 47 | featurizer: 48 | num_blocks: 1 49 | num_channels: 64 # C 50 | backbone: 51 | min_level: 1 52 | max_level: 3 53 | num_convs: 6 54 | detection_generator: 55 | pre_nms_score_threshold: 0.05 56 | nms_iou_threshold: 0.5 57 | max_num_detections: 200 58 | train_data: 59 | global_batch_size: 64 # 2 * 32, 2 per core, 4x4 df (4 workers, 8 cores per worker) 60 | dtype: 'float32' 61 | shuffle_buffer_size: 256 62 | prefetch_buffer_size: 256 63 | validation_data: 64 | global_batch_size: 32 # 4 * 8 65 | dtype: 'float32' 66 | shuffle_buffer_size: 256 67 | prefetch_buffer_size: 256 68 | init_checkpoint: null 69 | use_wod_metrics: true 70 | trainer: 71 | # (158081 / 64) * 50 = 2470 * 50 72 | train_steps: 123500 73 | # 39987 / 32 74 | validation_steps: 1250 75 | validation_interval: 2470 76 | steps_per_loop: 2470 77 | summary_interval: 2470 78 | checkpoint_interval: 2470 79 | optimizer_config: 80 | optimizer: 81 | type: 'sgd' 82 | sgd: 83 | momentum: 0.9 84 | global_clipnorm: 10.0 85 | learning_rate: 86 | type: 'cosine' 87 | cosine: 88 | decay_steps: 123500 89 | initial_learning_rate: 0.0016 90 | warmup: 91 | type: 'linear' 92 | linear: 93 | warmup_learning_rate: 0.00016 94 | warmup_steps: 2470 # 1 epoch 95 | -------------------------------------------------------------------------------- /tf_vision/pointpillars/dataloaders/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/pointpillars/dataloaders/__init__.py -------------------------------------------------------------------------------- /tf_vision/pointpillars/modeling/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/pointpillars/modeling/__init__.py -------------------------------------------------------------------------------- /tf_vision/pointpillars/registry_imports.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 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 | """All necessary imports for registration. 16 | 17 | Custom models, task, configs, etc need to be imported to registry so they can be 18 | picked up by the trainer. They can be included in this file so you do not need 19 | to handle each file separately. 20 | """ 21 | 22 | # pylint: disable=unused-import 23 | from tf_vision.pointpillars.configs import pointpillars as cfg 24 | from tf_vision.pointpillars.tasks import pointpillars as task 25 | -------------------------------------------------------------------------------- /tf_vision/pointpillars/tasks/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/pointpillars/tasks/__init__.py -------------------------------------------------------------------------------- /tf_vision/pointpillars/tools/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/pointpillars/tools/__init__.py -------------------------------------------------------------------------------- /tf_vision/pointpillars/tools/export_model.py: -------------------------------------------------------------------------------- 1 | # Copyright 2023 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 | """A script to export PointPillars model.""" 16 | 17 | from absl import app 18 | from absl import flags 19 | from absl import logging 20 | 21 | from official.core import exp_factory 22 | from official.modeling import hyperparams 23 | from tf_vision.pointpillars import registry_imports # pylint: disable=unused-import 24 | from tf_vision.pointpillars.utils import model_exporter 25 | 26 | _EXPERIMENT = flags.DEFINE_string( 27 | 'experiment', None, 'experiment type, e.g. retinanet_resnetfpn_coco') 28 | _EXPORT_DIR = flags.DEFINE_string('export_dir', None, 'The export directory.') 29 | _CHECKPOINT_PATH = flags.DEFINE_string('checkpoint_path', None, 30 | 'Checkpoint path.') 31 | _BATCH_SIZE = flags.DEFINE_integer('batch_size', None, 'Batch size.') 32 | _CONFIG_FILE = flags.DEFINE_string( 33 | 'config_file', 34 | default=None, 35 | help='YAML/JSON files which specifies overrides.') 36 | _TEST_INFERENCE = flags.DEFINE_boolean( 37 | 'test_inference', 38 | default=False, 39 | help='True if want to load saved model and run inference.') 40 | 41 | 42 | def main(_): 43 | params = exp_factory.get_exp_config(_EXPERIMENT.value) 44 | if _CONFIG_FILE.value: 45 | params = hyperparams.override_params_dict( 46 | params, _CONFIG_FILE.value, is_strict=True) 47 | params.validate() 48 | params.lock() 49 | 50 | model_exporter.export_inference_graph( 51 | batch_size=_BATCH_SIZE.value, 52 | params=params, 53 | checkpoint_path=_CHECKPOINT_PATH.value, 54 | export_dir=_EXPORT_DIR.value) 55 | logging.info('Successfully exported model to %s', _EXPORT_DIR.value) 56 | 57 | if _TEST_INFERENCE.value: 58 | predict_fn = model_exporter.load_model_predict_fn(_EXPORT_DIR.value) 59 | pillars, indices = model_exporter.random_input_tensors( 60 | batch_size=_BATCH_SIZE.value, params=params, 61 | ) 62 | _ = predict_fn(pillars=pillars, indices=indices) 63 | logging.info('Successfully test model inference') 64 | 65 | if __name__ == '__main__': 66 | app.run(main) 67 | -------------------------------------------------------------------------------- /tf_vision/pointpillars/utils/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/pointpillars/utils/__init__.py -------------------------------------------------------------------------------- /tf_vision/registry_imports.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """All necessary imports for registration.""" 16 | 17 | # pylint: disable=unused-import 18 | from tf_vision import configs 19 | from tf_vision import modeling 20 | from tf_vision import tasks 21 | from tf_vision.pointpillars import registry_imports as pointpillars_imports 22 | from official.vision import beta 23 | -------------------------------------------------------------------------------- /tf_vision/search_spaces/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Search spaces package definition.""" 16 | 17 | from tf_vision.search_spaces import tunable_pointpillars_search_space 18 | -------------------------------------------------------------------------------- /tf_vision/tasks/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Tasks package definition.""" 16 | 17 | from tf_vision.tasks import pointpillars 18 | from tf_vision.tasks import retinanet 19 | from tf_vision.tasks import semantic_segmentation 20 | -------------------------------------------------------------------------------- /tf_vision/tasks/semantic_segmentation.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """Image segmentation task definition.""" 16 | from typing import Optional 17 | 18 | from tf_vision.configs import semantic_segmentation as semantic_segmentation_cfg 19 | from tf_vision.dataloaders import segmentation_input 20 | import tensorflow as tf 21 | 22 | from official.common import dataset_fn 23 | from official.core import task_factory 24 | from official.vision.beta.configs import semantic_segmentation as base_semantic_segmentation_cfg 25 | from official.vision.beta.dataloaders import input_reader_factory 26 | from official.vision.beta.dataloaders import segmentation_input as base_segmentation_input 27 | from official.vision.beta.dataloaders import tfds_factory 28 | from official.vision.beta.tasks import semantic_segmentation as base_semantic_segmentation_task 29 | 30 | 31 | @task_factory.register_task_cls( 32 | semantic_segmentation_cfg.SemanticSegmentationTask) 33 | class SemanticSegmentationTask( 34 | base_semantic_segmentation_task.SemanticSegmentationTask): 35 | """A task for semantic segmentation.""" 36 | 37 | def build_inputs(self, 38 | params, 39 | input_context = None): 40 | """Builds classification input.""" 41 | 42 | ignore_label = self.task_config.losses.ignore_label 43 | 44 | if params.tfds_name: 45 | decoder = tfds_factory.get_segmentation_decoder(params.tfds_name) 46 | else: 47 | decoder = base_segmentation_input.Decoder() 48 | 49 | parser = segmentation_input.Parser( 50 | aug_policy=params.aug_policy, 51 | output_size=params.output_size, 52 | crop_size=params.crop_size, 53 | ignore_label=ignore_label, 54 | resize_eval_groundtruth=params.resize_eval_groundtruth, 55 | groundtruth_padded_size=params.groundtruth_padded_size, 56 | aug_scale_min=params.aug_scale_min, 57 | aug_scale_max=params.aug_scale_max, 58 | aug_rand_hflip=params.aug_rand_hflip, 59 | dtype=params.dtype) 60 | 61 | reader = input_reader_factory.input_reader_generator( 62 | params, 63 | dataset_fn=dataset_fn.pick_dataset_fn(params.file_type), 64 | decoder_fn=decoder.decode, 65 | parser_fn=parser.parse_fn(params.is_training)) 66 | 67 | return reader.read(input_context=input_context) 68 | -------------------------------------------------------------------------------- /tf_vision/test_files/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/tf_vision/test_files/__init__.py -------------------------------------------------------------------------------- /tf_vision/test_files/fast_mnasnet_detection_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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 | runtime: 15 | mixed_precision_dtype: 'float16' 16 | task: 17 | model: 18 | backbone: 19 | type: 'tunable_mnasnet' 20 | decoder: 21 | type: 'fpn' 22 | detection_generator: 23 | # The maximum number of bboxes in one image. 24 | max_num_detections: 100 25 | head: 26 | num_filters: 8 27 | num_convs: 1 28 | anchor: 29 | # The intermediate scales added on each level. 30 | # For instance, num_scales=2 adds one additional intermediate anchor scales 31 | # [2^0, 2^0.5] on each level. 32 | num_scales: 3 33 | aspect_ratios: [1.0, 2.0, 0.5] 34 | # A float number representing the scale of size of the base 35 | # anchor to the feature stride 2^level. 36 | anchor_size: 4.0 37 | num_classes: 91 38 | input_size: [32, 32, 3] 39 | max_level: 4 40 | min_level: 3 41 | train_data: 42 | dtype: 'float16' 43 | global_batch_size: 1 44 | is_training: true 45 | shuffle_buffer_size: 100 46 | cache: true 47 | parser: 48 | aug_scale_max: 1.2 49 | aug_scale_min: 0.8 50 | validation_data: 51 | dtype: 'float16' 52 | global_batch_size: 1 53 | is_training: false 54 | cache: true 55 | trainer: 56 | train_steps: 1 57 | steps_per_loop: 1 58 | validation_steps: 1 59 | validation_interval: 1 60 | summary_interval: 1 61 | checkpoint_interval: 1 62 | -------------------------------------------------------------------------------- /tf_vision/test_files/fast_nas_classification_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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 | runtime: 15 | mixed_precision_dtype: 'float16' 16 | task: 17 | model: 18 | backbone: 19 | type: 'tunable_mnasnet' 20 | input_size: [224, 224, 3] 21 | train_data: 22 | dtype: 'float16' 23 | global_batch_size: 1 24 | is_training: true 25 | shuffle_buffer_size: 100 26 | cache: true 27 | validation_data: 28 | dtype: 'float16' 29 | global_batch_size: 1 30 | is_training: false 31 | cache: true 32 | trainer: 33 | train_steps: 1 34 | steps_per_loop: 1 35 | validation_steps: 1 36 | validation_interval: 1 37 | summary_interval: 1 38 | checkpoint_interval: 1 39 | -------------------------------------------------------------------------------- /tf_vision/test_files/fast_nas_detection_nasfpn_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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 | # ---------- Search NAS-FPN nodes based on NAS-FPN paper ---------- 15 | runtime: 16 | mixed_precision_dtype: 'float16' 17 | task: 18 | model: 19 | decoder: 20 | type: 'tunable_nasfpn' 21 | tunable_nasfpn: 22 | num_filters: 32 23 | num_repeats: 1 24 | use_separable_conv: false 25 | input_size: [128, 128, 3] 26 | max_level: 7 27 | min_level: 3 28 | train_data: 29 | dtype: 'float16' 30 | global_batch_size: 1 31 | is_training: true 32 | shuffle_buffer_size: 100 33 | cache: true 34 | parser: 35 | aug_scale_max: 1.2 36 | aug_scale_min: 0.8 37 | validation_data: 38 | dtype: 'float16' 39 | global_batch_size: 1 40 | is_training: false 41 | cache: true 42 | trainer: 43 | train_steps: 1 44 | steps_per_loop: 1 45 | validation_steps: 1 46 | validation_interval: 1 47 | summary_interval: 1 48 | checkpoint_interval: 1 49 | optimizer_config: 50 | learning_rate: 51 | stepwise: 52 | boundaries: [13864] 53 | values: [0.08, 0.008] 54 | type: 'stepwise' 55 | warmup: 56 | linear: 57 | warmup_learning_rate: 0.0067 58 | warmup_steps: 0 59 | -------------------------------------------------------------------------------- /tf_vision/test_files/fast_nas_detection_spinenet_mbconv_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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 | # ---------- Search NAS-FPN nodes based on NAS-FPN paper ---------- 15 | 16 | runtime: 17 | mixed_precision_dtype: 'float16' 18 | task: 19 | model: 20 | backbone: 21 | tunable_spinenet_mbconv: 22 | # The multiplier of the number of filters for each block. 23 | filter_size_scale: 0.25 24 | # The number of filters of the output endpoints. 25 | endpoints_num_filters: 64 26 | type: 'tunable_spinenet_mbconv' 27 | decoder: 28 | type: 'identity' 29 | input_size: [32, 32, 3] 30 | max_level: 4 31 | min_level: 3 32 | train_data: 33 | dtype: 'float16' 34 | global_batch_size: 1 35 | is_training: true 36 | shuffle_buffer_size: 100 37 | cache: true 38 | parser: 39 | aug_scale_max: 1.2 40 | aug_scale_min: 0.8 41 | validation_data: 42 | dtype: 'float16' 43 | global_batch_size: 1 44 | is_training: false 45 | cache: true 46 | trainer: 47 | train_steps: 1 48 | steps_per_loop: 1 49 | validation_steps: 1 50 | validation_interval: 1 51 | summary_interval: 1 52 | checkpoint_interval: 1 53 | optimizer_config: 54 | learning_rate: 55 | stepwise: 56 | boundaries: [13864] 57 | values: [0.08, 0.008] 58 | type: 'stepwise' 59 | warmup: 60 | linear: 61 | warmup_learning_rate: 0.0067 62 | warmup_steps: 0 63 | 64 | 65 | -------------------------------------------------------------------------------- /tf_vision/test_files/fast_nas_detection_spinenet_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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 | runtime: 15 | mixed_precision_dtype: 'float16' 16 | task: 17 | model: 18 | backbone: 19 | tunable_spinenet: 20 | model_id: '49S' 21 | # The multiplier of the number of filters for each block. 22 | filter_size_scale: 0.2 23 | # The scaling factor to scale feature dimension before resolution resampling. 24 | resample_alpha: 0.2 25 | # The number of filters of the output endpoints. 26 | endpoints_num_filters: 4 27 | block_repeats: 1 28 | type: 'tunable_spinenet' 29 | decoder: 30 | type: 'identity' 31 | input_size: [16, 16, 3] 32 | max_level: 4 33 | min_level: 3 34 | train_data: 35 | dtype: 'float16' 36 | global_batch_size: 1 37 | is_training: true 38 | shuffle_buffer_size: 100 39 | cache: true 40 | parser: 41 | aug_scale_max: 1.2 42 | aug_scale_min: 0.8 43 | validation_data: 44 | dtype: 'float16' 45 | global_batch_size: 1 46 | is_training: false 47 | cache: true 48 | trainer: 49 | train_steps: 1 50 | steps_per_loop: 1 51 | validation_steps: 1 52 | validation_interval: 1 53 | summary_interval: 1 54 | checkpoint_interval: 1 55 | -------------------------------------------------------------------------------- /tf_vision/test_files/fast_nas_segmentation_aug_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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 | runtime: 15 | mixed_precision_dtype: 'float16' 16 | task: 17 | model: 18 | backbone: 19 | efficientnet: 20 | model_id: 'b0' 21 | type: 'efficientnet' 22 | decoder: 23 | type: 'fpn' 24 | input_size: [null, null, 3] 25 | max_level: 7 26 | min_level: 3 27 | train_data: 28 | output_size: [256, 256] 29 | dtype: 'float16' 30 | global_batch_size: 2 31 | is_training: true 32 | shuffle_buffer_size: 100 33 | cache: true 34 | validation_data: 35 | output_size: [256, 256] 36 | dtype: 'float16' 37 | global_batch_size: 1 38 | is_training: false 39 | cache: true 40 | trainer: 41 | train_steps: 1 42 | steps_per_loop: 1 43 | validation_steps: 1 44 | validation_interval: 1 45 | summary_interval: 1 46 | checkpoint_interval: 1 47 | optimizer_config: 48 | learning_rate: 49 | stepwise: 50 | # Decay at end of epoch 8. 51 | boundaries: [13864] 52 | values: [0.08, 0.008] 53 | type: 'stepwise' 54 | warmup: 55 | linear: 56 | # Warm up in 1 epoch. 57 | warmup_steps: 1733 58 | -------------------------------------------------------------------------------- /tf_vision/test_files/fast_nas_segmentation_nasfpn_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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 | runtime: 15 | mixed_precision_dtype: 'float16' 16 | task: 17 | model: 18 | backbone: 19 | efficientnet: 20 | model_id: 'b0' 21 | type: 'efficientnet' 22 | decoder: 23 | tunable_nasfpn: 24 | num_filters: 256 25 | num_repeats: 3 26 | use_separable_conv: false 27 | type: 'tunable_nasfpn' 28 | input_size: [null, null, 3] 29 | max_level: 7 30 | min_level: 3 31 | train_data: 32 | output_size: [256, 256] 33 | dtype: 'float16' 34 | global_batch_size: 2 35 | is_training: true 36 | shuffle_buffer_size: 100 37 | cache: true 38 | validation_data: 39 | output_size: [256, 256] 40 | dtype: 'float16' 41 | global_batch_size: 1 42 | is_training: false 43 | cache: true 44 | trainer: 45 | train_steps: 1 46 | steps_per_loop: 1 47 | validation_steps: 1 48 | validation_interval: 1 49 | summary_interval: 1 50 | checkpoint_interval: 1 51 | optimizer_config: 52 | learning_rate: 53 | stepwise: 54 | # Decay at end of epoch 8. 55 | boundaries: [13864] 56 | values: [0.08, 0.008] 57 | type: 'stepwise' 58 | warmup: 59 | linear: 60 | # Warm up in 1 epoch. 61 | warmup_steps: 1733 62 | -------------------------------------------------------------------------------- /tf_vision/test_files/fast_nas_segmentation_spinenet_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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 | runtime: 15 | mixed_precision_dtype: 'float16' 16 | task: 17 | model: 18 | backbone: 19 | tunable_spinenet: 20 | # The multiplier of the number of filters for each block. 21 | filter_size_scale: 0.25 22 | # The scaling factor to scale feature dimension before resolution resampling. 23 | resample_alpha: 0.25 24 | # The number of filters of the output endpoints. 25 | endpoints_num_filters: 64 26 | type: 'tunable_spinenet' 27 | decoder: 28 | type: 'identity' 29 | input_size: [null, null, 3] 30 | max_level: 7 31 | min_level: 3 32 | train_data: 33 | output_size: [256, 256] 34 | dtype: 'float16' 35 | global_batch_size: 2 36 | is_training: true 37 | shuffle_buffer_size: 100 38 | cache: true 39 | validation_data: 40 | output_size: [256, 256] 41 | dtype: 'float16' 42 | global_batch_size: 1 43 | is_training: false 44 | cache: true 45 | trainer: 46 | train_steps: 1 47 | steps_per_loop: 1 48 | validation_steps: 1 49 | validation_interval: 1 50 | summary_interval: 1 51 | checkpoint_interval: 1 52 | optimizer_config: 53 | learning_rate: 54 | stepwise: 55 | # Decay at end of epoch 8. 56 | boundaries: [13864] 57 | values: [0.08, 0.008] 58 | type: 'stepwise' 59 | warmup: 60 | linear: 61 | # Warm up in 1 epoch. 62 | warmup_steps: 1733 63 | -------------------------------------------------------------------------------- /tf_vision/test_files/fast_pointpillars_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | runtime: 16 | distribution_strategy: 'mirrored' 17 | mixed_precision_dtype: 'float32' 18 | loss_scale: 'dynamic' 19 | task: 20 | model: 21 | classes: 'vehicle' 22 | num_classes: 2 23 | image: 24 | x_range: [-76.8, 76.8] 25 | y_range: [-76.8, 76.8] 26 | z_range: [-3.0, 3.0] 27 | resolution: 0.3 28 | height: 512 29 | width: 512 30 | pillars: 31 | num_pillars: 24000 32 | num_points_per_pillar: 100 33 | num_features_per_point: 10 34 | # 1 [256, 256], 2 [128, 128], 3 [64, 64] 35 | min_level: 1 36 | max_level: 3 37 | anchors: 38 | - length: 15.752693 39 | width: 6.930973 40 | anchor_labeler: 41 | match_threshold: 0.6 42 | unmatched_threshold: 0.45 43 | detection_generator: 44 | pre_nms_score_threshold: 0.05 45 | nms_iou_threshold: 0.5 46 | max_num_detections: 100 47 | train_data: 48 | global_batch_size: 4 49 | dtype: 'float32' 50 | shuffle_buffer_size: 10 51 | prefetch_buffer_size: 10 52 | validation_data: 53 | global_batch_size: 4 54 | dtype: 'float32' 55 | shuffle_buffer_size: 10 56 | prefetch_buffer_size: 10 57 | init_checkpoint: null 58 | use_wod_metrics: true 59 | trainer: 60 | train_steps: 4 61 | validation_steps: 2 62 | steps_per_loop: 2 63 | validation_interval: 2 64 | summary_interval: 2 65 | checkpoint_interval: 2 66 | optimizer_config: 67 | optimizer: 68 | type: 'sgd' 69 | sgd: 70 | momentum: 0.9 71 | global_clipnorm: 10.0 72 | learning_rate: 73 | type: 'cosine' 74 | cosine: 75 | decay_steps: 4 76 | initial_learning_rate: 0.0032 77 | warmup: 78 | type: 'linear' 79 | linear: 80 | warmup_learning_rate: 0.00032 81 | warmup_steps: 2 82 | -------------------------------------------------------------------------------- /tf_vision/train.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 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 | """TensorFlow Model Garden Vision training driver.""" 16 | 17 | from absl import app 18 | from tf_vision import registry_imports # pylint: disable=unused-import 19 | 20 | from official.common import flags as tfm_flags 21 | from official.vision.beta import train 22 | 23 | if __name__ == '__main__': 24 | tfm_flags.define_flags() 25 | app.run(train.main) 26 | -------------------------------------------------------------------------------- /third_party/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/__init__.py -------------------------------------------------------------------------------- /third_party/medical_3d/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/medical_3d/__init__.py -------------------------------------------------------------------------------- /third_party/medical_3d/configs/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/medical_3d/configs/__init__.py -------------------------------------------------------------------------------- /third_party/medical_3d/configs/fast_unet_3d_nasfpn_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | 16 | # Unet Encoder related. 17 | features: [1, 2, 4, 8] 18 | 19 | # NAS-FPN related. 20 | # NOTE: If you change min-level and max-level here, then change in the search-space definition too. 21 | # NOTE: For segmentation, min-level should be set to 1 to use the top-most layer. 22 | min_level: 1 23 | max_level: 4 24 | num_filters: 2 25 | num_repeats: 1 26 | 27 | -------------------------------------------------------------------------------- /third_party/medical_3d/configs/fast_unet_3d_search_for_testing.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | 16 | features: [1, 2, 4, 8] 17 | -------------------------------------------------------------------------------- /third_party/medical_3d/configs/unet_3d_nasfpn_finetune.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | 16 | # Unet Encoder related. 17 | features: [32, 64, 128, 256] 18 | 19 | # NAS-FPN related. 20 | # NOTE: If you change min-level and max-level here, then change in the search-space definition too. 21 | # NOTE: For segmentation, min-level should be set to 1 to use the top-most layer. 22 | min_level: 1 23 | max_level: 4 24 | num_filters: 64 25 | num_repeats: 2 26 | 27 | -------------------------------------------------------------------------------- /third_party/medical_3d/configs/unet_3d_nasfpn_search.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | 16 | # Unet Encoder related. 17 | features: [32, 64, 128, 256] 18 | 19 | # NAS-FPN related. 20 | # NOTE: If you change min-level and max-level here, then change in the search-space definition too. 21 | # NOTE: For segmentation, min-level should be set to 1 to use the top-most layer. 22 | min_level: 1 23 | max_level: 4 24 | num_filters: 16 25 | num_repeats: 2 26 | 27 | -------------------------------------------------------------------------------- /third_party/medical_3d/configs/unet_3d_search.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | 16 | features: [32, 64, 128, 256] 17 | -------------------------------------------------------------------------------- /third_party/medical_3d/medical_3d.Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Google LLC 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.\n", 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 | # Install the latest version of pytorch 16 | FROM gcr.io/cloud-ml-public/training/pytorch-gpu.1-6 17 | WORKDIR /root 18 | 19 | # Installs pandas, google-cloud-storage and tensorflow. 20 | RUN pip install --upgrade pip==21.3.1 21 | 22 | # Install tensorflow to use its tf.gfile lib to access objects in GCS. 23 | # TODO: remove the dependency on tensorflow and use fsspec instead. 24 | RUN pip install pandas==1.3.4 google-cloud-storage==1.42.3 tensorflow==1.15 25 | RUN pip install pyglove==0.1.0 26 | 27 | # Install Monai. 28 | RUN pip install "monai[all]==0.5.2" 29 | RUN pip install -q matplotlib==3.4.3 30 | 31 | RUN pip install protobuf==3.20.* 32 | 33 | RUN mkdir /root/training 34 | COPY . /root/training/ 35 | ENV PATH="/root/training/:${PATH}" 36 | 37 | WORKDIR /root/training 38 | RUN mv third_party/medical_3d/medical_3d_main.py medical_3d.py 39 | ENTRYPOINT ["python", "medical_3d.py"] 40 | -------------------------------------------------------------------------------- /third_party/medical_3d/static_unet.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 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 | """Static Unet model.""" 16 | 17 | from third_party.medical_3d import basic_unet 18 | 19 | 20 | # https://github.com/Project-MONAI/MONAI/blob/2db93d8d050feb2e245de0b9189b813693012b96/monai/networks/nets/basic_unet.py 21 | def unet(params): 22 | """Returns a Unet model.""" 23 | return basic_unet.BasicUNet( 24 | dimensions=3, 25 | in_channels=params['in_channels'], 26 | out_channels=params['out_channels'], 27 | features=params['features'], 28 | ) 29 | -------------------------------------------------------------------------------- /third_party/medical_3d/unet_encoder.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020 - 2021 MONAI Consortium 2 | # Licensed under the Apache License, Version 2.0 (the "License"); 3 | # you may not use this file except in compliance with the License. 4 | # You may obtain a copy of the License at 5 | # http://www.apache.org/licenses/LICENSE-2.0 6 | # Unless required by applicable law or agreed to in writing, software 7 | # distributed under the License is distributed on an "AS IS" BASIS, 8 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 9 | # See the License for the specific language governing permissions and 10 | # limitations under the License. 11 | """Unet Encoder derived from MONAI BasicUnet.""" 12 | 13 | from third_party.medical_3d import basic_unet 14 | import torch.nn as nn 15 | 16 | 17 | class UNetEncoder(nn.Module): 18 | """Unet-Encoder implementation.""" 19 | 20 | def __init__( 21 | self, 22 | dimensions, 23 | in_channels, 24 | features, 25 | act=("LeakyReLU", { 26 | "negative_slope": 0.1, 27 | "inplace": True 28 | }), 29 | norm=("instance", { 30 | "affine": True 31 | }), 32 | dropout=0.0 33 | ): 34 | """A UNet-Encoder implementation with 1D/2D/3D supports. 35 | 36 | Args: 37 | dimensions: number of spatial dimensions. Defaults to 3 for spatial 38 | 3D inputs. 39 | in_channels: number of input channels. Defaults to 1. 40 | features: six integers as numbers of features. Defaults to ``(32, 41 | 32, 64, 128, 256)``, - the five values correspond to the 42 | five-level encoder feature sizes. 43 | act: activation type and arguments. Defaults to LeakyReLU. 44 | norm: feature normalization type and arguments. Defaults to instance 45 | norm. 46 | dropout: dropout ratio. Defaults to no dropout. 47 | """ 48 | super().__init__() 49 | 50 | self.features = list(features) 51 | self.num_levels = len(features) 52 | if self.num_levels < 2: 53 | raise ValueError("The Unet should atleast have a depth of two.") 54 | fea = list(features) 55 | print(f"BasicUNet features: {fea}.") 56 | 57 | self.down_ops = basic_unet.build_down_ops( 58 | dimensions=dimensions, 59 | in_channels=in_channels, 60 | features=fea, 61 | act=act, 62 | norm=norm, 63 | dropout=dropout, 64 | num_levels=self.num_levels) 65 | 66 | def get_channels(self): 67 | return self.features 68 | 69 | def forward(self, x): 70 | """Returns a list of features at every level starting with topmost level.""" 71 | # Down path. 72 | down_features = [] 73 | for level in range(self.num_levels): 74 | x = self.down_ops[level](x) 75 | down_features.append(x) 76 | return down_features 77 | -------------------------------------------------------------------------------- /third_party/tutorial/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/__init__.py -------------------------------------------------------------------------------- /third_party/tutorial/dummy_input.txt: -------------------------------------------------------------------------------- 1 | Hello world. 2 | -------------------------------------------------------------------------------- /third_party/tutorial/images/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/__init__.py -------------------------------------------------------------------------------- /third_party/tutorial/images/cloud_shell_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/cloud_shell_open.png -------------------------------------------------------------------------------- /third_party/tutorial/images/create_bucket.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/create_bucket.png -------------------------------------------------------------------------------- /third_party/tutorial/images/create_folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/create_folder.png -------------------------------------------------------------------------------- /third_party/tutorial/images/device_latency_search_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/device_latency_search_ui.png -------------------------------------------------------------------------------- /third_party/tutorial/images/download_log_drop_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/download_log_drop_down.png -------------------------------------------------------------------------------- /third_party/tutorial/images/flops_search_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/flops_search_analysis.png -------------------------------------------------------------------------------- /third_party/tutorial/images/flops_search_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/flops_search_ui.png -------------------------------------------------------------------------------- /third_party/tutorial/images/gcp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/gcp.png -------------------------------------------------------------------------------- /third_party/tutorial/images/gcp_storage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/gcp_storage.png -------------------------------------------------------------------------------- /third_party/tutorial/images/job_ui_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/job_ui_page.png -------------------------------------------------------------------------------- /third_party/tutorial/images/open_tensorboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/open_tensorboard.png -------------------------------------------------------------------------------- /third_party/tutorial/images/open_tensorboard_alternative.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/open_tensorboard_alternative.png -------------------------------------------------------------------------------- /third_party/tutorial/images/tensorboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/tensorboard.png -------------------------------------------------------------------------------- /third_party/tutorial/images/test_search_job_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/test_search_job_ui.png -------------------------------------------------------------------------------- /third_party/tutorial/images/test_search_job_ui_finished.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/test_search_job_ui_finished.png -------------------------------------------------------------------------------- /third_party/tutorial/images/training_input_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/training_input_ui.png -------------------------------------------------------------------------------- /third_party/tutorial/images/ui_page_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/ui_page_analysis.png -------------------------------------------------------------------------------- /third_party/tutorial/images/view_logs_drop_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/images/view_logs_drop_down.png -------------------------------------------------------------------------------- /third_party/tutorial/tutorial1.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:2.7.0-gpu 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | 5 | # This is added to fix docker build error related to Nvidia key update. 6 | RUN rm -f /etc/apt/sources.list.d/cuda.list 7 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 8 | 9 | # Install google cloud SDK 10 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ 11 | | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ 12 | | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y 13 | 14 | RUN pip install --upgrade pip 15 | RUN pip install Pillow==8.4.0 && \ 16 | pip install pyglove==0.1.0 && \ 17 | pip install google-cloud-storage==2.6.0 && \ 18 | pip install protobuf==3.20.* 19 | 20 | # Make sure gsutil will use the default service account 21 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 22 | 23 | RUN mkdir /root/training 24 | COPY . /root/training/ 25 | ENV PATH="/root/training/:${PATH}" 26 | 27 | WORKDIR /root/training 28 | RUN mv third_party/tutorial/tutorial1_mnist_search.py tutorial1_mnist_search.py 29 | ENTRYPOINT ["python", "tutorial1_mnist_search.py"] 30 | -------------------------------------------------------------------------------- /third_party/tutorial/tutorial2.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:2.7.0-gpu 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | 5 | # This is added to fix docker build error related to Nvidia key update. 6 | RUN rm -f /etc/apt/sources.list.d/cuda.list 7 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 8 | 9 | # Install google cloud SDK 10 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ 11 | | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ 12 | | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y 13 | 14 | RUN pip install --upgrade pip 15 | RUN pip install Pillow==8.4.0 && \ 16 | pip install pyglove==0.1.0 && \ 17 | pip install google-cloud-storage==2.6.0 && \ 18 | pip install protobuf==3.20.* 19 | 20 | # Make sure gsutil will use the default service account 21 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 22 | 23 | RUN mkdir /root/training 24 | COPY . /root/training/ 25 | ENV PATH="/root/training/:${PATH}" 26 | 27 | WORKDIR /root/training 28 | RUN mv third_party/tutorial/tutorial2_search_spaces.py tutorial2_search_spaces.py 29 | ENTRYPOINT ["python", "tutorial2_search_spaces.py"] 30 | -------------------------------------------------------------------------------- /third_party/tutorial/tutorial3.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:2.7.0-gpu 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | 5 | # This is added to fix docker build error related to Nvidia key update. 6 | RUN rm -f /etc/apt/sources.list.d/cuda.list 7 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 8 | 9 | # Install google cloud SDK 10 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ 11 | | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ 12 | | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y 13 | 14 | RUN pip install --upgrade pip 15 | RUN pip install Pillow==8.4.0 && \ 16 | pip install pyglove==0.1.0 && \ 17 | pip install google-cloud-storage==2.6.0 && \ 18 | pip install protobuf==3.20.* 19 | 20 | # Make sure gsutil will use the default service account 21 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 22 | 23 | RUN mkdir /root/training 24 | COPY . /root/training/ 25 | ENV PATH="/root/training/:${PATH}" 26 | 27 | WORKDIR /root/training 28 | RUN mv third_party/tutorial/tutorial3_mnist_search.py tutorial3_mnist_search.py 29 | ENTRYPOINT ["python", "tutorial3_mnist_search.py"] 30 | -------------------------------------------------------------------------------- /third_party/tutorial/tutorial4.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:2.7.0-gpu 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | 5 | # This is added to fix docker build error related to Nvidia key update. 6 | RUN rm -f /etc/apt/sources.list.d/cuda.list 7 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 8 | 9 | # Install google cloud SDK 10 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" \ 11 | | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && curl https://packages.cloud.google.com/apt/doc/apt-key.gpg \ 12 | | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && apt-get update -y && apt-get install google-cloud-sdk -y 13 | 14 | RUN pip install --upgrade pip 15 | RUN pip install Pillow==8.4.0 && \ 16 | pip install pyglove==0.1.0 && \ 17 | pip install google-cloud-storage==2.6.0 && \ 18 | pip install protobuf==3.20.* 19 | 20 | # Make sure gsutil will use the default service account 21 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 22 | 23 | RUN mkdir /root/training 24 | COPY . /root/training/ 25 | ENV PATH="/root/training/:${PATH}" 26 | 27 | WORKDIR /root/training 28 | RUN mv third_party/tutorial/tutorial4_mnist_search_with_latency_constraint.py tutorial4_mnist_search_with_latency_constraint.py 29 | ENTRYPOINT ["python", "tutorial4_mnist_search_with_latency_constraint.py"] 30 | -------------------------------------------------------------------------------- /third_party/tutorial/tutorial4_latency_calculation.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM tensorflow/tensorflow:2.6.0-gpu 2 | 3 | ENV DEBIAN_FRONTEND=noninteractive 4 | 5 | # This is added to fix docker build error related to Nvidia key update. 6 | RUN rm -f /etc/apt/sources.list.d/cuda.list 7 | RUN curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - 8 | 9 | # Install google-cloud-sdk to enable "gcloud" cli. 10 | # The install command is documented here: 11 | # https://cloud.google.com/sdk/docs/install#deb under step-3. 12 | RUN echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] http://packages.cloud.google.com/apt cloud-sdk main" | \ 13 | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \ 14 | curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | \ 15 | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - && \ 16 | apt-get update -y && apt-get install google-cloud-sdk -y 17 | 18 | RUN pip install --upgrade pip==21.3.1 && \ 19 | pip install Pillow==8.4.0 && \ 20 | pip install fsspec==2021.10.1 && \ 21 | pip install gcsfs==2021.10.1 && \ 22 | pip install pyglove==0.1.0 23 | 24 | # Make sure gsutil will use the default service account 25 | RUN echo '[GoogleCompute]\nservice_account = default' > /etc/boto.cfg 26 | 27 | 28 | RUN mkdir /root/training 29 | COPY . /root/training/ 30 | ENV PATH="/root/training/:${PATH}" 31 | 32 | WORKDIR /root/training 33 | RUN mv third_party/tutorial/tutorial4_latency_computation.py tutorial4_latency_computation.py 34 | ENTRYPOINT ["python", "tutorial4_latency_computation.py"] 35 | -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/__init__.py -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/back_to_job_list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/back_to_job_list.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/cancel_job_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/cancel_job_ui.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/cloud_shell_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/cloud_shell_open.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/custom_latency_setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/custom_latency_setup.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/device_latency_search_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/device_latency_search_ui.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/flops_search_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/flops_search_ui.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/job_ui_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/job_ui_page.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/local_device_latency_search_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/local_device_latency_search_ui.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/model_evaluator_flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/model_evaluator_flow.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/test_search_job_ui_finished.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/test_search_job_ui_finished.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/train_only_job_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/train_only_job_ui.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/training_input_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/training_input_ui.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/ui_page_analysis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/ui_page_analysis.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/vertex_ui_custom_job.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/vertex_ui_custom_job.png -------------------------------------------------------------------------------- /third_party/tutorial/vertex_images/view_logs_drop_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/vertex-ai-nas/206a0b99ae332f9404ab82a7c12eb05c2a3a380c/third_party/tutorial/vertex_images/view_logs_drop_down.png --------------------------------------------------------------------------------