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 not isinstance(input_node, node_module.TextNode): raise ValueError('The input_node should be a TextNode.') if vectorizer == 'ngram': output_node = preprocessor_module.TextToNgramVector()(output_node) output_node = block_module.DenseBlock()(output_node) else: output_node = preprocessor_module.TextToIntSequence()(output_node) output_node = block_module.EmbeddingBlock( pretraining=self.pretraining)(output_node) output_node = block_module.ConvBlock(separable=True)(output_node) output_node = block_module.SpatialReduction()(output_node) output_node = block_module.DenseBlock()(output_node) return output_node
def test_dense_block(): input_shape = (32, ) block = block_module.DenseBlock() hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) assert name_in_hps('num_layers', hp) assert name_in_hps('use_batchnorm', hp)
def assemble(self, input_node): output_node = input_node ratio = self.sw_ratio() if not isinstance(input_node, node.TextNode): raise ValueError('The input_node should be a TextNode.') if ratio < 1500: output_node = processor.TextToNgramVector()(output_node) output_node = block.DenseBlock()(output_node) else: output_node = processor.TextToIntSequence()(output_node) output_node = block.EmbeddingBlock( pretrained=(ratio < 15000))(output_node) output_node = block.ConvBlock(separable=True)(output_node) return output_node
def build_body(self, hp, input_node): if len(self.heads) > 1: module_type_choices = ['dense'] else: module_type_choices = ['lightgbm', 'dense'] module_type = self.module_type or hp.Choice( 'module_type', module_type_choices, default=module_type_choices[0]) if module_type == 'dense': output_node = block.DenseBlock()(input_node) elif module_type == 'lightgbm': output_node = preprocessor.LightGBMBlock( seed=self.seed)(input_node) else: raise ValueError( 'Unsupported module' 'type: {module_type}'.format(module_type=module_type)) nest.flatten(output_node)[0].shape = self.output_shape return output_node
def build_body(self, hp, input_node): if self.num_heads > 1: block_type = ['dense'] else: block_type = ['lightgbm', 'dense'] block_type = self.block_type or hp.Choice('block_type', block_type, default=block_type[0]) if block_type == 'dense': output_node = block_module.DenseBlock()(input_node) elif block_type == 'lightgbm': output_node = preprocessor_module.LightGBM( seed=self.seed)(input_node) else: raise ValueError('Expect the block_type to be "dense" or "lightgbm", ' 'but got {block_type}'.format(block_type=block_type)) nest.flatten(output_node)[0].shape = self.output_shape return output_node
def assemble(self, input_node): block = hyperblock.ImageBlock(seed=self.seed) if max(self._shape[0], self._shape[1]) < 32: if self._num_samples < 10000: self.hps.append(hp_module.Choice( block.name + '_resnet/v1/conv4_depth', [6], default=6)) self.hps.append(hp_module.Choice( block.name + '_resnet/v2/conv4_depth', [6], default=6)) self.hps.append(hp_module.Choice( block.name + '_resnet/next/conv4_depth', [6], default=6)) self.hps.append(hp_module.Int( block.name + '_xception/num_residual_blocks', 2, 4, default=4)) output_node = block(input_node) output_node = block_module.SpatialReduction()(output_node) return block_module.DenseBlock()(output_node)