def test_text_block(): block = wrapper.TextBlock() hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) block.build(hp, ak.TextInput(shape=(1, )).build()) assert utils.name_in_hps('vectorizer', hp)
def test_time_series_input_node(): # TODO. Change test once TimeSeriesBlock is added. node = ak.TimeseriesInput(shape=(32, ), lookback=2) output = node.build() assert isinstance(output, tf.Tensor) node = graph_module.deserialize(graph_module.serialize(node)) output = node.build() assert isinstance(output, tf.Tensor)
def test_spatial_reduction(): input_shape = (32, 32, 3) block = reduction.SpatialReduction() hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) block.build(hp, ak.Input(shape=input_shape).build()) assert utils.name_in_hps('reduction_type', hp)
def block_basic_exam(block, inputs, hp_names): hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) outputs = block.build(hp, inputs) for hp_name in hp_names: assert name_in_hps(hp_name, hp) return outputs
def test_image_block(): block = wrapper.ImageBlock(normalize=None, augment=None) hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) block.build(hp, ak.ImageInput(shape=(32, 32, 3)).build()) assert utils.name_in_hps('block_type', hp) assert utils.name_in_hps('normalize', hp) assert utils.name_in_hps('augment', hp)
def test_imag_augmentation(): input_shape = (32, 32, 3) block = preprocessing.ImageAugmentation() hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) block.build(hp, ak.Input(shape=input_shape).build()) assert utils.name_in_hps('vertical_flip', hp) assert utils.name_in_hps('horizontal_flip', hp)
def test_dense_block(): input_shape = (32, ) block = basic.DenseBlock() hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) block.build(hp, ak.Input(shape=input_shape).build()) assert utils.name_in_hps('num_layers', hp) assert utils.name_in_hps('use_batchnorm', hp)
def test_segmentation(): y = np.array(['a', 'a', 'c', 'b']) head = head_module.SegmentationHead(name='a') adapter = head.get_adapter() adapter.fit_transform(y) head.config_from_adapter(adapter) input_shape = (64, 64, 21) hp = kerastuner.HyperParameters() head = graph_module.deserialize(graph_module.serialize(head)) head.build(hp, ak.Input(shape=input_shape).build())
def test_embedding_block(): input_shape = (32, ) block = basic.Embedding() block.max_features = 100 hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) block.build(hp, ak.Input(shape=input_shape).build()) assert utils.name_in_hps('pretraining', hp) assert utils.name_in_hps('embedding_dim', hp)
def test_rnn_block(): input_shape = (32, 10) block = basic.RNNBlock() hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) block.build(hp, ak.Input(shape=input_shape).build()) assert utils.name_in_hps('bidirectional', hp) assert utils.name_in_hps('layer_type', hp) assert utils.name_in_hps('num_layers', hp)
def test_conv_block(): input_shape = (32, 32, 3) block = basic.ConvBlock() hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) 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)
def test_resnet_block(init, build): input_shape = (32, 32, 3) block = basic.ResNetBlock() hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) block.build(hp, ak.Input(shape=input_shape).build()) assert utils.name_in_hps('version', hp) assert utils.name_in_hps('pooling', hp) assert init.called assert build.called
def test_merge(): input_shape_1 = (32, ) input_shape_2 = (4, 8) block = reduction.Merge() hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) block.build(hp, [ ak.Input(shape=input_shape_1).build(), ak.Input(shape=input_shape_2).build() ]) assert utils.name_in_hps('merge_type', hp)
def test_xception_block(init, build): input_shape = (32, 32, 3) block = basic.XceptionBlock() hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) 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
def test_structured_data_block(): block = wrapper.StructuredDataBlock() block.column_names = ['0', '1'] block.column_types = { '0': adapters.CATEGORICAL, '1': adapters.CATEGORICAL, } hp = kerastuner.HyperParameters() block = graph_module.deserialize(graph_module.serialize(block)) block.column_names = ['0', '1'] block.column_types = { '0': adapters.CATEGORICAL, '1': adapters.CATEGORICAL, } output = block.build(hp, ak.StructuredDataInput(shape=(2, )).build()) assert isinstance(output, tf.Tensor)
def test_timeseries_block(): block = wrapper.TimeseriesBlock() hp = kerastuner.HyperParameters() block.column_names = ['0', '1'] block.column_types = { '0': adapters.NUMERICAL, '1': adapters.NUMERICAL, } block = graph_module.deserialize(graph_module.serialize(block)) block.column_names = ['0', '1'] block.column_types = { '0': adapters.NUMERICAL, '1': adapters.NUMERICAL, } output = block.build(hp, ak.TimeseriesInput(shape=(32, ), lookback=2).build()) assert isinstance(output, tf.Tensor)