Example #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
Example #2
0
def test_conv_block():
    utils.block_basic_exam(
        basic.ConvBlock(),
        tf.keras.Input(shape=(32, 32, 3), dtype=tf.float32),
        [
            'kernel_size',
            'num_blocks',
            'separable',
        ])
def test_conv_block():
    input_shape = (32, 32, 3)
    block = basic.ConvBlock()
    hp = kerastuner.HyperParameters()

    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)
Example #4
0
 def build(self, hp, inputs=None):
     input_node = nest.flatten(inputs)[0]
     output_node = input_node
     vectorizer = self.vectorizer or hp.Choice('vectorizer',
                                               ['sequence', 'ngram'],
                                               default='sequence')
     if vectorizer == 'ngram':
         output_node = preprocessing.TextToNgramVector().build(hp, output_node)
         output_node = basic.DenseBlock().build(hp, output_node)
     else:
         output_node = preprocessing.TextToIntSequence().build(hp, output_node)
         output_node = basic.Embedding(
             pretraining=self.pretraining).build(hp, output_node)
         output_node = basic.ConvBlock().build(hp, output_node)
         output_node = reduction.SpatialReduction().build(hp, output_node)
         output_node = basic.DenseBlock().build(hp, output_node)
     return output_node
def test_type_error_for_call():
    block = basic.ConvBlock()
    with pytest.raises(TypeError) as info:
        block(block)
    assert 'Expect the inputs to layer' in str(info.value)