You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

627 lines
23 KiB

6 years ago
  1. # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ==============================================================================
  15. """Tests for preprocessor_builder."""
  16. import tensorflow as tf
  17. from google.protobuf import text_format
  18. from object_detection.builders import preprocessor_builder
  19. from object_detection.core import preprocessor
  20. from object_detection.protos import preprocessor_pb2
  21. class PreprocessorBuilderTest(tf.test.TestCase):
  22. def assert_dictionary_close(self, dict1, dict2):
  23. """Helper to check if two dicts with floatst or integers are close."""
  24. self.assertEqual(sorted(dict1.keys()), sorted(dict2.keys()))
  25. for key in dict1:
  26. value = dict1[key]
  27. if isinstance(value, float):
  28. self.assertAlmostEqual(value, dict2[key])
  29. else:
  30. self.assertEqual(value, dict2[key])
  31. def test_build_normalize_image(self):
  32. preprocessor_text_proto = """
  33. normalize_image {
  34. original_minval: 0.0
  35. original_maxval: 255.0
  36. target_minval: -1.0
  37. target_maxval: 1.0
  38. }
  39. """
  40. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  41. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  42. function, args = preprocessor_builder.build(preprocessor_proto)
  43. self.assertEqual(function, preprocessor.normalize_image)
  44. self.assertEqual(args, {
  45. 'original_minval': 0.0,
  46. 'original_maxval': 255.0,
  47. 'target_minval': -1.0,
  48. 'target_maxval': 1.0,
  49. })
  50. def test_build_random_horizontal_flip(self):
  51. preprocessor_text_proto = """
  52. random_horizontal_flip {
  53. keypoint_flip_permutation: 1
  54. keypoint_flip_permutation: 0
  55. keypoint_flip_permutation: 2
  56. keypoint_flip_permutation: 3
  57. keypoint_flip_permutation: 5
  58. keypoint_flip_permutation: 4
  59. }
  60. """
  61. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  62. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  63. function, args = preprocessor_builder.build(preprocessor_proto)
  64. self.assertEqual(function, preprocessor.random_horizontal_flip)
  65. self.assertEqual(args, {'keypoint_flip_permutation': (1, 0, 2, 3, 5, 4)})
  66. def test_build_random_vertical_flip(self):
  67. preprocessor_text_proto = """
  68. random_vertical_flip {
  69. keypoint_flip_permutation: 1
  70. keypoint_flip_permutation: 0
  71. keypoint_flip_permutation: 2
  72. keypoint_flip_permutation: 3
  73. keypoint_flip_permutation: 5
  74. keypoint_flip_permutation: 4
  75. }
  76. """
  77. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  78. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  79. function, args = preprocessor_builder.build(preprocessor_proto)
  80. self.assertEqual(function, preprocessor.random_vertical_flip)
  81. self.assertEqual(args, {'keypoint_flip_permutation': (1, 0, 2, 3, 5, 4)})
  82. def test_build_random_rotation90(self):
  83. preprocessor_text_proto = """
  84. random_rotation90 {}
  85. """
  86. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  87. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  88. function, args = preprocessor_builder.build(preprocessor_proto)
  89. self.assertEqual(function, preprocessor.random_rotation90)
  90. self.assertEqual(args, {})
  91. def test_build_random_pixel_value_scale(self):
  92. preprocessor_text_proto = """
  93. random_pixel_value_scale {
  94. minval: 0.8
  95. maxval: 1.2
  96. }
  97. """
  98. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  99. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  100. function, args = preprocessor_builder.build(preprocessor_proto)
  101. self.assertEqual(function, preprocessor.random_pixel_value_scale)
  102. self.assert_dictionary_close(args, {'minval': 0.8, 'maxval': 1.2})
  103. def test_build_random_image_scale(self):
  104. preprocessor_text_proto = """
  105. random_image_scale {
  106. min_scale_ratio: 0.8
  107. max_scale_ratio: 2.2
  108. }
  109. """
  110. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  111. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  112. function, args = preprocessor_builder.build(preprocessor_proto)
  113. self.assertEqual(function, preprocessor.random_image_scale)
  114. self.assert_dictionary_close(args, {'min_scale_ratio': 0.8,
  115. 'max_scale_ratio': 2.2})
  116. def test_build_random_rgb_to_gray(self):
  117. preprocessor_text_proto = """
  118. random_rgb_to_gray {
  119. probability: 0.8
  120. }
  121. """
  122. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  123. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  124. function, args = preprocessor_builder.build(preprocessor_proto)
  125. self.assertEqual(function, preprocessor.random_rgb_to_gray)
  126. self.assert_dictionary_close(args, {'probability': 0.8})
  127. def test_build_random_adjust_brightness(self):
  128. preprocessor_text_proto = """
  129. random_adjust_brightness {
  130. max_delta: 0.2
  131. }
  132. """
  133. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  134. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  135. function, args = preprocessor_builder.build(preprocessor_proto)
  136. self.assertEqual(function, preprocessor.random_adjust_brightness)
  137. self.assert_dictionary_close(args, {'max_delta': 0.2})
  138. def test_build_random_adjust_contrast(self):
  139. preprocessor_text_proto = """
  140. random_adjust_contrast {
  141. min_delta: 0.7
  142. max_delta: 1.1
  143. }
  144. """
  145. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  146. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  147. function, args = preprocessor_builder.build(preprocessor_proto)
  148. self.assertEqual(function, preprocessor.random_adjust_contrast)
  149. self.assert_dictionary_close(args, {'min_delta': 0.7, 'max_delta': 1.1})
  150. def test_build_random_adjust_hue(self):
  151. preprocessor_text_proto = """
  152. random_adjust_hue {
  153. max_delta: 0.01
  154. }
  155. """
  156. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  157. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  158. function, args = preprocessor_builder.build(preprocessor_proto)
  159. self.assertEqual(function, preprocessor.random_adjust_hue)
  160. self.assert_dictionary_close(args, {'max_delta': 0.01})
  161. def test_build_random_adjust_saturation(self):
  162. preprocessor_text_proto = """
  163. random_adjust_saturation {
  164. min_delta: 0.75
  165. max_delta: 1.15
  166. }
  167. """
  168. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  169. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  170. function, args = preprocessor_builder.build(preprocessor_proto)
  171. self.assertEqual(function, preprocessor.random_adjust_saturation)
  172. self.assert_dictionary_close(args, {'min_delta': 0.75, 'max_delta': 1.15})
  173. def test_build_random_distort_color(self):
  174. preprocessor_text_proto = """
  175. random_distort_color {
  176. color_ordering: 1
  177. }
  178. """
  179. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  180. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  181. function, args = preprocessor_builder.build(preprocessor_proto)
  182. self.assertEqual(function, preprocessor.random_distort_color)
  183. self.assertEqual(args, {'color_ordering': 1})
  184. def test_build_random_jitter_boxes(self):
  185. preprocessor_text_proto = """
  186. random_jitter_boxes {
  187. ratio: 0.1
  188. }
  189. """
  190. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  191. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  192. function, args = preprocessor_builder.build(preprocessor_proto)
  193. self.assertEqual(function, preprocessor.random_jitter_boxes)
  194. self.assert_dictionary_close(args, {'ratio': 0.1})
  195. def test_build_random_crop_image(self):
  196. preprocessor_text_proto = """
  197. random_crop_image {
  198. min_object_covered: 0.75
  199. min_aspect_ratio: 0.75
  200. max_aspect_ratio: 1.5
  201. min_area: 0.25
  202. max_area: 0.875
  203. overlap_thresh: 0.5
  204. clip_boxes: False
  205. random_coef: 0.125
  206. }
  207. """
  208. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  209. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  210. function, args = preprocessor_builder.build(preprocessor_proto)
  211. self.assertEqual(function, preprocessor.random_crop_image)
  212. self.assertEqual(args, {
  213. 'min_object_covered': 0.75,
  214. 'aspect_ratio_range': (0.75, 1.5),
  215. 'area_range': (0.25, 0.875),
  216. 'overlap_thresh': 0.5,
  217. 'clip_boxes': False,
  218. 'random_coef': 0.125,
  219. })
  220. def test_build_random_pad_image(self):
  221. preprocessor_text_proto = """
  222. random_pad_image {
  223. }
  224. """
  225. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  226. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  227. function, args = preprocessor_builder.build(preprocessor_proto)
  228. self.assertEqual(function, preprocessor.random_pad_image)
  229. self.assertEqual(args, {
  230. 'min_image_size': None,
  231. 'max_image_size': None,
  232. 'pad_color': None,
  233. })
  234. def test_build_random_absolute_pad_image(self):
  235. preprocessor_text_proto = """
  236. random_absolute_pad_image {
  237. max_height_padding: 50
  238. max_width_padding: 100
  239. }
  240. """
  241. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  242. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  243. function, args = preprocessor_builder.build(preprocessor_proto)
  244. self.assertEqual(function, preprocessor.random_absolute_pad_image)
  245. self.assertEqual(args, {
  246. 'max_height_padding': 50,
  247. 'max_width_padding': 100,
  248. 'pad_color': None,
  249. })
  250. def test_build_random_crop_pad_image(self):
  251. preprocessor_text_proto = """
  252. random_crop_pad_image {
  253. min_object_covered: 0.75
  254. min_aspect_ratio: 0.75
  255. max_aspect_ratio: 1.5
  256. min_area: 0.25
  257. max_area: 0.875
  258. overlap_thresh: 0.5
  259. clip_boxes: False
  260. random_coef: 0.125
  261. }
  262. """
  263. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  264. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  265. function, args = preprocessor_builder.build(preprocessor_proto)
  266. self.assertEqual(function, preprocessor.random_crop_pad_image)
  267. self.assertEqual(args, {
  268. 'min_object_covered': 0.75,
  269. 'aspect_ratio_range': (0.75, 1.5),
  270. 'area_range': (0.25, 0.875),
  271. 'overlap_thresh': 0.5,
  272. 'clip_boxes': False,
  273. 'random_coef': 0.125,
  274. 'pad_color': None,
  275. })
  276. def test_build_random_crop_pad_image_with_optional_parameters(self):
  277. preprocessor_text_proto = """
  278. random_crop_pad_image {
  279. min_object_covered: 0.75
  280. min_aspect_ratio: 0.75
  281. max_aspect_ratio: 1.5
  282. min_area: 0.25
  283. max_area: 0.875
  284. overlap_thresh: 0.5
  285. clip_boxes: False
  286. random_coef: 0.125
  287. min_padded_size_ratio: 0.5
  288. min_padded_size_ratio: 0.75
  289. max_padded_size_ratio: 0.5
  290. max_padded_size_ratio: 0.75
  291. }
  292. """
  293. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  294. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  295. function, args = preprocessor_builder.build(preprocessor_proto)
  296. self.assertEqual(function, preprocessor.random_crop_pad_image)
  297. self.assertEqual(args, {
  298. 'min_object_covered': 0.75,
  299. 'aspect_ratio_range': (0.75, 1.5),
  300. 'area_range': (0.25, 0.875),
  301. 'overlap_thresh': 0.5,
  302. 'clip_boxes': False,
  303. 'random_coef': 0.125,
  304. 'min_padded_size_ratio': (0.5, 0.75),
  305. 'max_padded_size_ratio': (0.5, 0.75),
  306. 'pad_color': None,
  307. })
  308. def test_build_random_crop_to_aspect_ratio(self):
  309. preprocessor_text_proto = """
  310. random_crop_to_aspect_ratio {
  311. aspect_ratio: 0.85
  312. overlap_thresh: 0.35
  313. clip_boxes: False
  314. }
  315. """
  316. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  317. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  318. function, args = preprocessor_builder.build(preprocessor_proto)
  319. self.assertEqual(function, preprocessor.random_crop_to_aspect_ratio)
  320. self.assert_dictionary_close(args, {'aspect_ratio': 0.85,
  321. 'overlap_thresh': 0.35,
  322. 'clip_boxes': False})
  323. def test_build_random_black_patches(self):
  324. preprocessor_text_proto = """
  325. random_black_patches {
  326. max_black_patches: 20
  327. probability: 0.95
  328. size_to_image_ratio: 0.12
  329. }
  330. """
  331. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  332. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  333. function, args = preprocessor_builder.build(preprocessor_proto)
  334. self.assertEqual(function, preprocessor.random_black_patches)
  335. self.assert_dictionary_close(args, {'max_black_patches': 20,
  336. 'probability': 0.95,
  337. 'size_to_image_ratio': 0.12})
  338. def test_build_random_resize_method(self):
  339. preprocessor_text_proto = """
  340. random_resize_method {
  341. target_height: 75
  342. target_width: 100
  343. }
  344. """
  345. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  346. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  347. function, args = preprocessor_builder.build(preprocessor_proto)
  348. self.assertEqual(function, preprocessor.random_resize_method)
  349. self.assert_dictionary_close(args, {'target_size': [75, 100]})
  350. def test_build_scale_boxes_to_pixel_coordinates(self):
  351. preprocessor_text_proto = """
  352. scale_boxes_to_pixel_coordinates {}
  353. """
  354. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  355. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  356. function, args = preprocessor_builder.build(preprocessor_proto)
  357. self.assertEqual(function, preprocessor.scale_boxes_to_pixel_coordinates)
  358. self.assertEqual(args, {})
  359. def test_build_resize_image(self):
  360. preprocessor_text_proto = """
  361. resize_image {
  362. new_height: 75
  363. new_width: 100
  364. method: BICUBIC
  365. }
  366. """
  367. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  368. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  369. function, args = preprocessor_builder.build(preprocessor_proto)
  370. self.assertEqual(function, preprocessor.resize_image)
  371. self.assertEqual(args, {'new_height': 75,
  372. 'new_width': 100,
  373. 'method': tf.image.ResizeMethod.BICUBIC})
  374. def test_build_rgb_to_gray(self):
  375. preprocessor_text_proto = """
  376. rgb_to_gray {}
  377. """
  378. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  379. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  380. function, args = preprocessor_builder.build(preprocessor_proto)
  381. self.assertEqual(function, preprocessor.rgb_to_gray)
  382. self.assertEqual(args, {})
  383. def test_build_subtract_channel_mean(self):
  384. preprocessor_text_proto = """
  385. subtract_channel_mean {
  386. means: [1.0, 2.0, 3.0]
  387. }
  388. """
  389. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  390. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  391. function, args = preprocessor_builder.build(preprocessor_proto)
  392. self.assertEqual(function, preprocessor.subtract_channel_mean)
  393. self.assertEqual(args, {'means': [1.0, 2.0, 3.0]})
  394. def test_random_self_concat_image(self):
  395. preprocessor_text_proto = """
  396. random_self_concat_image {
  397. concat_vertical_probability: 0.5
  398. concat_horizontal_probability: 0.25
  399. }
  400. """
  401. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  402. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  403. function, args = preprocessor_builder.build(preprocessor_proto)
  404. self.assertEqual(function, preprocessor.random_self_concat_image)
  405. self.assertEqual(args, {'concat_vertical_probability': 0.5,
  406. 'concat_horizontal_probability': 0.25})
  407. def test_build_ssd_random_crop(self):
  408. preprocessor_text_proto = """
  409. ssd_random_crop {
  410. operations {
  411. min_object_covered: 0.0
  412. min_aspect_ratio: 0.875
  413. max_aspect_ratio: 1.125
  414. min_area: 0.5
  415. max_area: 1.0
  416. overlap_thresh: 0.0
  417. clip_boxes: False
  418. random_coef: 0.375
  419. }
  420. operations {
  421. min_object_covered: 0.25
  422. min_aspect_ratio: 0.75
  423. max_aspect_ratio: 1.5
  424. min_area: 0.5
  425. max_area: 1.0
  426. overlap_thresh: 0.25
  427. clip_boxes: True
  428. random_coef: 0.375
  429. }
  430. }
  431. """
  432. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  433. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  434. function, args = preprocessor_builder.build(preprocessor_proto)
  435. self.assertEqual(function, preprocessor.ssd_random_crop)
  436. self.assertEqual(args, {'min_object_covered': [0.0, 0.25],
  437. 'aspect_ratio_range': [(0.875, 1.125), (0.75, 1.5)],
  438. 'area_range': [(0.5, 1.0), (0.5, 1.0)],
  439. 'overlap_thresh': [0.0, 0.25],
  440. 'clip_boxes': [False, True],
  441. 'random_coef': [0.375, 0.375]})
  442. def test_build_ssd_random_crop_empty_operations(self):
  443. preprocessor_text_proto = """
  444. ssd_random_crop {
  445. }
  446. """
  447. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  448. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  449. function, args = preprocessor_builder.build(preprocessor_proto)
  450. self.assertEqual(function, preprocessor.ssd_random_crop)
  451. self.assertEqual(args, {})
  452. def test_build_ssd_random_crop_pad(self):
  453. preprocessor_text_proto = """
  454. ssd_random_crop_pad {
  455. operations {
  456. min_object_covered: 0.0
  457. min_aspect_ratio: 0.875
  458. max_aspect_ratio: 1.125
  459. min_area: 0.5
  460. max_area: 1.0
  461. overlap_thresh: 0.0
  462. clip_boxes: False
  463. random_coef: 0.375
  464. min_padded_size_ratio: [1.0, 1.0]
  465. max_padded_size_ratio: [2.0, 2.0]
  466. pad_color_r: 0.5
  467. pad_color_g: 0.5
  468. pad_color_b: 0.5
  469. }
  470. operations {
  471. min_object_covered: 0.25
  472. min_aspect_ratio: 0.75
  473. max_aspect_ratio: 1.5
  474. min_area: 0.5
  475. max_area: 1.0
  476. overlap_thresh: 0.25
  477. clip_boxes: True
  478. random_coef: 0.375
  479. min_padded_size_ratio: [1.0, 1.0]
  480. max_padded_size_ratio: [2.0, 2.0]
  481. pad_color_r: 0.5
  482. pad_color_g: 0.5
  483. pad_color_b: 0.5
  484. }
  485. }
  486. """
  487. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  488. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  489. function, args = preprocessor_builder.build(preprocessor_proto)
  490. self.assertEqual(function, preprocessor.ssd_random_crop_pad)
  491. self.assertEqual(args, {'min_object_covered': [0.0, 0.25],
  492. 'aspect_ratio_range': [(0.875, 1.125), (0.75, 1.5)],
  493. 'area_range': [(0.5, 1.0), (0.5, 1.0)],
  494. 'overlap_thresh': [0.0, 0.25],
  495. 'clip_boxes': [False, True],
  496. 'random_coef': [0.375, 0.375],
  497. 'min_padded_size_ratio': [(1.0, 1.0), (1.0, 1.0)],
  498. 'max_padded_size_ratio': [(2.0, 2.0), (2.0, 2.0)],
  499. 'pad_color': [(0.5, 0.5, 0.5), (0.5, 0.5, 0.5)]})
  500. def test_build_ssd_random_crop_fixed_aspect_ratio(self):
  501. preprocessor_text_proto = """
  502. ssd_random_crop_fixed_aspect_ratio {
  503. operations {
  504. min_object_covered: 0.0
  505. min_area: 0.5
  506. max_area: 1.0
  507. overlap_thresh: 0.0
  508. clip_boxes: False
  509. random_coef: 0.375
  510. }
  511. operations {
  512. min_object_covered: 0.25
  513. min_area: 0.5
  514. max_area: 1.0
  515. overlap_thresh: 0.25
  516. clip_boxes: True
  517. random_coef: 0.375
  518. }
  519. aspect_ratio: 0.875
  520. }
  521. """
  522. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  523. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  524. function, args = preprocessor_builder.build(preprocessor_proto)
  525. self.assertEqual(function, preprocessor.ssd_random_crop_fixed_aspect_ratio)
  526. self.assertEqual(args, {'min_object_covered': [0.0, 0.25],
  527. 'aspect_ratio': 0.875,
  528. 'area_range': [(0.5, 1.0), (0.5, 1.0)],
  529. 'overlap_thresh': [0.0, 0.25],
  530. 'clip_boxes': [False, True],
  531. 'random_coef': [0.375, 0.375]})
  532. def test_build_ssd_random_crop_pad_fixed_aspect_ratio(self):
  533. preprocessor_text_proto = """
  534. ssd_random_crop_pad_fixed_aspect_ratio {
  535. operations {
  536. min_object_covered: 0.0
  537. min_aspect_ratio: 0.875
  538. max_aspect_ratio: 1.125
  539. min_area: 0.5
  540. max_area: 1.0
  541. overlap_thresh: 0.0
  542. clip_boxes: False
  543. random_coef: 0.375
  544. }
  545. operations {
  546. min_object_covered: 0.25
  547. min_aspect_ratio: 0.75
  548. max_aspect_ratio: 1.5
  549. min_area: 0.5
  550. max_area: 1.0
  551. overlap_thresh: 0.25
  552. clip_boxes: True
  553. random_coef: 0.375
  554. }
  555. aspect_ratio: 0.875
  556. min_padded_size_ratio: [1.0, 1.0]
  557. max_padded_size_ratio: [2.0, 2.0]
  558. }
  559. """
  560. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  561. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  562. function, args = preprocessor_builder.build(preprocessor_proto)
  563. self.assertEqual(function,
  564. preprocessor.ssd_random_crop_pad_fixed_aspect_ratio)
  565. self.assertEqual(args, {'min_object_covered': [0.0, 0.25],
  566. 'aspect_ratio': 0.875,
  567. 'aspect_ratio_range': [(0.875, 1.125), (0.75, 1.5)],
  568. 'area_range': [(0.5, 1.0), (0.5, 1.0)],
  569. 'overlap_thresh': [0.0, 0.25],
  570. 'clip_boxes': [False, True],
  571. 'random_coef': [0.375, 0.375],
  572. 'min_padded_size_ratio': (1.0, 1.0),
  573. 'max_padded_size_ratio': (2.0, 2.0)})
  574. def test_build_normalize_image_convert_class_logits_to_softmax(self):
  575. preprocessor_text_proto = """
  576. convert_class_logits_to_softmax {
  577. temperature: 2
  578. }
  579. """
  580. preprocessor_proto = preprocessor_pb2.PreprocessingStep()
  581. text_format.Merge(preprocessor_text_proto, preprocessor_proto)
  582. function, args = preprocessor_builder.build(preprocessor_proto)
  583. self.assertEqual(function, preprocessor.convert_class_logits_to_softmax)
  584. self.assertEqual(args, {'temperature': 2})
  585. if __name__ == '__main__':
  586. tf.test.main()