Commit 00ebd097 authored by Yuxin Wu's avatar Yuxin Wu

[FastRCNN] fix box selection in evaluation

parent 10186aa1
......@@ -46,7 +46,7 @@ To evaluate the performance (pretrained models can be downloaded in [model zoo](
Mean Average Precision @IoU=0.50:0.95:
+ trainval35k/minival, FASTRCNN_BATCH=256: 33.4. Takes 49h on 8 TitanX.
+ trainval35k/minival, FASTRCNN_BATCH=256: 33.7. Takes 49h on 8 TitanX.
+ trainval35k/minival, FASTRCNN_BATCH=64: 32.2. Takes 31h on 8 TitanX.
The hyperparameters are not carefully tuned. You can probably get better performance by e.g. training longer.
......
......@@ -44,8 +44,8 @@ def get_tf_nms(num_output, thresh):
def nms_fastrcnn_results(boxes, probs):
"""
Args:
boxes: nx4 floatbox in float32
probs: nxC
boxes: nx#catx4 floatbox in float32
probs: nx#class
Returns:
[DetectionResult]
......@@ -60,7 +60,7 @@ def nms_fastrcnn_results(boxes, probs):
if ids.size == 0:
continue
probs_k = probs[ids, klass].flatten()
boxes_k = boxes[ids, :]
boxes_k = boxes[ids, klass - 1, :]
selected_ids = nms_func(boxes_k, probs_k)
selected_boxes = boxes_k[selected_ids, :].copy()
ret.append(DetectionResult(klass, selected_boxes, probs_k[selected_ids]))
......
......@@ -137,14 +137,11 @@ class Model(ModelDesc):
add_moving_summary(k)
else:
label_probs = tf.nn.softmax(fastrcnn_label_logits, name='fastrcnn_all_probs') # #proposal x #Class
labels = tf.argmax(fastrcnn_label_logits, axis=1)
fg_ind, fg_box_logits = fastrcnn_predict_boxes(labels, fastrcnn_box_logits)
fg_label_probs = tf.gather(label_probs, fg_ind, name='fastrcnn_fg_probs')
fg_boxes = tf.gather(proposal_boxes, fg_ind)
fg_box_logits = fg_box_logits / tf.constant(config.FASTRCNN_BBOX_REG_WEIGHTS)
decoded_boxes = decode_bbox_target(fg_box_logits, fg_boxes) # #fgx4, floatbox
decoded_boxes = tf.identity(decoded_boxes, name='fastrcnn_fg_boxes')
anchors = tf.tile(tf.expand_dims(proposal_boxes, 1), [1, config.NUM_CLASS - 1, 1]) # #proposal x #Cat x 4
decoded_boxes = decode_bbox_target(
fastrcnn_box_logits /
tf.constant(config.FASTRCNN_BBOX_REG_WEIGHTS), anchors)
decoded_boxes = tf.identity(decoded_boxes, name='fastrcnn_all_boxes')
def _get_optimizer(self):
lr = tf.get_variable('learning_rate', initializer=0.003, trainable=False)
......@@ -210,8 +207,8 @@ def offline_evaluate(model_path, output_file):
session_init=get_model_loader(model_path),
input_names=['image'],
output_names=[
'fastrcnn_fg_probs',
'fastrcnn_fg_boxes',
'fastrcnn_all_probs',
'fastrcnn_all_boxes',
]))
df = get_eval_dataflow()
df = PrefetchDataZMQ(df, 1)
......@@ -227,8 +224,8 @@ def predict(model_path, input_file):
session_init=get_model_loader(model_path),
input_names=['image'],
output_names=[
'fastrcnn_fg_probs',
'fastrcnn_fg_boxes',
'fastrcnn_all_probs',
'fastrcnn_all_boxes',
]))
img = cv2.imread(input_file, cv2.IMREAD_COLOR)
results = detect_one_image(img, pred)
......@@ -239,7 +236,8 @@ def predict(model_path, input_file):
class EvalCallback(Callback):
def _setup_graph(self):
self.pred = self.trainer.get_predictor(['image'], ['fastrcnn_fg_probs', 'fastrcnn_fg_boxes'])
self.pred = self.trainer.get_predictor(
['image'], ['fastrcnn_all_probs', 'fastrcnn_all_boxes'])
self.df = PrefetchDataZMQ(get_eval_dataflow(), 1)
def _before_train(self):
......
......@@ -43,7 +43,6 @@ Training examples with __reproducible__ and meaningful performance.
Example needs to satisfy one of the following:
+ Reproduce performance of a published or well-known paper.
+ Get state-of-the-art performance on some task.
+ Illustrate a new way of using the library that is currently not covered.
__Performance is important__. Usually deep learning code is easy to write,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment