Made iou threshold actually count

Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
2019-08-05 13:44:34 +02:00
parent 6576f3d5e1
commit f4982e364c
2 changed files with 27 additions and 13 deletions

View File

@ -171,7 +171,7 @@ def _ssd_train(args: argparse.Namespace) -> None:
_init_eager_mode() _init_eager_mode()
batch_size, image_size, learning_rate, steps_per_val_epoch, nr_classes, \ batch_size, image_size, learning_rate, steps_per_val_epoch, nr_classes, \
iou_threshold, dropout_rate, top_k, nr_trajectories, \ dropout_rate, top_k, nr_trajectories, \
coco_path, summary_path, weights_path, train_gt_path, val_gt_path, \ coco_path, summary_path, weights_path, train_gt_path, val_gt_path, \
save_train_images, save_summaries = _ssd_train_get_config_values(conf.get_property) save_train_images, save_summaries = _ssd_train_get_config_values(conf.get_property)
@ -188,7 +188,6 @@ def _ssd_train(args: argparse.Namespace) -> None:
image_size, image_size,
nr_classes, nr_classes,
"training", "training",
iou_threshold,
dropout_rate, dropout_rate,
top_k, top_k,
pre_trained_weights_file) pre_trained_weights_file)
@ -241,7 +240,8 @@ def _ssd_test(args: argparse.Namespace) -> None:
_init_eager_mode() _init_eager_mode()
batch_size, image_size, learning_rate, \ batch_size, image_size, learning_rate, \
forward_passes_per_image, nr_classes, iou_threshold, dropout_rate, \ forward_passes_per_image, nr_classes, confidence_threshold, iou_threshold, \
dropout_rate, \
use_entropy_threshold, entropy_threshold_min, entropy_threshold_max, \ use_entropy_threshold, entropy_threshold_min, entropy_threshold_max, \
use_coco, \ use_coco, \
top_k, nr_trajectories, test_pretrained, \ top_k, nr_trajectories, test_pretrained, \
@ -260,7 +260,6 @@ def _ssd_test(args: argparse.Namespace) -> None:
image_size, image_size,
nr_classes, nr_classes,
"training", "training",
iou_threshold,
dropout_rate, dropout_rate,
top_k, top_k,
weights_file) weights_file)
@ -291,6 +290,8 @@ def _ssd_test(args: argparse.Namespace) -> None:
use_entropy_threshold, use_entropy_threshold,
entropy_threshold_min, entropy_threshold_min,
entropy_threshold_max, entropy_threshold_max,
confidence_threshold,
iou_threshold,
output_path, output_path,
coco_path, coco_path,
use_dropout, use_dropout,
@ -532,7 +533,7 @@ def _ssd_evaluate_unbatch_list(glob_string: str) -> List[np.ndarray]:
def _ssd_train_get_config_values(config_get: Callable[[str], Union[str, float, int, bool]] def _ssd_train_get_config_values(config_get: Callable[[str], Union[str, float, int, bool]]
) -> Tuple[int, int, float, int, int, float, float, int, int, ) -> Tuple[int, int, float, int, int, float, int, int,
str, str, str, str, str, str, str, str, str, str,
bool, bool]: bool, bool]:
@ -541,7 +542,6 @@ def _ssd_train_get_config_values(config_get: Callable[[str], Union[str, float, i
learning_rate = config_get("Parameters.learning_rate") learning_rate = config_get("Parameters.learning_rate")
steps_per_val_epoch = config_get("Parameters.steps_per_val_epoch") steps_per_val_epoch = config_get("Parameters.steps_per_val_epoch")
nr_classes = config_get("Parameters.nr_classes") nr_classes = config_get("Parameters.nr_classes")
iou_threshold = config_get("Parameters.ssd_iou_threshold")
dropout_rate = config_get("Parameters.ssd_dropout_rate") dropout_rate = config_get("Parameters.ssd_dropout_rate")
top_k = config_get("Parameters.ssd_top_k") top_k = config_get("Parameters.ssd_top_k")
nr_trajectories = config_get("Parameters.nr_trajectories") nr_trajectories = config_get("Parameters.nr_trajectories")
@ -561,7 +561,6 @@ def _ssd_train_get_config_values(config_get: Callable[[str], Union[str, float, i
learning_rate, learning_rate,
steps_per_val_epoch, steps_per_val_epoch,
nr_classes, nr_classes,
iou_threshold,
dropout_rate, dropout_rate,
top_k, top_k,
nr_trajectories, nr_trajectories,
@ -579,7 +578,7 @@ def _ssd_train_get_config_values(config_get: Callable[[str], Union[str, float, i
def _ssd_test_get_config_values(args: argparse.Namespace, def _ssd_test_get_config_values(args: argparse.Namespace,
config_get: Callable[[str], Union[str, float, int, bool]] config_get: Callable[[str], Union[str, float, int, bool]]
) -> Tuple[int, int, float, int, int, float, float, ) -> Tuple[int, int, float, int, int, float, float, float,
bool, float, float, bool, float, float,
bool, bool,
int, int, bool, int, int, bool,
@ -590,6 +589,7 @@ def _ssd_test_get_config_values(args: argparse.Namespace,
learning_rate = config_get("Parameters.learning_rate") learning_rate = config_get("Parameters.learning_rate")
forward_passes_per_image = config_get("Parameters.ssd_forward_passes_per_image") forward_passes_per_image = config_get("Parameters.ssd_forward_passes_per_image")
nr_classes = config_get("Parameters.nr_classes") nr_classes = config_get("Parameters.nr_classes")
confidence_threshold = config_get("Parameters.ssd_confidence_threshold")
iou_threshold = config_get("Parameters.ssd_iou_threshold") iou_threshold = config_get("Parameters.ssd_iou_threshold")
dropout_rate = config_get("Parameters.ssd_dropout_rate") dropout_rate = config_get("Parameters.ssd_dropout_rate")
use_entropy_threshold = config_get("Parameters.ssd_use_entropy_threshold") use_entropy_threshold = config_get("Parameters.ssd_use_entropy_threshold")
@ -614,6 +614,7 @@ def _ssd_test_get_config_values(args: argparse.Namespace,
learning_rate, learning_rate,
forward_passes_per_image, forward_passes_per_image,
nr_classes, nr_classes,
confidence_threshold,
iou_threshold, iou_threshold,
dropout_rate, dropout_rate,
# #

View File

@ -51,8 +51,9 @@ tfe = tf.contrib.eager
def get_model(use_dropout: bool, def get_model(use_dropout: bool,
dropout_model: callable, vanilla_model: callable, dropout_model: callable, vanilla_model: callable,
image_size: int, nr_classes: int, mode: str, image_size: int, nr_classes: int, mode: str,
iou_threshold: float, dropout_rate: float, top_k: int, dropout_rate: float, top_k: int,
pre_trained_weights_file: Optional[str] = None) -> Tuple[tf.keras.models.Model, np.ndarray]: pre_trained_weights_file: Optional[str] = None,
iou_threshold: Optional[float] = None) -> Tuple[tf.keras.models.Model, np.ndarray]:
""" """
Returns the correct SSD model and the corresponding predictor sizes. Returns the correct SSD model and the corresponding predictor sizes.
@ -63,10 +64,11 @@ def get_model(use_dropout: bool,
image_size: size of the resized images image_size: size of the resized images
nr_classes: number of classes nr_classes: number of classes
mode: one of "training", "inference", "inference_fast" mode: one of "training", "inference", "inference_fast"
iou_threshold: all boxes with higher iou to local maximum box are suppressed
dropout_rate: rate for dropout layers (only applies if dropout is used) dropout_rate: rate for dropout layers (only applies if dropout is used)
top_k: number of highest scoring predictions kept for each batch item top_k: number of highest scoring predictions kept for each batch item
pre_trained_weights_file: path to h5 file with pre-trained weights pre_trained_weights_file: path to h5 file with pre-trained weights
iou_threshold: all boxes with higher iou to local maximum box are suppressed
(only relevant for inference modes)
Returns: Returns:
SSD model, predictor_sizes SSD model, predictor_sizes
@ -151,6 +153,8 @@ def predict(generator: callable,
use_entropy_threshold: bool, use_entropy_threshold: bool,
entropy_threshold_min: float, entropy_threshold_min: float,
entropy_threshold_max: float, entropy_threshold_max: float,
confidence_threshold: float,
iou_threshold: float,
output_path: str, output_path: str,
coco_path: str, coco_path: str,
use_dropout: bool, use_dropout: bool,
@ -171,6 +175,9 @@ def predict(generator: callable,
use_entropy_threshold: if True entropy thresholding is applied use_entropy_threshold: if True entropy thresholding is applied
entropy_threshold_min: specifies the minimum threshold for the entropy entropy_threshold_min: specifies the minimum threshold for the entropy
entropy_threshold_max: specifies the maximum threshold for the entropy entropy_threshold_max: specifies the maximum threshold for the entropy
confidence_threshold: minimum confidence required for box to count as positive
iou_threshold: all boxes with iou overlap larger than threshold to local maximum box
will be suppressed
output_path: the path in which the results should be saved output_path: the path in which the results should be saved
coco_path: the path to the COCO data set coco_path: the path to the COCO data set
use_dropout: if True, multiple forward passes and observations will be used use_dropout: if True, multiple forward passes and observations will be used
@ -195,6 +202,8 @@ def predict(generator: callable,
_decode_predictions, _decode_predictions,
decode_func=ssd_output_decoder.decode_detections_fast, decode_func=ssd_output_decoder.decode_detections_fast,
image_size=image_size, image_size=image_size,
confidence_threshold=confidence_threshold,
iou_threshold=iou_threshold
), ),
transform_func=functools.partial( transform_func=functools.partial(
_transform_predictions, _transform_predictions,
@ -347,13 +356,17 @@ def _predict_vanilla_step(inputs: np.ndarray, model: tf.keras.models.Model) -> n
def _decode_predictions(predictions: np.ndarray, def _decode_predictions(predictions: np.ndarray,
decode_func: callable, decode_func: callable,
image_size: int, image_size: int,
entropy_threshold: float) -> np.ndarray: entropy_threshold: float,
confidence_threshold: float,
iou_thresholdd: float) -> np.ndarray:
return decode_func( return decode_func(
y_pred=predictions, y_pred=predictions,
img_width=image_size, img_width=image_size,
img_height=image_size, img_height=image_size,
input_coords="corners", input_coords="corners",
entropy_thresh=entropy_threshold entropy_thresh=entropy_threshold,
confidence_thresh=confidence_threshold,
iou_threshold=iou_thresholdd
) )