Skip to content

Instantly share code, notes, and snippets.

Created November 16, 2019 19:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koaning/1de832816bd1b124a42219962f2dabef to your computer and use it in GitHub Desktop.
Save koaning/1de832816bd1b124a42219962f2dabef to your computer and use it in GitHub Desktop.
keras grid job
import uuid
import json
import random
import keras
import numpy as np
import tensorflow as tf
import click
def build_model(blob):
inputs = keras.Input(shape=(blob['num_columns'],), name='img')
x = keras.layers.Dense(blob['num_columns'], activation='sigmoid')(inputs)
for i in range(blob['num_layers']-1):
x = keras.layers.Dense(blob['num_columns'], activation='sigmoid')(x)
outputs = keras.layers.Dense(blob['num_columns'], activation='sigmoid')(x)
model = keras.Model(inputs=inputs, outputs=outputs, name='mnist_model')
model.compile(loss='binary_crossentropy', optimizer=keras.optimizers.Adam(learning_rate=0.1))
return model
def train_model(mod, blob):
train = np.random.randint(0, 2, (blob['rows'], blob['num_columns']))
mod.compile(loss=blob['loss_func'], optimizer=keras.optimizers.Adam(learning_rate=0.1))
return, train,
callbacks=[keras.callbacks.ReduceLROnPlateau(monitor='val_loss', factor=0.5,
patience=15, verbose=2,
mode='auto', min_delta=0.01)])
def build_train(blob):
model = build_model(blob)
hist = train_model(model, blob)
blob['lr'] = [float(i) for i in blob['lr']]
return blob
if __name__ == "__main__":
res = build_train({'num_columns': random.choice([10, 11, 12]), 'num_layers': random.choice([1, 3, 2, 3, 4, 4, 5, 5]),
'loss_func': 'binary_crossentropy', 'tf_seed': random.randint(1, 4200),
'epochs': 300, 'rows': random.choice([2000, 3000, 4000])})
with open(f"/Users/vincent/Development/grid/logs/{str(uuid.uuid4())[:14]}.jsonl", "w") as f:
json.dump(res, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment