Python object_detection.utils.ops.position_sensitive_crop_regions() Examples
The following are 30
code examples of object_detection.utils.ops.position_sensitive_crop_regions().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
object_detection.utils.ops
, or try the search function
.
Example #1
Source File: ops_test.py From Person-Detection-and-Tracking with MIT License | 6 votes |
def test_position_sensitive_with_global_pool_false_and_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [1, 1] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # Since single_bin is used and crop_size = [1, 1] (i.e., no crop resize), # the outputs are the same whatever the global_pool value is. ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) ps_crop = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=False) with self.test_session() as sess: pooled_output, unpooled_output = sess.run((ps_crop_and_pool, ps_crop)) self.assertAllClose(pooled_output, unpooled_output)
Example #2
Source File: ops_test.py From yolo_v2 with Apache License 2.0 | 6 votes |
def test_position_sensitive_with_global_pool_false_and_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [1, 1] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # Since single_bin is used and crop_size = [1, 1] (i.e., no crop resize), # the outputs are the same whatever the global_pool value is. ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) ps_crop = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=False) with self.test_session() as sess: pooled_output, unpooled_output = sess.run((ps_crop_and_pool, ps_crop)) self.assertAllClose(pooled_output, unpooled_output)
Example #3
Source File: ops_test.py From object_detector_app with MIT License | 6 votes |
def test_position_sensitive_with_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [2, 2] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # When a single bin is used, position-sensitive crop and pool should be # the same as non-position sensitive crop and pool. crop = tf.image.crop_and_resize(image, boxes, box_ind, crop_size) crop_and_pool = tf.reduce_mean(crop, [1, 2], keep_dims=True) ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: expected_output, output = sess.run((crop_and_pool, ps_crop_and_pool)) self.assertAllClose(output, expected_output)
Example #4
Source File: ops_test.py From object_detector_app with MIT License | 6 votes |
def test_position_sensitive(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] # First channel is 1's, second channel is 2's, etc. image = tf.constant(range(1, 3 * 2 + 1) * 6, dtype=tf.float32, shape=image_shape) boxes = tf.random_uniform((2, 4)) box_ind = tf.constant([0, 0], dtype=tf.int32) # The result for both boxes should be [[1, 2], [3, 4], [5, 6]] # before averaging. expected_output = np.array([3.5, 3.5]).reshape([2, 1, 1, 1]) for crop_size_mult in range(1, 3): crop_size = [3 * crop_size_mult, 2 * crop_size_mult] ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: output = sess.run(ps_crop_and_pool) self.assertAllClose(output, expected_output)
Example #5
Source File: ops_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 6 votes |
def test_position_sensitive(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] # First channel is 1's, second channel is 2's, etc. image = tf.constant(range(1, 3 * 2 + 1) * 6, dtype=tf.float32, shape=image_shape) boxes = tf.random_uniform((2, 4)) box_ind = tf.constant([0, 0], dtype=tf.int32) # The result for both boxes should be [[1, 2], [3, 4], [5, 6]] # before averaging. expected_output = np.array([3.5, 3.5]).reshape([2, 1, 1, 1]) for crop_size_mult in range(1, 3): crop_size = [3 * crop_size_mult, 2 * crop_size_mult] ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: output = sess.run(ps_crop_and_pool) self.assertAllClose(output, expected_output)
Example #6
Source File: ops_test.py From yolo_v2 with Apache License 2.0 | 6 votes |
def test_position_sensitive(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] # First channel is 1's, second channel is 2's, etc. image = tf.constant(range(1, 3 * 2 + 1) * 6, dtype=tf.float32, shape=image_shape) boxes = tf.random_uniform((2, 4)) box_ind = tf.constant([0, 0], dtype=tf.int32) # The result for both boxes should be [[1, 2], [3, 4], [5, 6]] # before averaging. expected_output = np.array([3.5, 3.5]).reshape([2, 1, 1, 1]) for crop_size_mult in range(1, 3): crop_size = [3 * crop_size_mult, 2 * crop_size_mult] ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: output = sess.run(ps_crop_and_pool) self.assertAllClose(output, expected_output)
Example #7
Source File: ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_position_sensitive_with_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [2, 2] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # When a single bin is used, position-sensitive crop and pool should be # the same as non-position sensitive crop and pool. crop = tf.image.crop_and_resize(image, boxes, box_ind, crop_size) crop_and_pool = tf.reduce_mean(crop, [1, 2], keep_dims=True) ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: expected_output, output = sess.run((crop_and_pool, ps_crop_and_pool)) self.assertAllClose(output, expected_output)
Example #8
Source File: ops_test.py From yolo_v2 with Apache License 2.0 | 6 votes |
def test_position_sensitive_with_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [2, 2] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # When a single bin is used, position-sensitive crop and pool should be # the same as non-position sensitive crop and pool. crop = tf.image.crop_and_resize(image, boxes, box_ind, crop_size) crop_and_pool = tf.reduce_mean(crop, [1, 2], keep_dims=True) ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: expected_output, output = sess.run((crop_and_pool, ps_crop_and_pool)) self.assertAllClose(output, expected_output)
Example #9
Source File: ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_position_sensitive_with_global_pool_false_and_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [1, 1] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # Since single_bin is used and crop_size = [1, 1] (i.e., no crop resize), # the outputs are the same whatever the global_pool value is. ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) ps_crop = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=False) with self.test_session() as sess: pooled_output, unpooled_output = sess.run((ps_crop_and_pool, ps_crop)) self.assertAllClose(pooled_output, unpooled_output)
Example #10
Source File: ops_test.py From object_detector_app with MIT License | 6 votes |
def test_position_sensitive_with_global_pool_false_and_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [1, 1] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # Since single_bin is used and crop_size = [1, 1] (i.e., no crop resize), # the outputs are the same whatever the global_pool value is. ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) ps_crop = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=False) with self.test_session() as sess: pooled_output, unpooled_output = sess.run((ps_crop_and_pool, ps_crop)) self.assertAllClose(pooled_output, unpooled_output)
Example #11
Source File: ops_test.py From HereIsWally with MIT License | 6 votes |
def test_position_sensitive_with_global_pool_false_and_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [1, 1] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # Since single_bin is used and crop_size = [1, 1] (i.e., no crop resize), # the outputs are the same whatever the global_pool value is. ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) ps_crop = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=False) with self.test_session() as sess: pooled_output, unpooled_output = sess.run((ps_crop_and_pool, ps_crop)) self.assertAllClose(pooled_output, unpooled_output)
Example #12
Source File: ops_test.py From vehicle_counting_tensorflow with MIT License | 6 votes |
def test_position_sensitive(self): num_spatial_bins = [3, 2] image_shape = [3, 2, 6] # First channel is 1's, second channel is 2's, etc. image = tf.constant(range(1, 3 * 2 + 1) * 6, dtype=tf.float32, shape=image_shape) boxes = tf.random_uniform((2, 4)) # The result for both boxes should be [[1, 2], [3, 4], [5, 6]] # before averaging. expected_output = np.array([3.5, 3.5]).reshape([2, 1, 1, 1]) for crop_size_mult in range(1, 3): crop_size = [3 * crop_size_mult, 2 * crop_size_mult] ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: output = sess.run(ps_crop_and_pool) self.assertAllClose(output, expected_output)
Example #13
Source File: ops_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 6 votes |
def test_position_sensitive(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] # First channel is 1's, second channel is 2's, etc. image = tf.constant(range(1, 3 * 2 + 1) * 6, dtype=tf.float32, shape=image_shape) boxes = tf.random_uniform((2, 4)) box_ind = tf.constant([0, 0], dtype=tf.int32) # The result for both boxes should be [[1, 2], [3, 4], [5, 6]] # before averaging. expected_output = np.array([3.5, 3.5]).reshape([2, 1, 1, 1]) for crop_size_mult in range(1, 3): crop_size = [3 * crop_size_mult, 2 * crop_size_mult] ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: output = sess.run(ps_crop_and_pool) self.assertAllClose(output, expected_output)
Example #14
Source File: ops_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 6 votes |
def test_position_sensitive_with_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [2, 2] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # When a single bin is used, position-sensitive crop and pool should be # the same as non-position sensitive crop and pool. crop = tf.image.crop_and_resize(image, boxes, box_ind, crop_size) crop_and_pool = tf.reduce_mean(crop, [1, 2], keep_dims=True) ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: expected_output, output = sess.run((crop_and_pool, ps_crop_and_pool)) self.assertAllClose(output, expected_output)
Example #15
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 6 votes |
def test_position_sensitive(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] # First channel is 1's, second channel is 2's, etc. image = tf.constant(range(1, 3 * 2 + 1) * 6, dtype=tf.float32, shape=image_shape) boxes = tf.random_uniform((2, 4)) box_ind = tf.constant([0, 0], dtype=tf.int32) # The result for both boxes should be [[1, 2], [3, 4], [5, 6]] # before averaging. expected_output = np.array([3.5, 3.5]).reshape([2, 1, 1, 1]) for crop_size_mult in range(1, 3): crop_size = [3 * crop_size_mult, 2 * crop_size_mult] ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: output = sess.run(ps_crop_and_pool) self.assertAllClose(output, expected_output)
Example #16
Source File: ops_test.py From DOTA_models with Apache License 2.0 | 6 votes |
def test_position_sensitive(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] # First channel is 1's, second channel is 2's, etc. image = tf.constant(range(1, 3 * 2 + 1) * 6, dtype=tf.float32, shape=image_shape) boxes = tf.random_uniform((2, 4)) box_ind = tf.constant([0, 0], dtype=tf.int32) # The result for both boxes should be [[1, 2], [3, 4], [5, 6]] # before averaging. expected_output = np.array([3.5, 3.5]).reshape([2, 1, 1, 1]) for crop_size_mult in range(1, 3): crop_size = [3 * crop_size_mult, 2 * crop_size_mult] ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: output = sess.run(ps_crop_and_pool) self.assertAllClose(output, expected_output)
Example #17
Source File: ops_test.py From Person-Detection-and-Tracking with MIT License | 6 votes |
def test_position_sensitive_with_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [2, 2] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # When a single bin is used, position-sensitive crop and pool should be # the same as non-position sensitive crop and pool. crop = tf.image.crop_and_resize(image, boxes, box_ind, crop_size) crop_and_pool = tf.reduce_mean(crop, [1, 2], keep_dims=True) ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: expected_output, output = sess.run((crop_and_pool, ps_crop_and_pool)) self.assertAllClose(output, expected_output)
Example #18
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 6 votes |
def test_position_sensitive_with_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [2, 2] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # When a single bin is used, position-sensitive crop and pool should be # the same as non-position sensitive crop and pool. crop = tf.image.crop_and_resize(image, boxes, box_ind, crop_size) crop_and_pool = tf.reduce_mean(crop, [1, 2], keep_dims=True) ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: expected_output, output = sess.run((crop_and_pool, ps_crop_and_pool)) self.assertAllClose(output, expected_output)
Example #19
Source File: ops_test.py From Person-Detection-and-Tracking with MIT License | 6 votes |
def test_position_sensitive(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] # First channel is 1's, second channel is 2's, etc. image = tf.constant(range(1, 3 * 2 + 1) * 6, dtype=tf.float32, shape=image_shape) boxes = tf.random_uniform((2, 4)) box_ind = tf.constant([0, 0], dtype=tf.int32) # The result for both boxes should be [[1, 2], [3, 4], [5, 6]] # before averaging. expected_output = np.array([3.5, 3.5]).reshape([2, 1, 1, 1]) for crop_size_mult in range(1, 3): crop_size = [3 * crop_size_mult, 2 * crop_size_mult] ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: output = sess.run(ps_crop_and_pool) self.assertAllClose(output, expected_output)
Example #20
Source File: ops_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 6 votes |
def test_position_sensitive_with_global_pool_false_and_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [1, 1] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # Since single_bin is used and crop_size = [1, 1] (i.e., no crop resize), # the outputs are the same whatever the global_pool value is. ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) ps_crop = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=False) with self.test_session() as sess: pooled_output, unpooled_output = sess.run((ps_crop_and_pool, ps_crop)) self.assertAllClose(pooled_output, unpooled_output)
Example #21
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 6 votes |
def test_position_sensitive_with_global_pool_false_and_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [1, 1] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # Since single_bin is used and crop_size = [1, 1] (i.e., no crop resize), # the outputs are the same whatever the global_pool value is. ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) ps_crop = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=False) with self.test_session() as sess: pooled_output, unpooled_output = sess.run((ps_crop_and_pool, ps_crop)) self.assertAllClose(pooled_output, unpooled_output)
Example #22
Source File: ops_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 6 votes |
def test_position_sensitive_with_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [2, 2] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # When a single bin is used, position-sensitive crop and pool should be # the same as non-position sensitive crop and pool. crop = tf.image.crop_and_resize(image, boxes, box_ind, crop_size) crop_and_pool = tf.reduce_mean(crop, [1, 2], keep_dims=True) ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: expected_output, output = sess.run((crop_and_pool, ps_crop_and_pool)) self.assertAllClose(output, expected_output)
Example #23
Source File: ops_test.py From HereIsWally with MIT License | 6 votes |
def test_position_sensitive(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] # First channel is 1's, second channel is 2's, etc. image = tf.constant(range(1, 3 * 2 + 1) * 6, dtype=tf.float32, shape=image_shape) boxes = tf.random_uniform((2, 4)) box_ind = tf.constant([0, 0], dtype=tf.int32) # The result for both boxes should be [[1, 2], [3, 4], [5, 6]] # before averaging. expected_output = np.array([3.5, 3.5]).reshape([2, 1, 1, 1]) for crop_size_mult in range(1, 3): crop_size = [3 * crop_size_mult, 2 * crop_size_mult] ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: output = sess.run(ps_crop_and_pool) self.assertAllClose(output, expected_output)
Example #24
Source File: ops_test.py From HereIsWally with MIT License | 6 votes |
def test_position_sensitive_with_single_bin(self): num_spatial_bins = [1, 1] image_shape = [2, 3, 3, 4] crop_size = [2, 2] image = tf.random_uniform(image_shape) boxes = tf.random_uniform((6, 4)) box_ind = tf.constant([0, 0, 0, 1, 1, 1], dtype=tf.int32) # When a single bin is used, position-sensitive crop and pool should be # the same as non-position sensitive crop and pool. crop = tf.image.crop_and_resize(image, boxes, box_ind, crop_size) crop_and_pool = tf.reduce_mean(crop, [1, 2], keep_dims=True) ps_crop_and_pool = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: expected_output, output = sess.run((crop_and_pool, ps_crop_and_pool)) self.assertAllClose(output, expected_output)
Example #25
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_position_sensitive_with_global_pool_false(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] num_boxes = 2 # First channel is 1's, second channel is 2's, etc. image = tf.constant(range(1, 3 * 2 + 1) * 6, dtype=tf.float32, shape=image_shape) boxes = tf.random_uniform((num_boxes, 4)) box_ind = tf.constant([0, 0], dtype=tf.int32) expected_output = [] # Expected output, when crop_size = [3, 2]. expected_output.append(np.expand_dims( np.tile(np.array([[1, 2], [3, 4], [5, 6]]), (num_boxes, 1, 1)), axis=-1)) # Expected output, when crop_size = [6, 4]. expected_output.append(np.expand_dims( np.tile(np.array([[1, 1, 2, 2], [1, 1, 2, 2], [3, 3, 4, 4], [3, 3, 4, 4], [5, 5, 6, 6], [5, 5, 6, 6]]), (num_boxes, 1, 1)), axis=-1)) for crop_size_mult in range(1, 3): crop_size = [3 * crop_size_mult, 2 * crop_size_mult] ps_crop = ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=False) with self.test_session() as sess: output = sess.run(ps_crop) self.assertAllEqual(output, expected_output[crop_size_mult - 1])
Example #26
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_raise_value_error_on_non_divisible_crop_size(self): num_spatial_bins = [2, 3] image_shape = [1, 1, 1, 6] crop_size = [3, 2] image = tf.constant(1, dtype=tf.float32, shape=image_shape) boxes = tf.constant([[0, 0, 1, 1]], dtype=tf.float32) box_ind = tf.constant([0], dtype=tf.int32) with self.assertRaisesRegexp( ValueError, 'crop_size should be divisible by num_spatial_bins'): ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True)
Example #27
Source File: ops_test.py From yolo_v2 with Apache License 2.0 | 5 votes |
def test_raise_value_error_on_non_square_block_size(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] crop_size = [6, 2] image = tf.constant(1, dtype=tf.float32, shape=image_shape) boxes = tf.constant([[0, 0, 1, 1]], dtype=tf.float32) box_ind = tf.constant([0], dtype=tf.int32) with self.assertRaisesRegexp( ValueError, 'Only support square bin crop size for now.'): ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=False)
Example #28
Source File: ops_test.py From garbage-object-detection-tensorflow with MIT License | 5 votes |
def test_position_sensitive_with_equal_channels(self): num_spatial_bins = [2, 2] image_shape = [1, 3, 3, 4] crop_size = [2, 2] image = tf.constant(range(1, 3 * 3 + 1), dtype=tf.float32, shape=[1, 3, 3, 1]) tiled_image = tf.tile(image, [1, 1, 1, image_shape[3]]) boxes = tf.random_uniform((3, 4)) box_ind = tf.constant([0, 0, 0], dtype=tf.int32) # All channels are equal so position-sensitive crop and resize should # work as the usual crop and resize for just one channel. crop = tf.image.crop_and_resize(image, boxes, box_ind, crop_size) crop_and_pool = tf.reduce_mean(crop, [1, 2], keep_dims=True) ps_crop_and_pool = ops.position_sensitive_crop_regions( tiled_image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True) with self.test_session() as sess: expected_output, output = sess.run((crop_and_pool, ps_crop_and_pool)) self.assertAllClose(output, expected_output)
Example #29
Source File: ops_test.py From Person-Detection-and-Tracking with MIT License | 5 votes |
def test_raise_value_error_on_num_bins_less_than_one(self): num_spatial_bins = [1, -1] image_shape = [1, 1, 1, 2] crop_size = [2, 2] image = tf.constant(1, dtype=tf.float32, shape=image_shape) boxes = tf.constant([[0, 0, 1, 1]], dtype=tf.float32) box_ind = tf.constant([0], dtype=tf.int32) with self.assertRaisesRegexp(ValueError, 'num_spatial_bins should be >= 1'): ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=True)
Example #30
Source File: ops_test.py From Person-Detection-and-Tracking with MIT License | 5 votes |
def test_raise_value_error_on_non_square_block_size(self): num_spatial_bins = [3, 2] image_shape = [1, 3, 2, 6] crop_size = [6, 2] image = tf.constant(1, dtype=tf.float32, shape=image_shape) boxes = tf.constant([[0, 0, 1, 1]], dtype=tf.float32) box_ind = tf.constant([0], dtype=tf.int32) with self.assertRaisesRegexp( ValueError, 'Only support square bin crop size for now.'): ops.position_sensitive_crop_regions( image, boxes, box_ind, crop_size, num_spatial_bins, global_pool=False)