How to use deephyper - 10 common examples

To help you get started, we’ve selected a few deephyper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github deephyper / deephyper / tests / deephyper / search / nas / model / space / test_auto_output_structure.py View on Github external
def test_create_more_nodes(self):
        from deephyper.search.nas.model.space.struct import AutoOutputStructure
        from deephyper.search.nas.model.space.node import VariableNode
        from deephyper.search.nas.model.space.op.op1d import Dense
        struct = AutoOutputStructure((5, ), (1, ))

        vnode1 = VariableNode()
        struct.connect(struct.input_nodes[0], vnode1)

        vnode1.add_op(Dense(10))

        vnode2 = VariableNode()
        vnode2.add_op(Dense(10))

        struct.connect(vnode1, vnode2)

        struct.set_ops([0, 0])

        falias = 'test_direct_structure'
        struct.draw_graphviz(f'{falias}.dot')

        model = struct.create_model()
        from tensorflow.keras.utils import plot_model

        plot_model(model, to_file=f'{falias}.png', show_shapes=True)
github deephyper / deephyper / tests / deephyper / search / nas / model / space / test_direct_structure.py View on Github external
def test_create_more_nodes(self):
        from deephyper.search.nas.model.space.struct import DirectStructure
        from deephyper.search.nas.model.space.node import VariableNode
        from deephyper.search.nas.model.space.op.op1d import Dense
        struct = DirectStructure((5, ), (1, ))

        vnode1 = VariableNode()
        struct.connect(struct.input_nodes[0], vnode1)

        vnode1.add_op(Dense(10))

        vnode2 = VariableNode()
        vnode2.add_op(Dense(1))

        struct.connect(vnode1, vnode2)

        struct.set_ops([0, 0])

        falias = 'test_direct_structure'
        struct.draw_graphviz(f'{falias}.dot')

        model = struct.create_model()
        from tensorflow.keras.utils import plot_model

        plot_model(model, to_file=f'{falias}.png', show_shapes=True)
github deephyper / deephyper / tests / deephyper / search / nas / model / space / test_auto_output_structure.py View on Github external
def test_create_one_vnode(self):
        from deephyper.search.nas.model.space.struct import AutoOutputStructure
        struct = AutoOutputStructure((5, ), (1, ))

        from deephyper.search.nas.model.space.node import VariableNode
        vnode = VariableNode()

        struct.connect(struct.input_nodes[0], vnode)

        from deephyper.search.nas.model.space.op.op1d import Dense
        vnode.add_op(Dense(10))

        struct.set_ops([0])

        falias = 'test_direct_structure'
        struct.draw_graphviz(f'{falias}.dot')

        model = struct.create_model()
        from tensorflow.keras.utils import plot_model

        plot_model(model, to_file=f'{falias}.png', show_shapes=True)
github deephyper / deephyper / tests / deephyper / search / nas / model / space / test_direct_structure.py View on Github external
def test_create_one_vnode(self):
        from deephyper.search.nas.model.space.struct import DirectStructure
        struct = DirectStructure((5, ), (1, ))

        from deephyper.search.nas.model.space.node import VariableNode
        vnode = VariableNode()

        struct.connect(struct.input_nodes[0], vnode)

        from deephyper.search.nas.model.space.op.op1d import Dense
        vnode.add_op(Dense(1))

        struct.set_ops([0])

        falias = 'test_direct_structure'
        struct.draw_graphviz(f'{falias}.dot')

        model = struct.create_model()
        from tensorflow.keras.utils import plot_model

        plot_model(model, to_file=f'{falias}.png', show_shapes=True)
github deephyper / deephyper / tests / deephyper / search / nas / model / space / test_direct_structure.py View on Github external
def test_create_multiple_inputs_with_one_vnode(self):
        from deephyper.search.nas.model.space.struct import DirectStructure
        from deephyper.search.nas.model.space.node import VariableNode, ConstantNode
        from deephyper.search.nas.model.space.op.op1d import Dense
        from deephyper.search.nas.model.space.op.merge import Concatenate
        struct = DirectStructure([(5, ), (5, )], (1, ))

        merge = ConstantNode()
        merge.set_op(Concatenate(struct, merge, struct.input_nodes))

        vnode1 = VariableNode()
        struct.connect(merge, vnode1)

        vnode1.add_op(Dense(1))

        struct.set_ops([0])

        struct.create_model()
github deephyper / deephyper / search / run_nas.py View on Github external
import numpy as np
import tensorflow as tf
tf.set_random_seed(1000003)
np.random.seed(1000003)

HERE = os.path.dirname(os.path.abspath(__file__)) # search dir
top  = os.path.dirname(os.path.dirname(HERE)) # directory containing deephyper
sys.path.append(top)

import deephyper.model.arch as a
from deephyper.evaluators import evaluate
from deephyper.search import util
from deephyper.search.nas.policy.tf import NASCellPolicyV5
from deephyper.search.nas.reinforce.tf import BasicReinforceV5

logger = util.conf_logger('deephyper.search.run_nas')

import subprocess as sp
logger.debug(f'ddd {sp.Popen("which mpirun".split())}')
logger.debug(f'python exe : {sys.executable}')

from balsam.launcher import dag
from balsam.launcher import worker

SERVICE_PERIOD = 2          # Delay (seconds) between main loop iterations

class Search:
    def __init__(self, cfg):
        self.opt_config = cfg
        self.evaluator = evaluate.create_evaluator_nas(cfg)
        self.config = cfg.config
        self.map_model_reward = {}
github deephyper / deephyper / search / async-search.py View on Github external
cfg, optimizer, evaluator = load_checkpoint(chk_path)
    else:
        cfg = util.OptConfig(args)
        optimizer = Optimizer(
            cfg.space,
            base_estimator=ExtremeGradientBoostingQuantileRegressor(),
            acq_optimizer='sampling',
            acq_func='LCB',
            acq_func_kwargs={'kappa':0},
            random_state=SEED,
            n_initial_points=args.num_workers
        )
        evaluator = evaluate.create_evaluator(cfg)
        logger.info(f"Starting new run with {cfg.benchmark_module_name}")

    timer = util.elapsed_timer(max_runtime_minutes=None, service_period=SERVICE_PERIOD)
    chkpoint_counter = 0

    # Gracefully handle shutdown
    def handler(signum, stack):
        logger.info('Received SIGINT/SIGTERM')
        save_checkpoint(cfg, optimizer, evaluator)
        sys.exit(0)

    signal.signal(signal.SIGINT, handler)
    signal.signal(signal.SIGTERM, handler)

    # MAIN LOOP
    logger.info("Hyperopt driver starting")

    for elapsed_seconds in timer:
        logger.info(f"Elapsed time: {util.pretty_time(elapsed_seconds)}")
github deephyper / deephyper / deephyper / benchmarks / b1 / addition_rnn.py View on Github external
callbacks_list = [timeout_monitor]

    timer.start('model training')
    train_history = model.fit(x_train, y_train, callbacks=callbacks_list, batch_size=BATCH_SIZE, 
                                initial_epoch=initial_epoch, epochs=EPOCHS, validation_split=0.30)#, validation_data=(x_val, y_val))
    timer.end()
    
    score = model.evaluate(x_val, y_val, batch_size=BATCH_SIZE)
    print('===Validation loss:', score[0])
    print('===Validation accuracy:', score[1])
    print('OUTPUT:', -score[1])
    
    if model_path:
        timer.start('model save')
        model.save(model_path)
        util.save_meta_data(param_dict, model_mda_path)
        timer.end()
    return -score[1]
github deephyper / deephyper / deephyper / benchmarks / b3 / babi_rnn.py View on Github external
#earlystop = EarlyStopping(monitor='val_acc', min_delta=0.0001, patience=50, verbose=1, mode='auto')
    timeout_monitor = TerminateOnTimeOut(TIMEOUT)
    callbacks_list = [timeout_monitor]
    timer.start('model training')
    print('Training')
    model.fit([x, xq], y, callbacks=callbacks_list, batch_size=BATCH_SIZE, initial_epoch=initial_epoch, 
                epochs=EPOCHS, validation_split=0.30)
    timer.end()
    loss, acc = model.evaluate([tx, txq], ty, batch_size=BATCH_SIZE)
    print('Test loss / test accuracy = {:.4f} / {:.4f}'.format(loss, acc))
    print('OUTPUT:', -acc)
    
    if model_path:
        timer.start('model save')
        model.save(model_path)  
        util.save_meta_data(param_dict, model_mda_path)
        timer.end()
    
    return -acc
github deephyper / deephyper / deephyper / model / trainer / tf.py View on Github external
def preprocess_data(self):
        self.train_X = self.config[a.data][a.train_X]
        self.train_y = self.config[a.data][a.train_Y]
        perm = np.random.permutation(np.shape(self.train_X)[0])
        self.train_X = self.train_X[perm]
        self.train_y = self.train_y[perm]
        self.valid_X = self.config[a.data][a.valid_X]
        self.valid_y = self.config[a.data][a.valid_Y]
        self.train_size = np.shape(self.config[a.data][a.train_X])[0]
        #if self.train_size == self.batch_size: self.train_size = self.train_X.shape[1]
        logger.debug(f'\ntrain_X.shape = {self.train_X.shape},\n\
                       train_y.shape = {self.train_y.shape},\n\
                       input_shape = {self.input_shape}')
        self.train_X = self.train_X.reshape(
            [-1]+self.input_shape).astype('float32')
        self.valid_X = self.valid_X.reshape(
            [-1]+self.input_shape).astype('float32')
        self.np_label_type = 'float32' if self.num_outputs == 1 else 'int64'
        self.train_y = np.squeeze(self.train_y).astype(self.np_label_type)
        self.valid_y = np.squeeze(self.valid_y).astype(self.np_label_type)

        logger.debug(f'\n after reshaping: train_X.shape = {self.train_X.shape},\n\
                           train_y.shape = {self.train_y.shape},\n\