Last active
May 12, 2021 15:41
-
-
Save ZackAkil/ac4df918ceaebaf5dfd0f3ad76a01099 to your computer and use it in GitHub Desktop.
Given a Google Cloud Storage folder location, generate a automl image classification training data label file using the folders as labels. (https://cloud.google.com/ai-platform-unified/docs/datasets/prepare-image)
This file contains 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 google.cloud import storage | |
folder_location = 'automl-ui-dataset/x-ray-dataset' | |
parts = folder_location.split('/') | |
prefix = '/'.join(parts[1:]) if len(parts) > 1 else '' | |
storage_client = storage.Client() | |
blobs = storage_client.list_blobs(parts[0], prefix=prefix) | |
f = open("labels.csv", "w") | |
for blob in list(blobs)[1:]: | |
path = 'gs://' + blob.name | |
label = blob.name.split(prefix)[1].split('/')[1] | |
print(path, label) | |
f.write(path+','+label+'\n') | |
f.close() | |
print(parts, prefix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment