Skip to content

Commit

Permalink
chore: Change name of DecodeDetections2 layer
Browse files Browse the repository at this point in the history
The previous name was non-descriptive and inconsistent with the rest of the code.
  • Loading branch information
pierluigiferrari committed Apr 23, 2018
1 parent 5156b65 commit 03fa7c4
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 45 deletions.
11 changes: 5 additions & 6 deletions keras_layers/keras_layer_DecodeDetections2.py
Expand Up @@ -27,7 +27,7 @@
from keras.engine.topology import InputSpec
from keras.engine.topology import Layer

class DecodeDetections2(Layer):
class DecodeDetectionsFast(Layer):
'''
A Keras layer to decode the raw SSD prediction output.
Expand Down Expand Up @@ -103,11 +103,11 @@ def __init__(self,
self.tf_img_width = tf.constant(self.img_width, dtype=tf.float32, name='img_width')
self.tf_nms_max_output_size = tf.constant(self.nms_max_output_size, name='nms_max_output_size')

super(DecodeDetections2, self).__init__(**kwargs)
super(DecodeDetectionsFast, self).__init__(**kwargs)

def build(self, input_shape):
self.input_spec = [InputSpec(shape=input_shape)]
super(DecodeDetections2, self).build(input_shape)
super(DecodeDetectionsFast, self).build(input_shape)

def call(self, y_pred, mask=None):
'''
Expand Down Expand Up @@ -157,8 +157,7 @@ def non_normalized_coords():
y_pred = tf.concat(values=[class_ids, confidences, xmin, ymin, xmax, ymax], axis=-1)

#####################################################################################
# 2. Perform confidence thresholding, per-class non-maximum suppression, and
# top-k filtering.
# 2. Perform confidence thresholding, non-maximum suppression, and top-k filtering.
#####################################################################################

batch_size = tf.shape(y_pred)[0] # Output dtype: tf.int32
Expand Down Expand Up @@ -264,5 +263,5 @@ def get_config(self):
'img_height': self.img_height,
'img_width': self.img_width,
}
base_config = super(DecodeDetections2, self).get_config()
base_config = super(DecodeDetectionsFast, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
20 changes: 10 additions & 10 deletions models/keras_ssd300.py
Expand Up @@ -27,7 +27,7 @@
from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes
from keras_layers.keras_layer_L2Normalization import L2Normalization
from keras_layers.keras_layer_DecodeDetections import DecodeDetections
from keras_layers.keras_layer_DecodeDetections2 import DecodeDetections2
from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast

def ssd_300(image_size,
n_classes,
Expand Down Expand Up @@ -433,15 +433,15 @@ def input_channel_swap(tensor):
name='decoded_predictions')(predictions)
model = Model(inputs=x, outputs=decoded_predictions)
elif mode == 'inference_fast':
decoded_predictions = DecodeDetections2(confidence_thresh=confidence_thresh,
iou_threshold=iou_threshold,
top_k=top_k,
nms_max_output_size=nms_max_output_size,
coords=coords,
normalize_coords=normalize_coords,
img_height=img_height,
img_width=img_width,
name='decoded_predictions')(predictions)
decoded_predictions = DecodeDetectionsFast(confidence_thresh=confidence_thresh,
iou_threshold=iou_threshold,
top_k=top_k,
nms_max_output_size=nms_max_output_size,
coords=coords,
normalize_coords=normalize_coords,
img_height=img_height,
img_width=img_width,
name='decoded_predictions')(predictions)
model = Model(inputs=x, outputs=decoded_predictions)
else:
raise ValueError("`mode` must be one of 'training', 'inference' or 'inference_fast', but received '{}'.".format(mode))
Expand Down
20 changes: 10 additions & 10 deletions models/keras_ssd512.py
Expand Up @@ -27,7 +27,7 @@
from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes
from keras_layers.keras_layer_L2Normalization import L2Normalization
from keras_layers.keras_layer_DecodeDetections import DecodeDetections
from keras_layers.keras_layer_DecodeDetections2 import DecodeDetections2
from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast

def ssd_512(image_size,
n_classes,
Expand Down Expand Up @@ -452,15 +452,15 @@ def input_channel_swap(tensor):
name='decoded_predictions')(predictions)
model = Model(inputs=x, outputs=decoded_predictions)
elif mode == 'inference_fast':
decoded_predictions = DecodeDetections2(confidence_thresh=confidence_thresh,
iou_threshold=iou_threshold,
top_k=top_k,
nms_max_output_size=nms_max_output_size,
coords=coords,
normalize_coords=normalize_coords,
img_height=img_height,
img_width=img_width,
name='decoded_predictions')(predictions)
decoded_predictions = DecodeDetectionsFast(confidence_thresh=confidence_thresh,
iou_threshold=iou_threshold,
top_k=top_k,
nms_max_output_size=nms_max_output_size,
coords=coords,
normalize_coords=normalize_coords,
img_height=img_height,
img_width=img_width,
name='decoded_predictions')(predictions)
model = Model(inputs=x, outputs=decoded_predictions)
else:
raise ValueError("`mode` must be one of 'training', 'inference' or 'inference_fast', but received '{}'.".format(mode))
Expand Down
20 changes: 10 additions & 10 deletions models/keras_ssd7.py
Expand Up @@ -26,7 +26,7 @@

from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes
from keras_layers.keras_layer_DecodeDetections import DecodeDetections
from keras_layers.keras_layer_DecodeDetections2 import DecodeDetections2
from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast

def build_model(image_size,
n_classes,
Expand Down Expand Up @@ -407,15 +407,15 @@ def input_channel_swap(tensor):
name='decoded_predictions')(predictions)
model = Model(inputs=x, outputs=decoded_predictions)
elif mode == 'inference_fast':
decoded_predictions = DecodeDetections2(confidence_thresh=confidence_thresh,
iou_threshold=iou_threshold,
top_k=top_k,
nms_max_output_size=nms_max_output_size,
coords=coords,
normalize_coords=normalize_coords,
img_height=img_height,
img_width=img_width,
name='decoded_predictions')(predictions)
decoded_predictions = DecodeDetectionsFast(confidence_thresh=confidence_thresh,
iou_threshold=iou_threshold,
top_k=top_k,
nms_max_output_size=nms_max_output_size,
coords=coords,
normalize_coords=normalize_coords,
img_height=img_height,
img_width=img_width,
name='decoded_predictions')(predictions)
model = Model(inputs=x, outputs=decoded_predictions)
else:
raise ValueError("`mode` must be one of 'training', 'inference' or 'inference_fast', but received '{}'.".format(mode))
Expand Down
2 changes: 1 addition & 1 deletion ssd300_evaluation_COCO.ipynb
Expand Up @@ -43,7 +43,7 @@
"from keras_loss_function.keras_ssd_loss import SSDLoss\n",
"from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes\n",
"from keras_layers.keras_layer_DecodeDetections import DecodeDetections\n",
"from keras_layers.keras_layer_DecodeDetections2 import DecodeDetections2\n",
"from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast\n",
"from keras_layers.keras_layer_L2Normalization import L2Normalization\n",
"from data_generator.object_detection_2d_data_generator import DataGenerator\n",
"from eval_utils.coco_utils import get_coco_category_maps, predict_all_to_json\n",
Expand Down
2 changes: 1 addition & 1 deletion ssd300_evaluation_Pascal_VOC.ipynb
Expand Up @@ -30,7 +30,7 @@
"from keras_loss_function.keras_ssd_loss import SSDLoss\n",
"from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes\n",
"from keras_layers.keras_layer_DecodeDetections import DecodeDetections\n",
"from keras_layers.keras_layer_DecodeDetections2 import DecodeDetections2\n",
"from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast\n",
"from keras_layers.keras_layer_L2Normalization import L2Normalization\n",
"from data_generator.object_detection_2d_data_generator import DataGenerator\n",
"from eval_utils.pascal_voc_utils import predict_all_to_txt\n",
Expand Down
2 changes: 1 addition & 1 deletion ssd300_inference.ipynb
Expand Up @@ -29,7 +29,7 @@
"from keras_loss_function.keras_ssd_loss import SSDLoss\n",
"from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes\n",
"from keras_layers.keras_layer_DecodeDetections import DecodeDetections\n",
"from keras_layers.keras_layer_DecodeDetections2 import DecodeDetections2\n",
"from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast\n",
"from keras_layers.keras_layer_L2Normalization import L2Normalization\n",
"\n",
"from ssd_encoder_decoder.ssd_output_decoder import decode_detections, decode_detections_fast\n",
Expand Down
4 changes: 2 additions & 2 deletions ssd300_training.ipynb
Expand Up @@ -32,7 +32,7 @@
"from keras_loss_function.keras_ssd_loss import SSDLoss\n",
"from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes\n",
"from keras_layers.keras_layer_DecodeDetections import DecodeDetections\n",
"from keras_layers.keras_layer_DecodeDetections2 import DecodeDetections2\n",
"from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast\n",
"from keras_layers.keras_layer_L2Normalization import L2Normalization\n",
"\n",
"from ssd_encoder_decoder.ssd_input_encoder import SSDInputEncoder\n",
Expand Down Expand Up @@ -185,7 +185,7 @@
"\n",
"The SSD model contains custom objects: Neither the loss function nor the anchor box or L2-normalization layer types are contained in the Keras core library, so we need to provide them to the model loader.\n",
"\n",
"This next code cell assumes that you want to load a model that was created in 'training' mode. If you want to load a model that was created in 'inference' or 'inference_fast' mode, you'll have to add the `DecodeDetections` or `DecodeDetections2` layer type to the `custom_objects` dictionary below."
"This next code cell assumes that you want to load a model that was created in 'training' mode. If you want to load a model that was created in 'inference' or 'inference_fast' mode, you'll have to add the `DecodeDetections` or `DecodeDetectionsFast` layer type to the `custom_objects` dictionary below."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion ssd512_inference.ipynb
Expand Up @@ -29,7 +29,7 @@
"from keras_loss_function.keras_ssd_loss import SSDLoss\n",
"from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes\n",
"from keras_layers.keras_layer_DecodeDetections import DecodeDetections\n",
"from keras_layers.keras_layer_DecodeDetections2 import DecodeDetections2\n",
"from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast\n",
"from keras_layers.keras_layer_L2Normalization import L2Normalization\n",
"\n",
"from ssd_encoder_decoder.ssd_output_decoder import decode_detections, decode_detections_fast\n",
Expand Down
4 changes: 2 additions & 2 deletions ssd7_training.ipynb
Expand Up @@ -32,7 +32,7 @@
"from keras_loss_function.keras_ssd_loss import SSDLoss\n",
"from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes\n",
"from keras_layers.keras_layer_DecodeDetections import DecodeDetections\n",
"from keras_layers.keras_layer_DecodeDetections2 import DecodeDetections2\n",
"from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast\n",
"\n",
"from ssd_encoder_decoder.ssd_input_encoder import SSDInputEncoder\n",
"from ssd_encoder_decoder.ssd_output_decoder import decode_detections, decode_detections_fast\n",
Expand Down Expand Up @@ -167,7 +167,7 @@
"\n",
"The SSD model contains custom objects: Neither the loss function, nor the anchor box or detection decoding layer types are contained in the Keras core library, so we need to provide them to the model loader.\n",
"\n",
"This next code cell assumes that you want to load a model that was created in 'training' mode. If you want to load a model that was created in 'inference' or 'inference_fast' mode, you'll have to add the `DecodeDetections` or `DecodeDetections2` layer type to the `custom_objects` dictionary below."
"This next code cell assumes that you want to load a model that was created in 'training' mode. If you want to load a model that was created in 'inference' or 'inference_fast' mode, you'll have to add the `DecodeDetections` or `DecodeDetectionsFast` layer type to the `custom_objects` dictionary below."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion weight_sampling_tutorial.ipynb
Expand Up @@ -426,7 +426,7 @@
"from keras_loss_function.keras_ssd_loss import SSDLoss\n",
"from keras_layers.keras_layer_AnchorBoxes import AnchorBoxes\n",
"from keras_layers.keras_layer_DecodeDetections import DecodeDetections\n",
"from keras_layers.keras_layer_DecodeDetections2 import DecodeDetections2\n",
"from keras_layers.keras_layer_DecodeDetectionsFast import DecodeDetectionsFast\n",
"from keras_layers.keras_layer_L2Normalization import L2Normalization\n",
"\n",
"from data_generator.object_detection_2d_data_generator import DataGenerator\n",
Expand Down

0 comments on commit 03fa7c4

Please sign in to comment.