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='resnet') normalize = self.normalize if normalize is None: normalize = hp.Choice('normalize', [True, False], default=True) augment = self.augment if augment is None: augment = hp.Choice('augment', [True, False], default=True) if normalize: output_node = preprocessor.Normalization()(output_node) if augment: output_node = preprocessor.ImageAugmentation( seed=self.seed)(output_node) sub_block_name = self.name + '_' + block_type if block_type == 'resnet': output_node = block.ResNetBlock(name=sub_block_name)(output_node) elif block_type == 'xception': output_node = block.XceptionBlock(name=sub_block_name)(output_node) elif block_type == 'vanilla': output_node = block.ConvBlock(name=sub_block_name)(output_node) return output_node
def test_xception_block(init, build): input_shape = (32, 32, 3) block = block_module.XceptionBlock() hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) assert name_in_hps('activation', hp) assert name_in_hps('initial_strides', hp) assert name_in_hps('num_residual_blocks', hp) assert name_in_hps('pooling', hp) assert init.called assert build.called
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='resnet') if block_type == 'resnet': output_node = block.ResNetBlock()(output_node) elif block_type == 'xception': output_node = block.XceptionBlock()(output_node) elif block_type == 'vanilla': output_node = block.ConvBlock().build(output_node) return output_node