@@ -383,7 +383,7 @@ images, labels = ...
383
383
predictions = ...
384
384
385
385
# Define the loss functions and get the total loss.
386
- loss = losses.ClassificationLoss (predictions, labels)
386
+ loss = losses.cross_entropy_loss (predictions, labels)
387
387
```
388
388
389
389
In this example, we start by creating the model (using TF-Slim's VGG
@@ -398,16 +398,16 @@ images, scene_labels, depth_labels = ...
398
398
scene_predictions, depth_predictions = CreateMultiTaskModel(images)
399
399
400
400
# Define the loss functions and get the total loss.
401
- classification_loss = slim.losses.ClassificationLoss (scene_predictions, scene_labels)
402
- sum_of_squares_loss = slim.losses.SumOfSquaresLoss (depth_predictions, depth_labels)
401
+ classification_loss = slim.losses.cross_entropy_loss (scene_predictions, scene_labels)
402
+ sum_of_squares_loss = slim.losses.l2loss (depth_predictions - depth_labels)
403
403
404
404
# The following two lines have the same effect:
405
405
total_loss1 = classification_loss + sum_of_squares_loss
406
406
total_loss2 = tf.get_collection(slim.losses.LOSSES_COLLECTION )
407
407
```
408
408
409
409
In this example, we have two losses which we add by calling
410
- ` losses.ClassificationLoss ` and ` losses.SumOfSquaresLoss ` . We can obtain the
410
+ ` losses.cross_entropy_loss ` and ` losses.l2loss ` . We can obtain the
411
411
total loss by adding them together (` total_loss1 ` ) or by calling
412
412
` losses.GetTotalLoss() ` . How did this work? When you create a loss function via
413
413
TF-Slim, TF-Slim adds the loss to a special TensorFlow collection of loss
@@ -426,8 +426,8 @@ images, scene_labels, depth_labels, pose_labels = ...
426
426
scene_predictions, depth_predictions, pose_predictions = CreateMultiTaskModel(images)
427
427
428
428
# Define the loss functions and get the total loss.
429
- classification_loss = slim.losses.ClassificationLoss (scene_predictions, scene_labels)
430
- sum_of_squares_loss = slim.losses.SumOfSquaresLoss (depth_predictions, depth_labels)
429
+ classification_loss = slim.losses.cross_entropy_loss (scene_predictions, scene_labels)
430
+ sum_of_squares_loss = slim.losses.l2loss (depth_predictions - depth_labels)
431
431
pose_loss = MyCustomLossFunction(pose_predictions, pose_labels)
432
432
tf.add_to_collection(slim.losses.LOSSES_COLLECTION , pose_loss) # Letting TF-Slim know about the additional loss.
433
433
0 commit comments