Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review #6

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 53 additions & 45 deletions SeBRe_detection.ipynb

Large diffs are not rendered by default.

44 changes: 15 additions & 29 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,9 @@ def call(self, inputs):

# Non-max suppression
def nms(normalized_boxes, scores):
indices, scores = tf.image.non_max_suppression_with_scores(
normalized_boxes,
scores,
max_output_size=100,
iou_threshold=self.nms_threshold,
score_threshold=0.1,
soft_nms_sigma=0.5)
# indices = tf.image.non_max_suppression(
# normalized_boxes, scores, self.proposal_count,
# self.nms_threshold, name="rpn_non_max_suppression")
indices = tf.image.non_max_suppression(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains original SeBRe model logic, and results in invalid detection results, even when running detection using weights that were also trained with normal non_max_suppression.

invalid

normalized_boxes, scores, self.proposal_count,
self.nms_threshold, name="rpn_non_max_suppression")
proposals = tf.gather(normalized_boxes, indices)
# Pad if needed
padding = tf.maximum(self.proposal_count - tf.shape(proposals)[0], 0)
Expand Down Expand Up @@ -727,18 +720,11 @@ def nms_keep_map(class_id):
# Indices of ROIs of the given class
ixs = tf.where(tf.equal(pre_nms_class_ids, class_id))[:, 0]
# Apply NMS
class_keep, scores = tf.image.non_max_suppression_with_scores(
tf.to_float(tf.gather(pre_nms_rois, ixs)),
tf.gather(pre_nms_scores, ixs),
max_output_size=config.DETECTION_MAX_INSTANCES,
iou_threshold=config.DETECTION_NMS_THRESHOLD,
score_threshold=0.1,
soft_nms_sigma=0.5)
# class_keep = tf.image.non_max_suppression(
# tf.to_float(tf.gather(pre_nms_rois, ixs)),
# tf.gather(pre_nms_scores, ixs),
# max_output_size=config.DETECTION_MAX_INSTANCES,
# iou_threshold=config.DETECTION_NMS_THRESHOLD)
class_keep = tf.image.non_max_suppression(
tf.to_float(tf.gather(pre_nms_rois, ixs)),
tf.gather(pre_nms_scores, ixs),
max_output_size=config.DETECTION_MAX_INSTANCES,
iou_threshold=config.DETECTION_NMS_THRESHOLD)
# Map indicies
class_keep = tf.gather(keep, tf.gather(ixs, class_keep))
# Pad with -1 so returned tensors have the same shape
Expand Down Expand Up @@ -2101,13 +2087,13 @@ def compile(self, learning_rate, momentum):
None] * len(self.keras_model.outputs))

# Add metrics for losses
# for name in loss_names:
# # if name in self.keras_model.metrics_names:
# # continue
# layer = self.keras_model.get_layer(name)
# # self.keras_model.metrics_names.append(name)
# self.keras_model.add_metric(tf.reduce_mean(
# layer.output, keep_dims=True), name)
for name in loss_names:
if name in self.keras_model.metrics_names:
continue
layer = self.keras_model.get_layer(name)
self.keras_model.metrics_names.append(name)
self.keras_model.metrics_tensors.append(tf.reduce_mean(
layer.output, keep_dims=True))

def set_trainable(self, layer_regex, keras_model=None, indent=0, verbose=1):
"""Sets model layers as trainable if their names match
Expand Down
Loading