def calculate_loss(self, logits):
logits = tf.reshape(
logits, shape=[self.batch_size, self.cell_size, self.cell_size,
self.n_boxes, 5])
# ??class_pred?box_pred
self.box_preds = tf.concat(
[tf.sigmoid(logits[:,:,:,:,0:2]),
logits[:,:,:,:,2:4],
tf.sigmoid(logits[:,:,:,:,4:5])], axis=4)
# ?????example
results = tf.while_loop(
cond=self._one_example_cond,
body=self._one_example_body,
loop_vars=[tf.constant(0), self.batch_size,
tf.constant(0.0), tf.constant(0.0), tf.constant(0.0),
tf.constant(0.0), tf.constant(0.0), tf.constant(0.0), tf.constant(0.0)])
coord_loss = results[2]
object_loss = results[3]
noobject_loss = results[4]
iou_value = results[5]
object_value = results[6]
anyobject_value = results[7]
recall_value = results[8]
# ?????
coord_loss = coord_loss * self.coord_scale / self.batch_size
object_loss = object_loss * self.object_scale / self.batch_size
noobject_loss = noobject_loss * self.noobject_scale / self.batch_size
# ???
iou_value /= tf.reduce_sum(tf.cast(self.object_nums, tf.float32), axis=[0])
object_value /= tf.reduce_sum(tf.cast(self.object_nums, tf.float32), axis=[0])
anyobject_value /= (self.batch_size * self.cell_size * self.cell_size * self.n_boxes)
recall_value /= tf.reduce_sum(tf.cast(self.object_nums, tf.float32), axis=[0])
return coord_loss, object_loss, noobject_loss, \
iou_value, object_value, anyobject_value, recall_value
评论列表
文章目录