This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import tensorflow_datasets as tfds | |
ds = tfds.load('cifar10', as_supervised=True) | |
def csvfy(dataset, filename): | |
with open(filename, 'w') as f: | |
for image, label in dataset: | |
f.write('{},'.format(label.numpy())) | |
f.write(','.join(str(x) for x in list(image.numpy().reshape(-1)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
api_client.create_schedule_from_job_spec( | |
job_spec_path='e2e-tutorial-automl-pipeline-schedule.json', | |
# Start at the first minute of every hour. | |
schedule='1 * * * *' | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kfp.v2 import compiler | |
from google.cloud.aiplatform import AIPlatformClient | |
compiler.Compiler().compile(pipeline_func=e2e_tutorial_pipeline, package_path='e2e-tutorial-automl-pipeline.json') | |
api_client = AIPlatformClient(project_id='PROJECT_ID', region='us-central1') | |
api_client.create_run_from_job_spec( | |
job_spec_path='e2e-tutorial-automl-pipeline.json' | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kfp import dsl | |
from google_cloud_pipeline_components import aiplatform | |
@dsl.pipeline( | |
name='e2e-tutorial-automl-pipeline', | |
description='A simple automl training', | |
pipeline_root='GCS_PATH_FOR_PIPELINE' | |
) | |
def e2e_tutorial_pipeline(): | |
job = aiplatform.AutoMLImageTrainingJobRunOp( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"displayName": "e2e-tutorial-automl", | |
"inputDataConfig": { | |
"datasetId": "DATASET_ID", | |
"filterSplit": { | |
"trainingFilter": "labels.aiplatform.googleapis.com/ml_use=training", | |
"validationFilter": "labels.aiplatform.googleapis.com/ml_use=validation", | |
"testFilter": "labels.aiplatform.googleapis.com/ml_use=test" | |
} | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import tensorflow_datasets as tfds | |
cifar10 = tfds.load('cifar10', as_supervised=True) | |
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'] | |
def save_images_write_metadata(dataset, purpose, mf): | |
i = 1 | |
for image, label in dataset: | |
fn = '{}_{}.jpeg'.format(purpose, i) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import io | |
attr_map = tf.io.decode_jpeg(base64.b64decode(BASE64_JPEG_DATA)) | |
plt.subplot(1, 2, 1) | |
plt.xticks([]) | |
plt.yticks([]) | |
plt.title(class_names[test_labels[0][0]]) | |
plt.imshow(test_images[0]) | |
plt.xticks([]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"inputs": { | |
"image": { | |
"inputTensorName": "conv2d_input", | |
"modality": "image" | |
} | |
}, | |
"outputs": { | |
"explanation": { | |
"outputTensorName": "dense_1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
data = { | |
"instances": [ | |
(test_images[0]/255.0).tolist() | |
] | |
} | |
print(json.dumps(data), file=open('prediction_request.json', 'w')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.keras import datasets | |
import matplotlib.pyplot as plt | |
_, (test_images, test_labels) = datasets.cifar10.load_data() | |
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'] | |
plt.xticks([]) | |
plt.yticks([]) | |
plt.title(class_names[test_labels[0][0]]) |