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 tensorflow.keras import layers, models, losses | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('--epochs', dest='epochs', type=int, default=5) | |
parser.add_argument('--dropout_rate', dest='dropout_rate', type=float, default=0.1) | |
args = parser.parse_args() | |
def create_model(): |
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 hypertune | |
hpt = hypertune.HyperTune() | |
class CustomCallback(tf.keras.callbacks.Callback): | |
def on_epoch_end(self, epoch, logs=None): | |
hpt.report_hyperparameter_tuning_metric( | |
hyperparameter_metric_tag='val_accuracy', | |
metric_value=logs['val_accuracy'], |
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
studySpec: | |
metrics: | |
# Correspond to the metrics we use the hypertune library to report. | |
- metricId: val_accuracy | |
goal: MAXIMIZE | |
parameters: | |
# Correspond to the command line argument our Python code expects. | |
- parameterId: dropout_rate | |
doubleValueSpec: | |
minValue: 0.01 |
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 os | |
tensorboard_callback = tf.keras.callbacks.TensorBoard( | |
log_dir=os.environ['AIP_TENSORBOARD_LOG_DIR'], | |
histogram_freq=1 | |
) | |
model.fit(train_dataset, epochs=args.epochs, validation_data=val_dataset, callbacks=[tensorboard_callback]) |
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-viz", | |
"jobSpec": { | |
"workerPoolSpecs": [ | |
{ | |
"replicaCount": 1, | |
"machineSpec": { | |
"machineType": "n1-standard-4", | |
"acceleratorType": "NVIDIA_TESLA_V100", | |
"acceleratorCount": 2 |
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]]) |
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
{ | |
"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 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
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) |