myco.losses¶
Loss functions for evaluating model performance and optimizing model training. Losses are a subset of metrics - all losses are metrics, but not all metrics are losses. This is because a loss must decrease in value to indicate an increase in model performance. R-squared is an example of a metric that is not a loss - an increase in r2 corresponds to better performance. Losses and Metrics are also independed python object types that have different assumptions regarding subclasses and class functions.
MycoLoss
¶
Bases: tf.keras.losses.Loss
Base class for creating loss functions to evaluate performance on slices (subsets) of data
Source code in myco/losses.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
__init__(loss_function, name=None, nodata=None, greater_than=None, less_than=None, dtype=tf.float32, **kwargs)
¶
Create a custom loss function that filters input data prior to the loss calculation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
loss_function |
Callable
|
a callable function that takes (y_true, y_pred) arguments and returns a scalar value |
required |
name |
str
|
the name of the loss function (this is printed during model training) |
None
|
nodata |
float
|
the nodata value to exclude from calculations |
None
|
greater_than |
float
|
only include values above this threshold |
None
|
less_than |
float
|
only include values below this threshold |
None
|
dtype |
tf.dtypes.DType
|
the tf data type to compute the metric in. Not implemented yet. |
tf.float32
|
Source code in myco/losses.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
call(y_true, y_pred, sample_weight=None)
¶
Logic for the loss calculation
Source code in myco/losses.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
get_loss(name)
¶
Returns an un-initiated loss function object by name.
Source code in myco/losses.py
211 212 213 214 |
|
get_names()
¶
Returns a list of the available loss functions supported in configuration.
Source code in myco/losses.py
206 207 208 |
|