Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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)
def add_dense_to_(node):
node.add_op(Identity()) # we do not want to create a layer in this case
activations = [None, tf.nn.relu, tf.nn.tanh, tf.nn.sigmoid]
for units in range(16, 97, 16):
for activation in activations:
node.add_op(Dense(units=units, activation=activation))
def create_search_space(
input_shape=(100,), output_shape=[(100), (1,)], num_layers=5, **kwargs
):
struct = KSearchSpace(input_shape, output_shape)
inp = struct.input_nodes[0]
# regressor
# prev_node = latente_space
prev_node = inp
for _ in range(num_layers):
vnode = VariableNode()
for i in range(16, 129, 16):
vnode.add_op(Dense(i, tf.nn.relu))
struct.connect(prev_node, vnode)
prev_node = vnode
out1 = ConstantNode(op=Dense(1, name="output_0"))
struct.connect(prev_node, out1)
# auto-encoder
# units = [128, 64, 32, 16, 8, 16, 32, 64, 128]
units = [32, 16, 32]
prev_node = inp
d = 1
for i in range(len(units)):
vnode = VariableNode()
# vnode.add_op(Identity)
if d == 1 and units[i] < units[i + 1]:
def create_block():
# first node of block
n1 = Node('N1')
for inpt in input_nodes:
n1.add_op(Connect(cell.graph, inpt, n1))
# second node of block
mlp_op_list = list()
mlp_op_list.append(Identity())
mlp_op_list.append(Dense(5, tf.nn.relu))
mlp_op_list.append(Dense(5, tf.nn.tanh))
mlp_op_list.append(Dense(10, tf.nn.relu))
mlp_op_list.append(Dense(10, tf.nn.tanh))
mlp_op_list.append(Dense(20, tf.nn.relu))
mlp_op_list.append(Dense(20, tf.nn.tanh))
n2 = Node('N2')
for op in mlp_op_list:
n2.add_op(op)
# third node of block
n3 = Node('N3')
for op in dropout_ops:
n3.add_op(op)
block = Block()
block.add_node(n1)
block.add_node(n2)
block.add_node(n3)
block.add_edge(n1, n2)
d = 1
for i in range(len(units)):
vnode = VariableNode()
# vnode.add_op(Identity)
if d == 1 and units[i] < units[i + 1]:
d = -1
# print(min(1, units[i]), ' - ', max(1, units[i])+1)
for u in range(min(2, units[i], 2), max(2, units[i]) + 1, 2):
vnode.add_op(Dense(u, tf.nn.relu))
latente_space = vnode
else:
# print(min(units[i], units[i+d]), ' - ', max(units[i], units[i+d])+1)
for u in range(
min(units[i], units[i + d]), max(units[i], units[i + d]) + 1, 2
):
vnode.add_op(Dense(u, tf.nn.relu))
struct.connect(prev_node, vnode)
prev_node = vnode
out2 = ConstantNode(op=Dense(100, name="output_1"))
struct.connect(prev_node, out2)
return struct
def create_block():
# first node of block
n1 = Node('N1')
for inpt in input_nodes:
n1.add_op(Connect(cell.graph, inpt, n1))
# second node of block
mlp_op_list = list()
mlp_op_list.append(Identity())
mlp_op_list.append(Dense(5, tf.nn.relu))
mlp_op_list.append(Dense(5, tf.nn.tanh))
mlp_op_list.append(Dense(10, tf.nn.relu))
mlp_op_list.append(Dense(10, tf.nn.tanh))
mlp_op_list.append(Dense(20, tf.nn.relu))
mlp_op_list.append(Dense(20, tf.nn.tanh))
n2 = Node('N2')
for op in mlp_op_list:
n2.add_op(op)
# third node of block
n3 = Node('N3')
for op in dropout_ops:
n3.add_op(op)
block = Block()
block.add_node(n1)
block.add_node(n2)
block.add_node(n3)
def add_dense_to_(node):
node.add_op(Identity()) # we do not want to create a layer in this case
activations = [None, tf.nn.relu, tf.nn.tanh, tf.nn.sigmoid]
for units in range(16, 97, 16):
for activation in activations:
node.add_op(Dense(units=units, activation=activation))
"""
cell = Cell(input_nodes)
# first node of block
n1 = VariableNode('N_0')
for inpt in input_nodes:
n1.add_op(Connect(cell.graph, inpt, n1))
# second node of block
mlp_op_list = list()
mlp_op_list.append(Identity())
mlp_op_list.append(Dense(5, tf.nn.relu))
mlp_op_list.append(Dense(10, tf.nn.relu))
mlp_op_list.append(Dense(20, tf.nn.relu))
mlp_op_list.append(Dense(40, tf.nn.relu))
mlp_op_list.append(Dense(80, tf.nn.relu))
mlp_op_list.append(Dense(160, tf.nn.relu))
mlp_op_list.append(Dense(320, tf.nn.relu))
n2 = VariableNode('N_1')
for op in mlp_op_list:
n2.add_op(op)
# third
n3 = VariableNode('N_2')
drop_ops = []
drop_ops.extend(dropout_ops)
for op in drop_ops:
n3.add_op(op)
# 1 Blocks
block1 = Block()
block1.add_node(n1)