def get_losses(self): """Generates a dictionary of losses to apply to each path. Done in the detection generator because all parameters are the same across both loss and detection generator. Returns: Dict[str, tf.Tensor] of losses """ loss = yolo_loss.YoloLoss(keys=self._keys, classes=self._classes, anchors=self._anchors, path_strides=self._path_scale, truth_thresholds=self._truth_thresh, ignore_thresholds=self._ignore_thresh, loss_types=self._loss_type, iou_normalizers=self._iou_normalizer, cls_normalizers=self._cls_normalizer, object_normalizers=self._object_normalizer, objectness_smooths=self._objectness_smooth, box_types=self._box_type, max_deltas=self._max_delta, scale_xys=self._scale_xy, use_scaled_loss=self._use_scaled_loss, update_on_repeat=self._update_on_repeat, label_smoothing=self._label_smoothing) return loss
def test_loss_init(self, scaled): """Test creation of YOLO family models.""" def inpdict(input_shape, dtype=tf.float32): inputs = {} for key in input_shape: inputs[key] = tf.ones(input_shape[key], dtype=dtype) return inputs tf.keras.backend.set_image_data_format('channels_last') input_shape = { '3': [1, 52, 52, 255], '4': [1, 26, 26, 255], '5': [1, 13, 13, 255] } classes = 80 anchors = { '3': [[12.0, 19.0], [31.0, 46.0], [96.0, 54.0]], '4': [[46.0, 114.0], [133.0, 127.0], [79.0, 225.0]], '5': [[301.0, 150.0], [172.0, 286.0], [348.0, 340.0]] } keys = ['3', '4', '5'] path_strides = {key: 2**int(key) for key in keys} loss = yolo_loss.YoloLoss( keys, classes, anchors, path_strides=path_strides, truth_thresholds={key: 1.0 for key in keys}, ignore_thresholds={key: 0.7 for key in keys}, loss_types={key: 'ciou' for key in keys}, iou_normalizers={key: 0.05 for key in keys}, cls_normalizers={key: 0.5 for key in keys}, obj_normalizers={key: 1.0 for key in keys}, objectness_smooths={key: 1.0 for key in keys}, box_types={key: 'scaled' for key in keys}, scale_xys={key: 2.0 for key in keys}, max_deltas={key: 30.0 for key in keys}, label_smoothing=0.0, use_scaled_loss=scaled, update_on_repeat=True) count = inpdict({ '3': [1, 52, 52, 3, 1], '4': [1, 26, 26, 3, 1], '5': [1, 13, 13, 3, 1] }) ind = inpdict({ '3': [1, 300, 3], '4': [1, 300, 3], '5': [1, 300, 3] }, tf.int32) truths = inpdict({ '3': [1, 300, 6], '4': [1, 300, 6], '5': [1, 300, 6] }) boxes = tf.ones([1, 300, 4], dtype=tf.float32) classes = tf.ones([1, 300], dtype=tf.float32) gt = { 'true_conf': count, 'inds': ind, 'upds': truths, 'bbox': boxes, 'classes': classes } _, _, _ = loss(gt, inpdict(input_shape))