from sklearn.model_selection import KFold
import subprocess
import os
import numpy as np
import time
os.chdir('../')
data_generator = KFold(n_splits=5, shuffle=True, random_state=13)
base_job_name = 'isles_cv_soft_dice_loss'
bucket_name = 'gs://coral-weaver-4010'
data_dir = os.path.join(bucket_name, 'data/isles_tfrecords')
region = 'us-east1'

file_paths = subprocess.check_output('gsutil ls ' + data_dir, shell=True)
file_paths = np.array(file_paths.split('\n')[1:-1])

np.random.seed(1)
np.random.shuffle(file_paths)

fold = 1
for train_indices, valid_indices in data_generator.split(file_paths):
    train_file_paths = ' '.join(file_paths[train_indices])
    eval_file_paths = ' '.join(file_paths[valid_indices])
    job_dir = os.path.join(bucket_name, base_job_name, 'fold_' + str(fold))
    job_name = base_job_name + '_fold_' + str(fold)
    fold += 1

    command = 'gcloud ml-engine jobs submit training {0} ' \
              '--job-dir {1} ' \
              '--runtime-version 1.2 ' \
              '--module-name trainer.task ' \
              '--package-path trainer/ ' \
              '--scale-tier CUSTOM ' \
              '--config config.yaml ' \
              '--region {2} ' \
              '-- ' \
              '--train-files {3} ' \
              '--eval-files {4} ' \
              '--learning-rate .01 ' \
              '--train-steps 1000 ' \
              '--num-epochs 30 ' \
              '--verbosity DEBUG'.format(job_name, job_dir, region, train_file_paths, eval_file_paths)

    print command
    output = subprocess.call(command, shell=True)
    time.sleep(3600 * 1.5)

f71a69b59f6c106192d2dd286fd8d71aa3136e75
from sklearn.model_selection import KFold
import subprocess
import os
import numpy as np
import time
os.chdir('../')
data_generator = KFold(n_splits=5, shuffle=True, random_state=13)
base_job_name = 'isles_cv_soft_dice_loss'
bucket_name = 'gs://coral-weaver-4010'
data_dir = os.path.join(bucket_name, 'data/isles_tfrecords')
region = 'us-east1'

file_paths = subprocess.check_output('gsutil ls ' + data_dir, shell=True)
file_paths = np.array(file_paths.split('\n')[1:-1])

np.random.seed(1)
np.random.shuffle(file_paths)

fold = 1
for train_indices, valid_indices in data_generator.split(file_paths):
    train_file_paths = ' '.join(file_paths[train_indices])
    eval_file_paths = ' '.join(file_paths[valid_indices])
    job_dir = os.path.join(bucket_name, base_job_name, 'fold_' + str(fold))
    job_name = base_job_name + '_fold_' + str(fold)
    fold += 1

    command = 'gcloud ml-engine jobs submit training {0} ' \
              '--job-dir {1} ' \
              '--runtime-version 1.2 ' \
              '--module-name trainer.task ' \
              '--package-path trainer/ ' \
              '--scale-tier CUSTOM ' \
              '--config config.yaml ' \
              '--region {2} ' \
              '-- ' \
              '--train-files {3} ' \
              '--eval-files {4} ' \
              '--learning-rate .01 ' \
              '--train-steps 1000 ' \
              '--num-epochs 30 ' \
              '--verbosity DEBUG'.format(job_name, job_dir, region, train_file_paths, eval_file_paths)

    print command
    output = subprocess.call(command, shell=True)
    time.sleep(3600 * 1.5)
