def test_create_multiple_inputs_with_one_vnode(self): import tensorflow as tf from deephyper.nas import KSearchSpace from deephyper.nas.node import ConstantNode, VariableNode from deephyper.nas.operation import operation, Concatenate Dense = operation(tf.keras.layers.Dense) class TestSpace(KSearchSpace): def __init__(self, input_shape, output_shape): super().__init__(input_shape, output_shape) def build(self): merge = ConstantNode() merge.set_op(Concatenate(self, self.input_nodes)) vnode1 = VariableNode() self.connect(merge, vnode1) vnode1.add_op(Dense(1)) return self space = TestSpace([(5, ), (5, )], (1, )).build() model = space.sample()
def test_create_more_nodes(self): import tensorflow as tf from deephyper.nas import KSearchSpace from deephyper.nas.node import VariableNode from deephyper.nas.operation import operation Dense = operation(tf.keras.layers.Dense) class TestSpace(KSearchSpace): def __init__(self, input_shape, output_shape): super().__init__(input_shape, output_shape) def build(self): vnode1 = VariableNode() self.connect(self.input_nodes[0], vnode1) vnode1.add_op(Dense(10)) vnode2 = VariableNode() vnode2.add_op(Dense(1)) self.connect(vnode1, vnode2) return self space = TestSpace((5, ), (1, )).build() model = space.sample()
def test_basic_space(verbose=0): import tensorflow as tf from deephyper.nas import KSearchSpace from deephyper.nas.node import VariableNode, ConstantNode from deephyper.nas.operation import operation, Identity Dense = operation(tf.keras.layers.Dense) class BasicSpace(KSearchSpace): def __init__(self, input_shape, output_shape, batch_size=None, *args, **kwargs): super().__init__(input_shape, output_shape, batch_size=batch_size, *args, **kwargs) def build(self): input_node = self.input[0] dense = VariableNode() dense.add_op(Identity()) for i in range(1, 1000): dense.add_op(Dense(i)) self.connect(input_node, dense) output_node = ConstantNode(Dense(self.output_shape[0])) self.connect(dense, output_node) space = BasicSpace(input_shape=(1, ), output_shape=(1, )) space.build() model_1 = space.sample([1]) if verbose: model_1.summary() model_2 = space.sample() if verbose: model_2.summary()
def test_mirror_node(self): import tensorflow as tf from deephyper.nas.node import MirrorNode, VariableNode from deephyper.nas.operation import operation Dense = operation(tf.keras.layers.Dense) vnode = VariableNode() vop = Dense(10) vnode.add_op(vop) vnode.add_op(Dense(20)) mnode = MirrorNode(vnode) vnode.set_op(0) assert vnode.op == vop assert mnode.op == vop
import pytest import tensorflow as tf from deephyper.nas import KSearchSpace from deephyper.nas.node import ConstantNode, VariableNode from deephyper.nas.operation import operation, Concatenate Dense = operation(tf.keras.layers.Dense) @pytest.mark.incremental class TestKSearchSpace: def test_create(self): class TestSpace(KSearchSpace): def __init__(self, input_shape, output_shape): super().__init__(input_shape, output_shape) def build(self): vnode = VariableNode() self.connect(self.input_nodes[0], vnode) vnode.add_op(Dense(1)) return self space = TestSpace((5, ), (1, )).build() model = space.sample() def test_create_more_nodes(self): class TestSpace(KSearchSpace): def __init__(self, input_shape, output_shape):
import tensorflow as tf from deephyper.nas import KSearchSpace from deephyper.nas.node import ConstantNode, VariableNode from deephyper.nas.operation import operation, Concatenate Dense = operation(tf.keras.layers.Dense) Dropout = operation(tf.keras.layers.Dropout) class OneLayerSpace(KSearchSpace): def __init__(self, input_shape, output_shape, batch_size=None, seed=None, regression=True): super().__init__(input_shape, output_shape, batch_size=batch_size, seed=seed) self.regression = regression def build(self): if type(self.input_shape) is list: vnodes = [] for i in range(len(self.input_shape)): vn = self.gen_vnode() vnodes.append(vn) self.connect(self.input_nodes[i], vn)