def run(): model_path = "resnet-dogs" img_size = 224 batch_size = 64 train_data, test_data, num_classes = get_data(img_size, batch_size) model = get_model(img_size, num_classes) callbacks = get_callbacks(model_path, GCP_BUCKET) if tfc.remote(): epochs = 500 model.fit( train_data, epochs=epochs, callbacks=callbacks, validation_data=test_data, verbose=2 ) save_path = os.path.join("gs://", GCP_BUCKET, model_path) model.save(save_path) model = tf.keras.models.load_model(save_path) model.evaluate(test_data) tfc.run( requirements_txt="requirements.txt", distribution_strategy="auto", chief_config=tfc.MachineConfig( cpu_cores=8, memory=30, accelerator_type=tfc.AcceleratorType.NVIDIA_TESLA_T4, accelerator_count=2, ), docker_image_bucket_name=GCP_BUCKET, )
def auto_mirrored_strategy(self): return tfc.run( entry_point=os.path.join(self.test_data_path, "mnist_example_using_fit.py"), requirements_txt=os.path.join(self.test_data_path, "requirements.txt"), chief_config=tfc.MachineConfig( cpu_cores=8, memory=30, accelerator_type=tfc.AcceleratorType.NVIDIA_TESLA_K80, accelerator_count=2, ), )
def test_auto_mirrored_strategy(self): tfc.run( entry_point=os.path.join(self.test_data_path, "mnist_example_using_fit.py"), requirements_txt=os.path.join(self.test_data_path, "requirements.txt"), chief_config=tfc.MachineConfig( cpu_cores=8, memory=30, accelerator_type=tfc.AcceleratorType.NVIDIA_TESLA_T4, accelerator_count=2, ), ) self._mock_sys_exit.assert_called_once_with(0)
def auto_mirrored_strategy(self): return tfc.run( entry_point=os.path.join(self.test_data_path, "mnist_example_using_fit.ipynb"), requirements_txt=os.path.join(self.test_data_path, "requirements.txt"), chief_config=tfc.MachineConfig( cpu_cores=8, memory=30, accelerator_type=tfc.AcceleratorType.NVIDIA_TESLA_K80, accelerator_count=2, ), job_labels={ "job": "auto_mirrored_strategy", "team": "on_notebook_tests", }, )
# Copyright 2020 Google LLC. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import tensorflow_cloud as tfc # Automated MirroredStrategy: chief config with multiple GPUs tfc.run( entry_point="tests/testdata/mnist_example_using_fit.ipynb", distribution_strategy="auto", requirements_txt="tests/testdata/requirements.txt", chief_config=tfc.MachineConfig( cpu_cores=8, memory=30, accelerator_type=tfc.AcceleratorType.NVIDIA_TESLA_T4, accelerator_count=2, ), worker_count=0, )