def test_number_input_feature(
    number_config: Dict,
) -> None:
    # setup image input feature definition
    number_def = deepcopy(number_config)

    # pickup any other missing parameters
    NumberInputFeature.populate_defaults(number_def)

    # ensure no exceptions raised during build
    input_feature_obj = ECD.build_single_input(number_def, None).to(DEVICE)

    # check one forward pass through input feature
    input_tensor = torch.rand(2, dtype=torch.float32).to(DEVICE)

    encoder_output = input_feature_obj(input_tensor)
    assert encoder_output["encoder_output"].shape == (BATCH_SIZE, *input_feature_obj.output_shape)
Beispiel #2
0
def test_image_input_feature(image_config: Dict, encoder: str, height: int, width: int, num_channels) -> None:
    # setup image input feature definition
    image_def = deepcopy(image_config)
    image_def["encoder"] = encoder
    image_def["height"] = height
    image_def["width"] = width
    image_def["num_channels"] = num_channels

    # pickup any other missing parameters
    ImageInputFeature.populate_defaults(image_def)

    # ensure no exceptions raised during build
    input_feature_obj = ECD.build_single_input(image_def, None)

    # check one forward pass through input feature
    input_tensor = torch.randint(0, 256, size=(BATCH_SIZE, num_channels, height, width), dtype=torch.uint8)

    encoder_output = input_feature_obj(input_tensor)
    assert encoder_output["encoder_output"].shape == (BATCH_SIZE, *input_feature_obj.output_shape)
def test_category_input_feature(
    category_config: Dict,
    encoder: str,
) -> None:
    # setup image input feature definition
    category_def = deepcopy(category_config)
    category_def["encoder"] = encoder

    # pickup any other missing parameters
    CategoryInputFeature.populate_defaults(category_def)

    # ensure no exceptions raised during build
    input_feature_obj = ECD.build_single_input(category_def, None)

    # check one forward pass through input feature
    input_tensor = torch.randint(0, 3, size=(BATCH_SIZE,), dtype=torch.int32).to(DEVICE)

    encoder_output = input_feature_obj(input_tensor)
    assert encoder_output["encoder_output"].shape == (BATCH_SIZE, *input_feature_obj.output_shape)
Beispiel #4
0
def test_set_input_feature(set_config: Dict, ) -> None:
    # setup image input feature definition
    set_def = deepcopy(set_config)

    # pickup any other missing parameters
    SetInputFeature.populate_defaults(set_def)

    # ensure no exceptions raised during build
    input_feature_obj = ECD.build_single_input(set_def, None).to(DEVICE)

    # check one forward pass through input feature
    input_tensor = torch.randint(0,
                                 2,
                                 size=(BATCH_SIZE, len(set_def["vocab"])),
                                 dtype=torch.int64).to(DEVICE)

    encoder_output = input_feature_obj(input_tensor)
    assert encoder_output["encoder_output"].shape == (
        BATCH_SIZE, *input_feature_obj.output_shape)