test_eddl.cpp
Go to the documentation of this file.
1  /*
2 * ECVL - European Computer Vision Library
3 * Version: 0.3.4
4 * copyright (c) 2021, Università degli Studi di Modena e Reggio Emilia (UNIMORE), AImageLab
5 * Authors:
6 * Costantino Grana (costantino.grana@unimore.it)
7 * Federico Bolelli (federico.bolelli@unimore.it)
8 * Michele Cancilla (michele.cancilla@unimore.it)
9 * Laura Canalini (laura.canalini@unimore.it)
10 * Stefano Allegretti (stefano.allegretti@unimore.it)
11 * All rights reserved.
12 */
13 
14 #include <gtest/gtest.h>
15 
16 #include <sstream>
17 
18 #include "ecvl/support_eddl.h"
19 #include "ecvl/augmentations.h"
20 
21 using namespace ecvl;
22 
23 TEST(Augmentations, ConstructFromStreamAllParamsOk)
24 {
25  Image img({ 5, 5, 1 }, DataType::uint8, "xyc", ColorType::GRAY);
26  std::unique_ptr<Augmentation> p;
27  std::stringstream ss("angle=[-5,5] center=(0,0) scale=0.5 interp=\"linear\"");
28  EXPECT_NO_THROW(p = make_unique<AugRotate>(ss));
29  EXPECT_NO_THROW(p->Apply(img));
30  ss = std::stringstream("dims=(100,100) interp=\"linear\"");
31  EXPECT_NO_THROW(p = make_unique<AugResizeDim>(ss));
32  EXPECT_NO_THROW(p->Apply(img));
33  ss = std::stringstream("scale=(1.,2.) interp=\"linear\"");
34  EXPECT_NO_THROW(p = make_unique<AugResizeScale>(ss));
35  EXPECT_NO_THROW(p->Apply(img));
36  ss = std::stringstream("p=0.3");
37  EXPECT_NO_THROW(p = make_unique<AugFlip>(ss));
38  EXPECT_NO_THROW(p->Apply(img));
39  ss = std::stringstream("p=0.3");
40  EXPECT_NO_THROW(p = make_unique<AugMirror>(ss));
41  EXPECT_NO_THROW(p->Apply(img));
42  ss = std::stringstream("sigma=[1.,2.]");
43  EXPECT_NO_THROW(p = make_unique<AugGaussianBlur>(ss));
44  EXPECT_NO_THROW(p->Apply(img));
45  ss = std::stringstream("std_dev=[1.,2.]");
46  EXPECT_NO_THROW(p = make_unique<AugAdditiveLaplaceNoise>(ss));
47  EXPECT_NO_THROW(p->Apply(img));
48  ss = std::stringstream("lambda=[1.,2.]");
49  EXPECT_NO_THROW(p = make_unique<AugAdditivePoissonNoise>(ss));
50  EXPECT_NO_THROW(p->Apply(img));
51  ss = std::stringstream("gamma=[1.,2.]");
52  EXPECT_NO_THROW(p = make_unique<AugGammaContrast>(ss));
53  EXPECT_NO_THROW(p->Apply(img));
54  ss = std::stringstream("p=[0,0.55] drop_size=[0.02,0.1] per_channel=0");
55  EXPECT_NO_THROW(p = make_unique<AugCoarseDropout>(ss));
56  EXPECT_NO_THROW(p->Apply(img));
57  ss = std::stringstream("p=0.4");
58  EXPECT_NO_THROW(p = make_unique<AugTranspose>(ss));
59  EXPECT_NO_THROW(p->Apply(img));
60  ss = std::stringstream("beta=[30,60]");
61  EXPECT_NO_THROW(p = make_unique<AugBrightness>(ss));
62  EXPECT_NO_THROW(p->Apply(img));
63  ss = std::stringstream("num_steps=[5,10] distort_limit=[-0.2,0.2] interp=\"linear\" border_type=\"reflect_101\" border_value=0");
64  EXPECT_NO_THROW(p = make_unique<AugGridDistortion>(ss));
65  EXPECT_NO_THROW(p->Apply(img));
66  ss = std::stringstream("alpha=[34,60] sigma=[4,6] interp=\"linear\" border_type=\"reflect_101\" border_value=0");
67  EXPECT_NO_THROW(p = make_unique<AugElasticTransform>(ss));
68  EXPECT_NO_THROW(p->Apply(img));
69 }
70 
71 TEST(Augmentations, ConstructFromStreamWithoutOptionalParms)
72 {
73  Image img({ 5, 5, 1 }, DataType::uint8, "xyc", ColorType::GRAY);
74  std::unique_ptr<Augmentation> p;
75  std::stringstream ss("angle=[-5,5]");
76  EXPECT_NO_THROW(p = make_unique<AugRotate>(ss));
77  EXPECT_NO_THROW(p->Apply(img));
78  ss = std::stringstream("dims=(100,100)");
79  EXPECT_NO_THROW(p = make_unique<AugResizeDim>(ss));
80  EXPECT_NO_THROW(p->Apply(img));
81  ss = std::stringstream("scale=(1.,2.)");
82  EXPECT_NO_THROW(p = make_unique<AugResizeScale>(ss));
83  EXPECT_NO_THROW(p->Apply(img));
84  ss = std::stringstream("");
85  EXPECT_NO_THROW(p = make_unique<AugFlip>(ss));
86  EXPECT_NO_THROW(p->Apply(img));
87  ss = std::stringstream("");
88  EXPECT_NO_THROW(p = make_unique<AugMirror>(ss));
89  EXPECT_NO_THROW(p->Apply(img));
90  ss = std::stringstream("");
91  EXPECT_NO_THROW(p = make_unique<AugTranspose>(ss));
92  EXPECT_NO_THROW(p->Apply(img));
93  ss = std::stringstream("beta=[30,60]");
94  EXPECT_NO_THROW(p = make_unique<AugBrightness>(ss));
95  EXPECT_NO_THROW(p->Apply(img));
96  ss = std::stringstream("num_steps=[5,10] distort_limit=[-0.2,0.2]");
97  EXPECT_NO_THROW(p = make_unique<AugGridDistortion>(ss));
98  EXPECT_NO_THROW(p->Apply(img));
99  ss = std::stringstream("alpha=[34,60] sigma=[4,6]");
100  EXPECT_NO_THROW(p = make_unique<AugElasticTransform>(ss));
101  EXPECT_NO_THROW(p->Apply(img));
102 }
103 
104 TEST(Augmentations, ConstructFromStreamWithWrongParms)
105 {
106  Image img({ 5, 5, 1 }, DataType::uint8, "xyc", ColorType::GRAY);
107  std::unique_ptr<Augmentation> p;
108  std::stringstream ss("angle=(-5,5)");
109  EXPECT_THROW(p = make_unique<AugRotate>(ss), std::runtime_error);
110  ss = std::stringstream("dims=100");
111  EXPECT_THROW(p = make_unique<AugResizeDim>(ss), std::runtime_error);
112  ss = std::stringstream("");
113  EXPECT_THROW(p = make_unique<AugResizeScale>(ss), std::runtime_error);
114  ss = std::stringstream("p=\"test\"");
115  EXPECT_THROW(p = make_unique<AugFlip>(ss), std::runtime_error);
116  ss = std::stringstream("");
117  EXPECT_THROW(p = make_unique<AugBrightness>(ss), std::runtime_error);
118  ss = std::stringstream("num_steps=[5,10] distort_limit=(-0.2,0.2)");
119  EXPECT_THROW(p = make_unique<AugGridDistortion>(ss), std::runtime_error);
120  ss = std::stringstream("alpha=34");
121  EXPECT_THROW(p = make_unique<AugElasticTransform>(ss), std::runtime_error);
122 }
Image class.
Definition: image.h:72
TEST(Augmentations, ConstructFromStreamAllParamsOk)
Definition: test_eddl.cpp:23