Last active
May 31, 2021 14:13
-
-
Save eileen-code4fun/a0d6bcac4f618e96bb052c5fe250e75e to your computer and use it in GitHub Desktop.
CIFAR10 AutoML
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) | |
tf.keras.preprocessing.image.save_img(TEMP_LOCAL_PATH + fn, image.numpy()) | |
metadata = { | |
'imageGcsUri': GCS_PATH_FOR_DATA + fn, | |
'classificationAnnotation': {'displayName': class_names[label.numpy()]}, | |
'dataItemResourceLabels': {'aiplatform.googleapis.com/ml_use': purpose} | |
} | |
json.dump(metadata, mf) | |
mf.write('\n') | |
i += 1 | |
with open('metadata.jsonl', 'w') as mf: | |
save_images_write_metadata(cifar10['train'].take(40000), 'train', mf) | |
save_images_write_metadata(cifar10['train'].skip(40000), 'validation', mf) | |
save_images_write_metadata(cifar10['test'], 'test', mf) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment