Python object_detection.core.box_predictor.WeightSharedConvolutionalBoxPredictor() Examples
The following are 30
code examples of object_detection.core.box_predictor.WeightSharedConvolutionalBoxPredictor().
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.core.box_predictor
, or try the search function
.
Example #1
Source File: box_predictor_test.py From ros_tensorflow with Apache License 2.0 | 6 votes |
def test_get_boxes_for_five_aspect_ratios_per_location(self): def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, objectness_predictions) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, objectness_predictions) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(objectness_predictions.shape, [4, 320, 1])
Example #2
Source File: box_predictor_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 6 votes |
def test_get_boxes_for_five_aspect_ratios_per_location(self): def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, objectness_predictions) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, objectness_predictions) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(objectness_predictions.shape, [4, 320, 1])
Example #3
Source File: box_predictor_test.py From Gun-Detector with Apache License 2.0 | 6 votes |
def test_bias_predictions_to_background_with_sigmoid_score_conversion(self): def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=True, num_classes=2, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, class_prediction_bias_init=-4.6, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') class_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (tf.nn.sigmoid(class_predictions),) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) class_predictions = self.execute(graph_fn, [image_features]) self.assertAlmostEqual(np.mean(class_predictions), 0.01, places=3)
Example #4
Source File: box_predictor_test.py From AniSeg with Apache License 2.0 | 6 votes |
def test_get_boxes_for_five_aspect_ratios_per_location(self): def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, objectness_predictions) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, objectness_predictions) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(objectness_predictions.shape, [4, 320, 1])
Example #5
Source File: box_predictor_test.py From Person-Detection-and-Tracking with MIT License | 6 votes |
def test_get_boxes_for_five_aspect_ratios_per_location(self): def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, objectness_predictions) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, objectness_predictions) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 4]) self.assertAllEqual(objectness_predictions.shape, [4, 320, 1])
Example #6
Source File: box_predictor_test.py From Person-Detection-and-Tracking with MIT License | 6 votes |
def test_bias_predictions_to_background_with_sigmoid_score_conversion(self): def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=True, num_classes=2, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, class_prediction_bias_init=-4.6, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') class_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (tf.nn.sigmoid(class_predictions),) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) class_predictions = self.execute(graph_fn, [image_features]) self.assertAlmostEqual(np.mean(class_predictions), 0.01, places=3)
Example #7
Source File: box_predictor_test.py From Gun-Detector with Apache License 2.0 | 6 votes |
def test_get_boxes_for_five_aspect_ratios_per_location(self): def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, objectness_predictions) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, objectness_predictions) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(objectness_predictions.shape, [4, 320, 1])
Example #8
Source File: box_predictor_test.py From ros_tensorflow with Apache License 2.0 | 6 votes |
def test_bias_predictions_to_background_with_sigmoid_score_conversion(self): def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=True, num_classes=2, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, class_prediction_bias_init=-4.6, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') class_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (tf.nn.sigmoid(class_predictions),) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) class_predictions = self.execute(graph_fn, [image_features]) self.assertAlmostEqual(np.mean(class_predictions), 0.01, places=3)
Example #9
Source File: box_predictor_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 6 votes |
def test_get_boxes_for_five_aspect_ratios_per_location(self): def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = box_predictions[box_predictor.BOX_ENCODINGS] objectness_predictions = box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND] return (box_encodings, objectness_predictions) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, objectness_predictions) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(objectness_predictions.shape, [4, 320, 1])
Example #10
Source File: box_predictor_test.py From Elphas with Apache License 2.0 | 6 votes |
def test_get_boxes_for_five_aspect_ratios_per_location(self): def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = box_predictions[box_predictor.BOX_ENCODINGS] objectness_predictions = box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND] return (box_encodings, objectness_predictions) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, objectness_predictions) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(objectness_predictions.shape, [4, 320, 1])
Example #11
Source File: box_predictor_test.py From Elphas with Apache License 2.0 | 5 votes |
def test_get_multi_class_predictions_for_five_aspect_ratios_per_location( self): num_classes_without_background = 6 def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = box_predictions[box_predictor.BOX_ENCODINGS] class_predictions_with_background = box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND] return (box_encodings, class_predictions_with_background) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 320, num_classes_without_background+1])
Example #12
Source File: box_predictor_test.py From ros_tensorflow with Apache License 2.0 | 5 votes |
def test_get_multi_class_predictions_for_five_aspect_ratios_per_location( self): num_classes_without_background = 6 def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 320, num_classes_without_background+1])
Example #13
Source File: box_predictor_test.py From ros_tensorflow with Apache License 2.0 | 5 votes |
def test_get_multi_class_predictions_from_two_feature_maps( self): num_classes_without_background = 6 def graph_fn(image_features1, image_features2): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features1, image_features2], num_predictions_per_location=[5, 5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features1 = np.random.rand(4, 8, 8, 64).astype(np.float32) image_features2 = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features1, image_features2]) self.assertAllEqual(box_encodings.shape, [4, 640, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 640, num_classes_without_background+1])
Example #14
Source File: box_predictor_test.py From Gun-Detector with Apache License 2.0 | 5 votes |
def test_get_multi_class_predictions_for_five_aspect_ratios_per_location( self): num_classes_without_background = 6 def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 320, num_classes_without_background+1])
Example #15
Source File: box_predictor_test.py From Elphas with Apache License 2.0 | 5 votes |
def test_get_multi_class_predictions_from_two_feature_maps( self): num_classes_without_background = 6 def graph_fn(image_features1, image_features2): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features1, image_features2], num_predictions_per_location=[5, 5], scope='BoxPredictor') box_encodings = box_predictions[box_predictor.BOX_ENCODINGS] class_predictions_with_background = box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND] return (box_encodings, class_predictions_with_background) image_features1 = np.random.rand(4, 8, 8, 64).astype(np.float32) image_features2 = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features1, image_features2]) self.assertAllEqual(box_encodings.shape, [4, 640, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 640, num_classes_without_background+1])
Example #16
Source File: box_predictor_test.py From Elphas with Apache License 2.0 | 5 votes |
def test_get_predictions_with_feature_maps_of_dynamic_shape( self): image_features = tf.placeholder(dtype=tf.float32, shape=[4, None, None, 64]) conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = box_predictions[box_predictor.BOX_ENCODINGS] objectness_predictions = box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND] init_op = tf.global_variables_initializer() resolution = 32 expected_num_anchors = resolution*resolution*5 with self.test_session() as sess: sess.run(init_op) (box_encodings_shape, objectness_predictions_shape) = sess.run( [tf.shape(box_encodings), tf.shape(objectness_predictions)], feed_dict={image_features: np.random.rand(4, resolution, resolution, 64)}) self.assertAllEqual(box_encodings_shape, [4, expected_num_anchors, 1, 4]) self.assertAllEqual(objectness_predictions_shape, [4, expected_num_anchors, 1])
Example #17
Source File: box_predictor_test.py From AniSeg with Apache License 2.0 | 5 votes |
def test_get_multi_class_predictions_for_five_aspect_ratios_per_location( self): num_classes_without_background = 6 def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 320, num_classes_without_background+1])
Example #18
Source File: box_predictor_test.py From AniSeg with Apache License 2.0 | 5 votes |
def test_get_multi_class_predictions_from_two_feature_maps( self): num_classes_without_background = 6 def graph_fn(image_features1, image_features2): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features1, image_features2], num_predictions_per_location=[5, 5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features1 = np.random.rand(4, 8, 8, 64).astype(np.float32) image_features2 = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features1, image_features2]) self.assertAllEqual(box_encodings.shape, [4, 640, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 640, num_classes_without_background+1])
Example #19
Source File: box_predictor_test.py From AniSeg with Apache License 2.0 | 5 votes |
def test_get_predictions_with_feature_maps_of_dynamic_shape( self): image_features = tf.placeholder(dtype=tf.float32, shape=[4, None, None, 64]) conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat(box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) init_op = tf.global_variables_initializer() resolution = 32 expected_num_anchors = resolution*resolution*5 with self.test_session() as sess: sess.run(init_op) (box_encodings_shape, objectness_predictions_shape) = sess.run( [tf.shape(box_encodings), tf.shape(objectness_predictions)], feed_dict={image_features: np.random.rand(4, resolution, resolution, 64)}) self.assertAllEqual(box_encodings_shape, [4, expected_num_anchors, 1, 4]) self.assertAllEqual(objectness_predictions_shape, [4, expected_num_anchors, 1])
Example #20
Source File: box_predictor_test.py From Gun-Detector with Apache License 2.0 | 5 votes |
def test_get_multi_class_predictions_from_two_feature_maps( self): num_classes_without_background = 6 def graph_fn(image_features1, image_features2): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features1, image_features2], num_predictions_per_location=[5, 5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features1 = np.random.rand(4, 8, 8, 64).astype(np.float32) image_features2 = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features1, image_features2]) self.assertAllEqual(box_encodings.shape, [4, 640, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 640, num_classes_without_background+1])
Example #21
Source File: box_predictor_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 5 votes |
def test_get_predictions_with_feature_maps_of_dynamic_shape( self): image_features = tf.placeholder(dtype=tf.float32, shape=[4, None, None, 64]) conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = box_predictions[box_predictor.BOX_ENCODINGS] objectness_predictions = box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND] init_op = tf.global_variables_initializer() resolution = 32 expected_num_anchors = resolution*resolution*5 with self.test_session() as sess: sess.run(init_op) (box_encodings_shape, objectness_predictions_shape) = sess.run( [tf.shape(box_encodings), tf.shape(objectness_predictions)], feed_dict={image_features: np.random.rand(4, resolution, resolution, 64)}) self.assertAllEqual(box_encodings_shape, [4, expected_num_anchors, 1, 4]) self.assertAllEqual(objectness_predictions_shape, [4, expected_num_anchors, 1])
Example #22
Source File: box_predictor_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 5 votes |
def test_get_multi_class_predictions_from_two_feature_maps( self): num_classes_without_background = 6 def graph_fn(image_features1, image_features2): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features1, image_features2], num_predictions_per_location=[5, 5], scope='BoxPredictor') box_encodings = box_predictions[box_predictor.BOX_ENCODINGS] class_predictions_with_background = box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND] return (box_encodings, class_predictions_with_background) image_features1 = np.random.rand(4, 8, 8, 64).astype(np.float32) image_features2 = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features1, image_features2]) self.assertAllEqual(box_encodings.shape, [4, 640, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 640, num_classes_without_background+1])
Example #23
Source File: box_predictor_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 5 votes |
def test_get_multi_class_predictions_for_five_aspect_ratios_per_location( self): num_classes_without_background = 6 def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = box_predictions[box_predictor.BOX_ENCODINGS] class_predictions_with_background = box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND] return (box_encodings, class_predictions_with_background) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 320, num_classes_without_background+1])
Example #24
Source File: box_predictor_test.py From Person-Detection-and-Tracking with MIT License | 5 votes |
def test_get_multi_class_predictions_from_two_feature_maps( self): num_classes_without_background = 6 def graph_fn(image_features1, image_features2): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features1, image_features2], num_predictions_per_location=[5, 5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features1 = np.random.rand(4, 8, 8, 64).astype(np.float32) image_features2 = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features1, image_features2]) self.assertAllEqual(box_encodings.shape, [4, 640, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 640, num_classes_without_background+1])
Example #25
Source File: box_predictor_test.py From Person-Detection-and-Tracking with MIT License | 5 votes |
def test_get_multi_class_predictions_for_five_aspect_ratios_per_location( self): num_classes_without_background = 6 def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 320, num_classes_without_background+1])
Example #26
Source File: box_predictor_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 5 votes |
def test_get_predictions_with_feature_maps_of_dynamic_shape( self): image_features = tf.placeholder(dtype=tf.float32, shape=[4, None, None, 64]) conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=0, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat(box_predictions[box_predictor.BOX_ENCODINGS], axis=1) objectness_predictions = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) init_op = tf.global_variables_initializer() resolution = 32 expected_num_anchors = resolution*resolution*5 with self.test_session() as sess: sess.run(init_op) (box_encodings_shape, objectness_predictions_shape) = sess.run( [tf.shape(box_encodings), tf.shape(objectness_predictions)], feed_dict={image_features: np.random.rand(4, resolution, resolution, 64)}) self.assertAllEqual(box_encodings_shape, [4, expected_num_anchors, 1, 4]) self.assertAllEqual(objectness_predictions_shape, [4, expected_num_anchors, 1])
Example #27
Source File: box_predictor_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 5 votes |
def test_get_multi_class_predictions_from_two_feature_maps( self): num_classes_without_background = 6 def graph_fn(image_features1, image_features2): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features1, image_features2], num_predictions_per_location=[5, 5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features1 = np.random.rand(4, 8, 8, 64).astype(np.float32) image_features2 = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features1, image_features2]) self.assertAllEqual(box_encodings.shape, [4, 640, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 640, num_classes_without_background+1])
Example #28
Source File: box_predictor_test.py From ros_people_object_detection_tensorflow with Apache License 2.0 | 5 votes |
def test_get_multi_class_predictions_for_five_aspect_ratios_per_location( self): num_classes_without_background = 6 def graph_fn(image_features): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=1, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features], num_predictions_per_location=[5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat(box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) image_features = np.random.rand(4, 8, 8, 64).astype(np.float32) (box_encodings, class_predictions_with_background) = self.execute( graph_fn, [image_features]) self.assertAllEqual(box_encodings.shape, [4, 320, 1, 4]) self.assertAllEqual(class_predictions_with_background.shape, [4, 320, num_classes_without_background+1])
Example #29
Source File: box_predictor_test.py From Gun-Detector with Apache License 2.0 | 4 votes |
def test_predictions_from_multiple_feature_maps_share_weights(self): num_classes_without_background = 6 def graph_fn(image_features1, image_features2): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams_fn=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=2, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features1, image_features2], num_predictions_per_location=[5, 5], scope='BoxPredictor') box_encodings = tf.concat( box_predictions[box_predictor.BOX_ENCODINGS], axis=1) class_predictions_with_background = tf.concat( box_predictions[box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND], axis=1) return (box_encodings, class_predictions_with_background) with self.test_session(graph=tf.Graph()): graph_fn(tf.random_uniform([4, 32, 32, 3], dtype=tf.float32), tf.random_uniform([4, 16, 16, 3], dtype=tf.float32)) actual_variable_set = set( [var.op.name for var in tf.trainable_variables()]) expected_variable_set = set([ ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictionTower/conv2d_0/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictionTower/conv2d_0/BatchNorm/beta'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictionTower/conv2d_1/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictionTower/conv2d_1/BatchNorm/beta'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/BatchNorm/beta'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/BatchNorm/beta'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictor/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictor/biases'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictor/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictor/biases')]) self.assertEqual(expected_variable_set, actual_variable_set)
Example #30
Source File: box_predictor_test.py From Traffic-Rule-Violation-Detection-System with MIT License | 4 votes |
def test_predictions_from_multiple_feature_maps_share_weights(self): num_classes_without_background = 6 def graph_fn(image_features1, image_features2): conv_box_predictor = box_predictor.WeightSharedConvolutionalBoxPredictor( is_training=False, num_classes=num_classes_without_background, conv_hyperparams=self._build_arg_scope_with_conv_hyperparams(), depth=32, num_layers_before_predictor=2, box_code_size=4) box_predictions = conv_box_predictor.predict( [image_features1, image_features2], num_predictions_per_location=[5, 5], scope='BoxPredictor') box_encodings = box_predictions[box_predictor.BOX_ENCODINGS] class_predictions_with_background = box_predictions[ box_predictor.CLASS_PREDICTIONS_WITH_BACKGROUND] return (box_encodings, class_predictions_with_background) with self.test_session(graph=tf.Graph()): graph_fn(tf.random_uniform([4, 32, 32, 3], dtype=tf.float32), tf.random_uniform([4, 16, 16, 3], dtype=tf.float32)) actual_variable_set = set( [var.op.name for var in tf.trainable_variables()]) expected_variable_set = set([ ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictionTower/conv2d_0/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictionTower/conv2d_0/biases'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictionTower/conv2d_1/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictionTower/conv2d_1/biases'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_0/biases'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictionTower/conv2d_1/biases'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictor/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'BoxEncodingPredictor/biases'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictor/weights'), ('BoxPredictor/WeightSharedConvolutionalBoxPredictor/' 'ClassPredictor/biases')]) self.assertEqual(expected_variable_set, actual_variable_set)