def test_image_block(): block = hyperblock_module.ImageBlock(normalize=None, augment=None) block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input()) assert common.name_in_hps('block_type', hp) assert common.name_in_hps('normalize', hp) assert common.name_in_hps('augment', hp)
def test_dense_block(): input_shape = (32,) block = block_module.DenseBlock() block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) assert common.name_in_hps('num_layers', hp) assert common.name_in_hps('use_batchnorm', hp)
def test_rnn_block(): input_shape = (32, 10) block = block_module.RNNBlock() block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) assert common.name_in_hps('bidirectional', hp) assert common.name_in_hps('layer_type', hp) assert common.name_in_hps('num_layers', hp)
def test_conv_block(): input_shape = (32, 32, 3) block = block_module.ConvBlock() block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) assert common.name_in_hps('kernel_size', hp) assert common.name_in_hps('num_blocks', hp) assert common.name_in_hps('separable', hp)
def test_embedding_block(): input_shape = (32,) block = block_module.EmbeddingBlock() block.max_features = 100 block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) assert common.name_in_hps('pretraining', hp) assert common.name_in_hps('embedding_dim', hp)
def test_resnet_block(init, build): input_shape = (32, 32, 3) block = block_module.ResNetBlock() block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) assert common.name_in_hps('version', hp) assert common.name_in_hps('pooling', hp) assert init.called assert build.called
def test_xception_block(init, build): input_shape = (32, 32, 3) block = block_module.XceptionBlock() block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) assert common.name_in_hps('activation', hp) assert common.name_in_hps('initial_strides', hp) assert common.name_in_hps('num_residual_blocks', hp) assert common.name_in_hps('pooling', hp) assert init.called assert build.called
def test_embedding_block_with_pretraining(get_file, load_embedding_index): load_embedding_index.return_value = {'test': np.ones((100, ))} get_file.return_value = '' input_shape = (32, ) block = block_module.EmbeddingBlock(pretraining='glove') block.max_features = 2 block.word_index = {'test': 1} block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) embedding_matrix = block._build_embedding_matrix('glove') assert np.array_equal(embedding_matrix[1], np.ones((100, ))) assert not common.name_in_hps('pretraining', hp) assert not common.name_in_hps('embedding_dim', hp)
def test_text_block(): block = hyperblock_module.TextBlock() block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.TextInput()) assert common.name_in_hps('vectorizer', hp)
def test_spatial_reduction(): input_shape = (32, 32, 3) block = block_module.SpatialReduction() block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) assert common.name_in_hps('reduction_type', hp)
def test_structured_data_block(): block = hyperblock_module.StructuredDataBlock() block.num_heads = 1 block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input()) assert common.name_in_hps('block_type', hp)
def test_structured_data_block(): block = hyperblock_module.StructuredDataBlock() block.heads = [ak.ClassificationHead()] block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input()) assert common.name_in_hps('module_type', hp)
def test_temporal_reduction(): input_shape = (32, 10) block = block_module.TemporalReduction() block.set_config(block.get_config()) hp = kerastuner.HyperParameters() block.build(hp, ak.Input(shape=input_shape).build()) assert common.name_in_hps('reduction_type', hp)
def test_merge(): input_shape_1 = (32,) input_shape_2 = (4, 8) block = block_module.Merge() block.set_state(block.get_state()) hp = kerastuner.HyperParameters() block.build(hp, [ak.Input(shape=input_shape_1).build(), ak.Input(shape=input_shape_2).build()]) assert common.name_in_hps('merge_type', hp)