#@title GCS
#@markdown You should change these values as per your preferences. The copy operation can take ~5 minutes. 
BUCKET_PATH = "gs://flowers-experimental" #@param {type:"string"}
REGION = "us-central1" #@param {type:"string"}

!gsutil mb -l {REGION} {BUCKET_PATH}
!gsutil -m cp -r flower_photos {BUCKET_PATH}import random
random.seed(666)

from google.cloud import storage
from pprint import pprint
import pandas as pd
import osfrom google.colab import auth
auth.authenticate_user()gs_uris = []

storage_client = storage.Client(project="fast-ai-exploration") # Change it accordingly.
blobs = storage_client.list_blobs(BUCKET_PATH.split("/")[-1])

for blob in blobs:
    if ".txt" in blob.name.split("/")[-1]:
        continue
    gs_uri = os.path.join(BUCKET_PATH, blob.name)
    gs_uris.append(gs_uri)

pprint(gs_uris[:5])# Create splits.
random.shuffle(gs_uris)

i = int(len(gs_uris) * 0.9)
train_paths = gs_uris[:i]
test_paths = gs_uris[i:]

i = int(len(train_paths) * 0.05)
valid_paths = train_paths[:i]
train_paths = train_paths[i:]

print(len(train_paths), len(valid_paths), len(test_paths))def derive_labels(gcs_paths, split="training"):
    labels = []
    for gcs_path in gcs_paths:
        label = gcs_path.split("/")[4]
        labels.append(label)
    return labels, [split] * len(gcs_paths)# File format is referred from: https://cloud.google.com/vertex-ai/docs/datasets/prepare-image#csv
train_labels, train_use = derive_labels(train_paths)
val_labels, val_use = derive_labels(valid_paths, split="validation")
test_labels, test_use= derive_labels(test_paths, split="test")gcs_uris = []
labels = []
use = []

gcs_uris.extend(train_paths)
gcs_uris.extend(valid_paths)
gcs_uris.extend(test_paths)

labels.extend(train_labels)
labels.extend(val_labels)
labels.extend(test_labels)

use.extend(train_use)
use.extend(val_use)
use.extend(test_use)import csv

with open("flowers_vertex.csv", "w") as csvfile: 
    csvwriter = csv.writer(csvfile)
    
    for ml_use, gcs_uri, label in zip(use, gcs_uris, labels):
        row = [ml_use, gcs_uri, label]
        csvwriter.writerow(row)  