def test_create_more_nodes(self): from deephyper.search.nas.model.space import AutoKSearchSpace from deephyper.search.nas.model.space.node import VariableNode from deephyper.search.nas.model.space.op.op1d import Dense struct = AutoKSearchSpace((5, ), (1, ), regression=True) 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_auto_keras_search_spaceure' 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)
def create_search_space( input_shape=(10, ), output_shape=(7, ), num_layers=10, *args, **kwargs): arch = AutoKSearchSpace(input_shape, output_shape, regression=True) source = prev_input = arch.input_nodes[0] # look over skip connections within a range of the 3 previous nodes anchor_points = collections.deque([source], maxlen=3) for _ in range(num_layers): vnode = VariableNode() add_dense_to_(vnode) arch.connect(prev_input, vnode) # * Cell output cell_output = vnode cmerge = ConstantNode() cmerge.set_op(AddByProjecting(arch, [cell_output], activation='relu')) for anchor in anchor_points: skipco = VariableNode() skipco.add_op(Tensor([])) skipco.add_op(Connect(arch, anchor)) arch.connect(skipco, cmerge) # ! for next iter prev_input = cmerge anchor_points.append(prev_input) return arch
def test_create_search_space(input_shape=(2, ), output_shape=(1, ), **kwargs): struct = AutoKSearchSpace(input_shape, output_shape, regression=True) vnode1 = VariableNode() for _ in range(1, 11): vnode1.add_op(Operation(layer=tf.keras.layers.Dense(10))) struct.connect(struct.input_nodes[0], vnode1) struct.set_ops([0]) struct.create_model()
def create_search_space_old( input_shape=(2, ), output_shape=(5, ), *args, **kwargs): ss = AutoKSearchSpace(input_shape, output_shape, regression=True) prev = ss.input_nodes[0] for _ in range(3): cn = ConstantNode(Dense(10, "relu")) ss.connect(prev, cn) prev = cn cn = ConstantNode(Dense(5)) ss.connect(prev, cn) return ss