def automl_image_classification_training_job_sample( project: str, location: str, dataset_id: str, display_name: str, ): aiplatform.init(project=project, location=location) dataset = aiplatform.ImageDataset(dataset_id) job = aiplatform.AutoMLImageTrainingJob( display_name=display_name, prediction_type="classification", multi_label=False, model_type="CLOUD", base_model=None, ) model = job.run( dataset=dataset, model_display_name=display_name, training_fraction_split=0.6, validation_fraction_split=0.2, test_fraction_split=0.2, budget_milli_node_hours=8000, disable_early_stopping=False, ) print(model.display_name) print(model.name) print(model.resource_name) print(model.description) print(model.uri) return model
def test_get_nonexistent_dataset(self): """Ensure attempting to retrieve a dataset that doesn't exist raises a Google API core 404 exception.""" aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) # AI Platform service returns 404 with pytest.raises(exceptions.NotFound): aiplatform.ImageDataset(dataset_name="0")
def test_get_existing_dataset(self): """Retrieve a known existing dataset, ensure SDK successfully gets the dataset resource.""" aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) flowers_dataset = aiplatform.ImageDataset(dataset_name=_TEST_IMAGE_DATASET_ID) assert flowers_dataset.name == _TEST_IMAGE_DATASET_ID assert flowers_dataset.display_name == _TEST_DATASET_DISPLAY_NAME
def create_training_pipeline_custom_package_job_sample( project: str, location: str, staging_bucket: str, display_name: str, python_package_gcs_uri: str, python_module_name: str, container_uri: str, model_serving_container_image_uri: str, dataset_id: Optional[str] = None, model_display_name: Optional[str] = None, args: Optional[List[Union[str, float, int]]] = None, replica_count: int = 1, machine_type: str = "n1-standard-4", accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED", accelerator_count: int = 0, training_fraction_split: float = 0.8, validation_fraction_split: float = 0.1, test_fraction_split: float = 0.1, sync: bool = True, ): aiplatform.init(project=project, location=location, staging_bucket=staging_bucket) job = aiplatform.CustomPythonPackageTrainingJob( display_name=display_name, python_package_gcs_uri=python_package_gcs_uri, python_module_name=python_module_name, container_uri=container_uri, model_serving_container_image_uri=model_serving_container_image_uri, ) # This example uses an ImageDataset, but you can use another type dataset = aiplatform.ImageDataset(dataset_id) if dataset_id else None model = job.run( dataset=dataset, model_display_name=model_display_name, args=args, replica_count=replica_count, machine_type=machine_type, accelerator_type=accelerator_type, accelerator_count=accelerator_count, training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, sync=sync, ) model.wait() print(model.display_name) print(model.resource_name) print(model.uri) return model
def create_training_pipeline_custom_training_managed_dataset_sample( project: str, location: str, display_name: str, script_path: str, container_uri: str, model_serving_container_image_uri: str, dataset_id: int, model_display_name: Optional[str] = None, args: Optional[List[Union[str, float, int]]] = None, replica_count: int = 0, machine_type: str = "n1-standard-4", accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED", accelerator_count: int = 0, training_fraction_split: float = 0.8, validation_fraction_split: float = 0.1, test_fraction_split: float = 0.1, sync: bool = True, ): aiplatform.init(project=project, location=location) job = aiplatform.CustomTrainingJob( display_name=display_name, script_path=script_path, container_uri=container_uri, model_serving_container_image_uri=model_serving_container_image_uri, ) my_image_ds = aiplatform.ImageDataset(dataset_id) model = job.run( dataset=my_image_ds, model_display_name=model_display_name, args=args, replica_count=replica_count, machine_type=machine_type, accelerator_type=accelerator_type, accelerator_count=accelerator_count, training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, sync=sync, ) model.wait() print(model.display_name) print(model.resource_name) print(model.uri) return model
def image_dataset_import_data_sample( project: str, location: str, src_uris: list, import_schema_uri: str, dataset_id: str ): aiplatform.init(project=project, location=location) ds = aiplatform.ImageDataset(dataset_id) ds = ds.import_data( gcs_source=src_uris, import_schema_uri=import_schema_uri, sync=True ) print(ds.display_name) print(ds.name) print(ds.resource_name) return ds
def create_training_pipeline_image_classification_sample( project: str, display_name: str, dataset_id: int, location: str = "us-central1", model_display_name: str = None, training_fraction_split: float = 0.8, validation_fraction_split: float = 0.1, test_fraction_split: float = 0.1, budget_milli_node_hours: int = 8000, disable_early_stopping: bool = False, sync: bool = True, ): aiplatform.init(project=project, location=location) job = aiplatform.AutoMLImageTrainingJob(display_name=display_name) my_image_ds = aiplatform.ImageDataset(dataset_id) model = job.run( dataset=my_image_ds, model_display_name=model_display_name, training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, budget_milli_node_hours=budget_milli_node_hours, disable_early_stopping=disable_early_stopping, sync=sync, ) model.wait() print(model.display_name) print(model.resource_name) print(model.uri) return model