예제 #1
0
def test_restrict_crop_size_too_small() -> None:
    """Test the modification of crop sizes when the image size is below the minimum."""
    shape = (10, 30, 40)
    crop_size = (20, 40, 20)
    stride = (10, 20, 20)
    constraint = CropSizeConstraints(multiple_of=16)
    with pytest.raises(ValueError) as e:
        constraint.restrict_crop_size_to_image(shape, crop_size, stride)
    # Error message should contain the actual image size
    assert str(shape) in e.value.args[0]
    assert "16" in e.value.args[0]
예제 #2
0
def check_restrict_crop(constraint: CropSizeConstraints, shape: TupleInt3,
                        crop_size: TupleInt3, stride: TupleInt3,
                        expected_crop: TupleInt3,
                        expected_stride: TupleInt3) -> None:
    (crop_new, stride_new) = constraint.restrict_crop_size_to_image(
        shape, crop_size, stride)
    assert crop_new == expected_crop
    assert stride_new == expected_stride
    # Stride and crop must be integer tuples
    assert isinstance(crop_new[0], int)
    assert isinstance(stride_new[0], int)