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_evaluate(tmp_dir):
x_train = np.random.rand(100, 32)
y_train = np.random.rand(100, 1)
input_node = ak.Input()
output_node = input_node
output_node = ak.DenseBlock()(output_node)
output_node = ak.RegressionHead()(output_node)
auto_model = ak.GraphAutoModel(input_node,
output_node,
directory=tmp_dir,
max_trials=1)
auto_model.fit(x_train, y_train, epochs=1, validation_data=(x_train, y_train))
auto_model.evaluate(x_train, y_train)
def test_basics(tmp_dir):
x_train = np.random.rand(100, 32)
y_train = np.random.rand(100, 1)
input_node = ak.Input()
output_node = input_node
output_node = ak.DenseBlock()(output_node)
output_node = ak.RegressionHead()(output_node)
auto_model = ak.GraphAutoModel(input_node,
output_node,
directory=tmp_dir,
max_trials=1)
auto_model.fit(x_train, y_train, epochs=1, validation_data=(x_train, y_train))
result = auto_model.predict(x_train)
assert result.shape == (100, 1)
def test_auto_model_basic(_, tmp_dir):
x_train = np.random.rand(100, 32, 32, 3)
y_train = np.random.rand(100, 1)
auto_model = ak.AutoModel(ak.ImageInput(),
ak.RegressionHead(),
directory=tmp_dir,
max_trials=2)
auto_model.fit(x_train, y_train, epochs=2, validation_split=0.2)
x_train = np.random.rand(100, 33)
y_train = np.random.rand(100, 1)
input_node1 = ak.Input()
temp_node1 = ak.Normalization()(input_node1)
output_node1 = ak.DenseBlock()(temp_node1)
output_node3 = ak.Normalization()(temp_node1)
output_node3 = ak.DenseBlock()(output_node3)
input_node2 = ak.Input()
output_node2 = ak.Normalization()(input_node2)
output_node2 = ak.DenseBlock()(output_node2)
output_node = ak.Merge()([output_node1, output_node2, output_node3])
output_node = ak.RegressionHead()(output_node)
graph = ak.GraphAutoModel([input_node1, input_node2],
output_node,
directory=tmp_dir,
max_trials=1)
graph.fit([x_train, x_train], y_train,
epochs=1,
batch_size=100,
validation_data=([x_train, x_train], y_train),
validation_split=0.5,
verbose=False)
def test_merge(tmp_dir):
x_train = np.random.rand(100, 33)
y_train = np.random.rand(100, 1)
input_node1 = ak.Input()
input_node2 = ak.Input()
output_node1 = ak.DenseBlock()(input_node1)
output_node2 = ak.DenseBlock()(input_node2)
output_node = ak.Merge()([output_node1, output_node2])
output_node = ak.RegressionHead()(output_node)
graph = ak.GraphAutoModel([input_node1, input_node2],
output_node,
directory=tmp_dir,
max_trials=1)
graph.fit([x_train, x_train], y_train,
epochs=1,
batch_size=100,
verbose=False,
validation_split=0.5)
result = graph.predict([x_train, x_train])
assert result.shape == (100, 1)
def test_input_missing(tmp_dir):
input_node1 = ak.Input()
input_node2 = ak.Input()
output_node1 = ak.DenseBlock()(input_node1)
output_node2 = ak.DenseBlock()(input_node2)
output_node = ak.Merge()([output_node1, output_node2])
output_node = ak.RegressionHead()(output_node)
with pytest.raises(ValueError) as info:
ak.GraphAutoModel(input_node1, output_node, directory=tmp_dir)
assert str(info.value).startswith('A required input is missing for HyperModel')
def test_input_output_disconnect():
input_node1 = ak.Input()
output_node = input_node1
_ = ak.DenseBlock()(output_node)
input_node = ak.Input()
output_node = input_node
output_node = ak.DenseBlock()(output_node)
output_node = ak.RegressionHead()(output_node)
with pytest.raises(ValueError) as info:
ak.hypermodel.graph.GraphHyperModel(input_node1, output_node)
assert 'Inputs and outputs not connected.' in str(info.value)
x_structured = np.random.rand(x_train.shape[0], 100)
y_regression = np.random.rand(x_train.shape[0], 1)
y_classification = y_classification.reshape(-1, 1)
# Build model and train.
inputs = ak.ImageInput(shape=(28, 28, 1))
outputs1 = ak.ResNetBlock(version='next')(inputs)
outputs2 = ak.XceptionBlock()(inputs)
image_outputs = ak.Merge()((outputs1, outputs2))
structured_inputs = ak.StructuredDataInput()
structured_outputs = ak.DenseBlock()(structured_inputs)
merged_outputs = ak.Merge()((structured_outputs, image_outputs))
classification_outputs = ak.ClassificationHead()(merged_outputs)
regression_outputs = ak.RegressionHead()(merged_outputs)
automodel = ak.GraphAutoModel(inputs=[inputs, structured_inputs],
outputs=[regression_outputs,
classification_outputs])
automodel.fit((x_image, x_structured),
(y_regression, y_classification),
# trials=100,
validation_split=0.2,
epochs=200,
callbacks=[tf.keras.callbacks.EarlyStopping()])