DEVICE_ID = DEVICE_ID_LIST[0] # grab first element from list # Set CUDA_VISIBLE_DEVICES to mask out all other GPUs than the first available device id os.environ["CUDA_VISIBLE_DEVICES"] = str(DEVICE_ID) except EnvironmentError: print("GPU not found") select_gpu() config = tf.ConfigProto(allow_soft_placement=True) config.gpu_options.allow_growth = True sess = tf.Session(config=config) init = tf.global_variables_initializer() sess.run(init) backend.set_session(sess) x_train, y_train, x_test, y_test = get_data() X = np.concatenate((x_train, x_test)) Y = np.concatenate((y_train, y_test)) k_fold = StratifiedKFold(n_splits=10, shuffle=False, random_state=7) ret = [] y_stub = np.random.randint(0, 10, X.shape[0]) cnn_model = get_model(X) weights = cnn_model.get_weights() for train, test in k_fold.split(X, y_stub): cnn_model.set_weights(weights) print("Training started") ret.append(train_model(cnn_model, X[train], Y[train], X[test], Y[test])) print(np.array(ret))
from examples.cnn.cifar10.cifar10 import get_data from examples.cnn.cnn import cnn, select_gpu select_gpu() for width in [64, 128, 256]: for dropout in [0.25, 0.5]: for regularizer in [0.01, 0.001]: params = [width * 1.0] * 6 + [dropout] * 6 + [regularizer] * 4 print(params) cnn(params, get_data())