-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathpreprocessor_intput_test.py
144 lines (122 loc) · 6.63 KB
/
preprocessor_intput_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""Tests for object_detection.core.preprocessor_input.
This code referred to preprocessor_test.py
"""
# Author: Jamyoung Koo
# Date created: 2018.02.21
# Date last modified: 2018.05.14
# Python Version: 3.5
import tensorflow as tf
from core import standard_fields as fields
from core import preprocessor_input
class PreprocessorTest(tf.test.TestCase):
def createTestImages(self):
images_r = tf.constant([[[128, 128, 128, 128], [0, 0, 128, 128],
[0, 128, 128, 128], [192, 192, 128, 128]]],
dtype=tf.float32)
images_r = tf.expand_dims(images_r, 3)
images_g = tf.constant([[[0, 0, 128, 128], [0, 0, 128, 128],
[0, 128, 192, 192], [192, 192, 128, 192]]],
dtype=tf.float32)
images_g = tf.expand_dims(images_g, 3)
images_b = tf.constant([[[128, 128, 192, 0], [0, 0, 128, 192],
[0, 128, 128, 0], [192, 192, 192, 128]]],
dtype=tf.float32)
images_b = tf.expand_dims(images_b, 3)
images = tf.concat([images_r, images_g, images_b], 3)
return images
def expectedImagesAfterNormalizationTiff(self):
images_r = tf.constant([[[127.5, 127.5, 127.5, 127.5], [0, 0, 127.5, 127.5],
[0, 127.5, 127.5, 127.5], [255, 255, 127.5, 127.5]]],
dtype=tf.float32)
images_r = tf.expand_dims(images_r, 3)
images_g = tf.constant([[[0, 0, 127.5, 127.5], [0, 0, 127.5, 127.5],
[0, 127.5, 255, 255], [255, 255, 127.5, 255]]],
dtype=tf.float32)
images_g = tf.expand_dims(images_g, 3)
images_b = tf.constant([[[127.5, 127.5, 255, 0], [0, 0, 127.5, 255],
[0, 127.5, 127.5, 0], [255, 255, 255, 127.5]]],
dtype=tf.float32)
images_b = tf.expand_dims(images_b, 3)
images = tf.concat([images_r, images_g, images_b], 3)
return images
def createTestImagesK3(self):
images_r = tf.constant([[[2905, 2905, 2905, 2905], [984, 984, 2905, 2905],
[984, 2905, 2905, 2905], [4826, 4826, 2905, 2905]]],
dtype=tf.float32)
images_r = tf.expand_dims(images_r, 3)
images_g = tf.constant([[[1405, 1405, 2820.5, 2820.5], [1405, 1405, 2820.5, 2820.5],
[1405, 2820.5, 4236, 4236], [4236, 4236, 2820.5, 4236]]],
dtype=tf.float32)
images_g = tf.expand_dims(images_g, 3)
images_b = tf.constant([[[4676.5, 4676.5, 6581, 2772], [2772, 2772, 4676.5, 6581],
[2772, 4676.5, 4676.5, 2772], [6581, 6581, 6581, 4676.5]]],
dtype=tf.float32)
images_b = tf.expand_dims(images_b, 3)
images = tf.concat([images_r, images_g, images_b], 3)
return images
def createTestRBoxes(self):
rboxes = tf.constant(
[[0.0, 0.25, 0.75, 1.0, -1.0], [0.25, 0.5, 0.75, 1.0, 0.2]], dtype=tf.float32)
return rboxes
def expectedRBoxesSwapHeightWidth(self):
rboxes = tf.constant(
[[0.0, 0.25, 1.0, 0.75, -1.0], [0.25, 0.5, 1.0, 0.75, 0.2]], dtype=tf.float32)
return rboxes
def expectedRBoxesSubtractAngle(self):
rboxes = tf.constant(
[[0.0, 0.25, 0.75, 1.0, -1.5], [0.25, 0.5, 0.75, 1.0, -0.3]], dtype=tf.float32)
return rboxes
def testSwapHeightWidthOfRboxes(self):
rboxes = self.createTestRBoxes()
rboxes_expected = self.expectedRBoxesSwapHeightWidth()
swapped_rbboxes = preprocessor_input.swap_height_width_of_rboxes(rboxes)
with self.test_session() as sess:
swapped_rbboxes, rboxes_expected = sess.run([swapped_rbboxes, rboxes_expected])
self.assertAllEqual(swapped_rbboxes, rboxes_expected)
def testSubtractAngleOfRboxes(self):
rboxes = self.createTestRBoxes()
rboxes_expected = self.expectedRBoxesSubtractAngle()
subtracted_rbboxes = preprocessor_input.subtract_angle_of_rboxes(rboxes, 0.5)
with self.test_session() as sess:
subtracted_rbboxes, rboxes_expected = sess.run([subtracted_rbboxes, rboxes_expected])
self.assertAllEqual(subtracted_rbboxes, rboxes_expected)
def testNormalizeTiffOfK3(self):
preprocess_options = [(preprocessor_input.normalize_tiff, {})]
images = self.createTestImagesK3()
tensor_dict = {fields.InputDataFields.image: images,
fields.InputDataFields.sensor: 'K3'}
tensor_dict = preprocessor_input.preprocess(tensor_dict, preprocess_options)
images = tensor_dict[fields.InputDataFields.image]
images_expected = self.expectedImagesAfterNormalizationTiff()
with self.test_session() as sess:
(images_, images_expected_) = sess.run([images, images_expected])
images_shape_ = images_.shape
images_expected_shape_ = images_expected_.shape
expected_shape = [1, 4, 4, 3]
self.assertAllEqual(images_expected_shape_, images_shape_)
self.assertAllEqual(images_shape_, expected_shape)
self.assertAllClose(images_, images_expected_)
def testCutoffMaxGTs(self):
preprocess_options = [(preprocessor_input.cutoff_max_gts, {'max_gts': 4})]
image = self.createTestImages()
rboxes = tf.constant([[0, 0, 1, 1, 0.1],
[1, 0.1, 1, 1.1, 0.2],
[2, -0.1, 1, 0.9, 0.3],
[3, 10, 1, 11, 0.4],
[4, 10.1, 1, 11.1, 0.5],
[5, 100, 1, 101, 0.6]], tf.float32)
classes = tf.constant([0, 1, 2, 3, 4, 5])
tensor_dict = {fields.InputDataFields.image: image,
fields.InputDataFields.groundtruth_rboxes: rboxes,
fields.InputDataFields.groundtruth_classes: classes}
tensor_dict = preprocessor_input.preprocess(tensor_dict, preprocess_options)
image = tensor_dict[fields.InputDataFields.image]
rboxes = tensor_dict[fields.InputDataFields.groundtruth_rboxes]
classes = tensor_dict[fields.InputDataFields.groundtruth_classes]
with self.test_session() as sess:
(image, rboxes_, classes_) = sess.run([image, rboxes, classes])
self.assertAllEqual(rboxes_.shape[0], 4)
self.assertAllEqual(classes_.shape[0], 4)
self.assertAllEqual(rboxes_[:, 0], classes_)
if __name__ == '__main__':
tf.test.main()