Exemplo n.º 1
0
 def __init__(self, preprocessors=None, **kwargs):
     super().__init__(**kwargs)
     self.preprocessors = nest.flatten(preprocessors)
     self._finished = False
     # Save or load the HyperModel.
     utils.save_json(os.path.join(self.project_dir, 'graph'),
                     graph_module.serialize(self.hypermodel.hypermodel))
Exemplo n.º 2
0
def test_text_block():
    block = wrapper.TextBlock()
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, ak.TextInput(shape=(1, )).build())

    assert utils.name_in_hps('vectorizer', hp)
Exemplo n.º 3
0
def test_spatial_reduction():
    input_shape = (32, 32, 3)
    block = reduction.SpatialReduction()
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, ak.Input(shape=input_shape).build())

    assert utils.name_in_hps('reduction_type', hp)
Exemplo n.º 4
0
def test_time_series_input_node():
    # TODO. Change test once TimeSeriesBlock is added.
    node = ak.TimeseriesInput(shape=(32, ), lookback=2)
    output = node.build()
    assert isinstance(output, tf.Tensor)

    node = graph_module.deserialize(graph_module.serialize(node))
    output = node.build()
    assert isinstance(output, tf.Tensor)
Exemplo n.º 5
0
def block_basic_exam(block, inputs, hp_names):
    hp = kerastuner.HyperParameters()
    block = graph_module.deserialize(graph_module.serialize(block))
    outputs = block.build(hp, inputs)

    for hp_name in hp_names:
        assert name_in_hps(hp_name, hp)

    return outputs
Exemplo n.º 6
0
def test_image_block():
    block = wrapper.ImageBlock(normalize=None, augment=None)
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, ak.ImageInput(shape=(32, 32, 3)).build())

    assert utils.name_in_hps('block_type', hp)
    assert utils.name_in_hps('normalize', hp)
    assert utils.name_in_hps('augment', hp)
Exemplo n.º 7
0
def test_imag_augmentation():
    input_shape = (32, 32, 3)
    block = preprocessing.ImageAugmentation()
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, ak.Input(shape=input_shape).build())

    assert utils.name_in_hps('vertical_flip', hp)
    assert utils.name_in_hps('horizontal_flip', hp)
Exemplo n.º 8
0
def test_segmentation():
    y = np.array(['a', 'a', 'c', 'b'])
    head = head_module.SegmentationHead(name='a')
    adapter = head.get_adapter()
    adapter.fit_transform(y)
    head.config_from_adapter(adapter)
    input_shape = (64, 64, 21)
    hp = kerastuner.HyperParameters()
    head = graph_module.deserialize(graph_module.serialize(head))
    head.build(hp, ak.Input(shape=input_shape).build())
Exemplo n.º 9
0
def test_dense_block():
    input_shape = (32, )
    block = basic.DenseBlock()
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, ak.Input(shape=input_shape).build())

    assert utils.name_in_hps('num_layers', hp)
    assert utils.name_in_hps('use_batchnorm', hp)
Exemplo n.º 10
0
def test_embedding_block():
    input_shape = (32, )
    block = basic.Embedding()
    block.max_features = 100
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, ak.Input(shape=input_shape).build())

    assert utils.name_in_hps('pretraining', hp)
    assert utils.name_in_hps('embedding_dim', hp)
Exemplo n.º 11
0
def test_rnn_block():
    input_shape = (32, 10)
    block = basic.RNNBlock()
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, ak.Input(shape=input_shape).build())

    assert utils.name_in_hps('bidirectional', hp)
    assert utils.name_in_hps('layer_type', hp)
    assert utils.name_in_hps('num_layers', hp)
Exemplo n.º 12
0
def test_conv_block():
    input_shape = (32, 32, 3)
    block = basic.ConvBlock()
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, ak.Input(shape=input_shape).build())

    assert utils.name_in_hps('kernel_size', hp)
    assert utils.name_in_hps('num_blocks', hp)
    assert utils.name_in_hps('separable', hp)
Exemplo n.º 13
0
def test_resnet_block(init, build):
    input_shape = (32, 32, 3)
    block = basic.ResNetBlock()
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, ak.Input(shape=input_shape).build())

    assert utils.name_in_hps('version', hp)
    assert utils.name_in_hps('pooling', hp)
    assert init.called
    assert build.called
Exemplo n.º 14
0
def test_merge():
    input_shape_1 = (32, )
    input_shape_2 = (4, 8)
    block = reduction.Merge()
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, [
        ak.Input(shape=input_shape_1).build(),
        ak.Input(shape=input_shape_2).build()
    ])

    assert utils.name_in_hps('merge_type', hp)
Exemplo n.º 15
0
def test_xception_block(init, build):
    input_shape = (32, 32, 3)
    block = basic.XceptionBlock()
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.build(hp, ak.Input(shape=input_shape).build())

    assert utils.name_in_hps('activation', hp)
    assert utils.name_in_hps('initial_strides', hp)
    assert utils.name_in_hps('num_residual_blocks', hp)
    assert utils.name_in_hps('pooling', hp)
    assert init.called
    assert build.called
Exemplo n.º 16
0
def test_structured_data_block():
    block = wrapper.StructuredDataBlock()
    block.column_names = ['0', '1']
    block.column_types = {
        '0': adapters.CATEGORICAL,
        '1': adapters.CATEGORICAL,
    }
    hp = kerastuner.HyperParameters()

    block = graph_module.deserialize(graph_module.serialize(block))
    block.column_names = ['0', '1']
    block.column_types = {
        '0': adapters.CATEGORICAL,
        '1': adapters.CATEGORICAL,
    }
    output = block.build(hp, ak.StructuredDataInput(shape=(2, )).build())

    assert isinstance(output, tf.Tensor)
Exemplo n.º 17
0
def test_timeseries_block():
    block = wrapper.TimeseriesBlock()
    hp = kerastuner.HyperParameters()
    block.column_names = ['0', '1']
    block.column_types = {
        '0': adapters.NUMERICAL,
        '1': adapters.NUMERICAL,
    }
    block = graph_module.deserialize(graph_module.serialize(block))

    block.column_names = ['0', '1']
    block.column_types = {
        '0': adapters.NUMERICAL,
        '1': adapters.NUMERICAL,
    }
    output = block.build(hp,
                         ak.TimeseriesInput(shape=(32, ), lookback=2).build())

    assert isinstance(output, tf.Tensor)
Exemplo n.º 18
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self._finished = False
     # Save or load the HyperModel.
     utils.save_json(os.path.join(self.directory, 'graph'),
                     graph_module.serialize(self.hypermodel.hypermodel))