Beispiel #1
0
    def build(self, hp, inputs=None):
        input_node = nest.flatten(inputs)[0]
        output_node = input_node

        block_type = self.block_type or hp.Choice(
            'block_type', ['resnet', 'xception', 'vanilla'], default='vanilla')

        normalize = self.normalize
        if normalize is None:
            normalize = hp.Boolean('normalize', default=False)
        augment = self.augment
        if augment is None:
            augment = hp.Boolean('augment', default=False)
        if normalize:
            output_node = preprocessing.Normalization().build(hp, output_node)
        if augment:
            output_node = preprocessing.ImageAugmentation().build(
                hp, output_node)
        if block_type == 'resnet':
            output_node = basic.ResNetBlock().build(hp, output_node)
        elif block_type == 'xception':
            output_node = basic.XceptionBlock().build(hp, output_node)
        elif block_type == 'vanilla':
            output_node = basic.ConvBlock().build(hp, output_node)
        return output_node
Beispiel #2
0
def test_xception_block(init, build):
    utils.block_basic_exam(
        basic.XceptionBlock(),
        tf.keras.Input(shape=(32, 32, 3), dtype=tf.float32),
        [
            'activation',
            'initial_strides',
            'num_residual_blocks',
            'pooling',
        ])
    assert init.called
    assert build.called
def test_xception_block(init, build):
    input_shape = (32, 32, 3)
    block = basic.XceptionBlock()
    hp = kerastuner.HyperParameters()

    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