예제 #1
0
def test_wrong_type_throws_exception():
    def f(_a):
        pass

    params = Params().add("a", "", int, 0)

    with pytest.raises(ValueError):
        params.call_with_params(f, {"a": "hello"})
예제 #2
0
def test_params_default_substitution_works():
    def f(a, b):
        assert a == 1
        assert b == 2

    params = Params().add("a", "", int, 1).add("b", "", int, 2)

    params.call_with_params(f, {"a": 1})
예제 #3
0
def test_unrecognized_param_throws_exception():
    def f(_a, _b):
        pass

    params = Params().add("a", "", int, 0).add("b", "", int, 0)

    with pytest.raises(ValueError):
        params.call_with_params(f, {"c": 3})
예제 #4
0
def test_missing_required_throws_exception():
    def f(_a):
        pass

    params = Params().add("a", "", int, 0, True)

    with pytest.raises(ValueError):
        params.call_with_params(f, {})
예제 #5
0
def test_ensure_conditions_checked():
    def f(_a):
        pass

    params = Params().add("a", "", int,
                          0).ensure(lambda params: params["a"] >= 0, "a >= 0")

    with pytest.raises(ValueError):
        params.call_with_params(f, {"a": -1})
예제 #6
0
def test_with_bound_type_cast_works():
    def type_cast(_v):
        raise RuntimeError("Should not be called")

    def actual_type_cast(v):
        return int(v)

    def f(a):
        assert a == 1

    params = Params().add("a", "", type_cast, 0)

    params.with_bound_type_cast(type_cast, actual_type_cast).call_with_params(
        f, {"a": "1"})
예제 #7
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add(
         "directory", "the directory to save images to", str, "", True).add(
             "clean_directory",
             "whether to forcibly ensure the output directory is empty",
             bool, True)
예제 #8
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("input_dim",
                         "The new length of the shortest dimension",
                         BoundedNumber(int, 0),
                         512).add("interpolation", "The interpolation type",
                                  InterpolationType, "INTER_LINEAR")
예제 #9
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("max_width",
                         "Maximum width of cropped area (normalized)",
                         BoundedNumber(float, 0, 1), 0.7).add(
                             "max_height",
                             "Maximum height of cropped area (normalized)",
                             BoundedNumber(float, 0, 1), 0.7)
예제 #10
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("annotations_folder",
                         "The folder where the annotations are stored", str,
                         "",
                         True).add("image_ext",
                                   "The file extension for loaded images",
                                   str, "jpg")
예제 #11
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add(
         "x_range", "normalized x range for coordinates that may be erased",
         NumericalRange(0.0, 1.0), (0.0, 1.0)).add(
             "y_range",
             "normalized y range for coordinates that may be erased",
             NumericalRange(0.0, 1.0), (0.0, 1.0))
예제 #12
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add(
         "angle_range",
         "The range from which the random angle will be chosen",
         NumericalRange(-360.0, 360.0),
         (-10.0, 10.0),
     )
예제 #13
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add(
         "strength",
         "Compression strength",
         BoundedNumber(int, 0, 100),
         1,
     )
예제 #14
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add(
         "annotations_folder",
         "the directory to save annotation files to", str, "", True).add(
             "database", "The name of the source database", str, "").add(
                 "clean_directory",
                 "whether to forcibly ensure the output directory is empty",
                 bool, True)
예제 #15
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add(
         "kernel_size",
         "Specify the kernel size, greater the size, the more the motion",
         BoundedNumber(int, minimum=0, maximum=None),
         10).add("direction",
                 "direction in which the blur is pointer towards",
                 Direction, 'DOWN')
예제 #16
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add(
         "annotations_file",
         "The path to the CSV file to write the annotations to", str, "",
         True
     ).add(
         "normalized",
         "whether the bounding box coordinates should be normalized before "
         "saving", bool, True)
예제 #17
0
 def params():
     """Return a Params object describing constructor parameters."""
     
     return (
         Params()
         .add("mean", "", NumericalRange(), (0.485, 0.456, 0.406))
         .add("std", "", NumericalRange(), (0.229, 0.224, 0.225))
         # Note to user, it will not make sense to tune max_pixel_value to a too small value.
         .add("max_pixel_value", "", NumericalRange(), (0.0, 255.0))
     )
예제 #18
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("height", "The height of the resized image",
                         BoundedNumber(int, 0),
                         512).add("width", "the width of the resized image",
                                  BoundedNumber(int, 0),
                                  512).add("interpolation",
                                           "The interpolation type",
                                           InterpolationType,
                                           "INTER_LINEAR")
예제 #19
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("replace_probs", "", float,
                         0.1).add("pepper", "The color of the pepper",
                                  BoundedNumber(int, 0, 255),
                                  0).add("salt", "The color of the salt",
                                         BoundedNumber(int, 0, 255),
                                         255).add("noise_type",
                                                  "The type of noise",
                                                  NoiseType, "RGB")
예제 #20
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add(
         "annotations_file",
         "The path to the CSV file containing the annotations", str, "",
         True
     ).add(
         "normalized",
         "whether the bounding box coordinates are stored in a normalized "
         "format", bool, True)
예제 #21
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("hue", "", NumericalRange(), (0.0, 0.0)).add(
         "saturation", "", NumericalRange(),
         (0.0, 0.0)).add("brightness", "", NumericalRange(), (0.0, 0.0))
예제 #22
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("translate_range",
                         "The translate range should be within 0 and 1",
                         NumericalRange(0, 1), (0.2, 0.2))
예제 #23
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("augmentations", "", augmentation_list, [])
예제 #24
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params()
예제 #25
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("annotations_folder",
                         "The folder where the annotations are stored", str,
                         "", True)
예제 #26
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("angle", "", float, 5)
예제 #27
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add(
         "annotations_file",
         "The path to the JSON file containing the annotations", str, "",
         True)
예제 #28
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("scale_x", "", BoundedNumber(float, -1.0),
                         0.2).add("scale_y", "", BoundedNumber(float, -1.0),
                                  0.2)
예제 #29
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("shear_factor", "", float, 0.2)
예제 #30
0
 def params():
     """Return a Params object describing constructor parameters."""
     return Params().add("mean", "", float, 0).add("variance", "", float,
                                                   0.01)