pub struct BCEWithLogitsLoss { /* private fields */ }
Expand description
This loss combines a Sigmoid layer and the BCELoss in one single class. This version is more numerically stable than using a plain Sigmoid followed by a BCELoss as, by combining the operations into one layer, we take advantage of the log-sum-exp trick for numerical stability.
-y log (1/(1 + exp(-x))) - (1-y) log(1 - 1/(1 + exp(-x)))
Prediction comes first, label comes second.
Implementations
sourceimpl BCEWithLogitsLoss
impl BCEWithLogitsLoss
pub fn new() -> BCEWithLogitsLoss
Trait Implementations
sourceimpl Default for BCEWithLogitsLoss
impl Default for BCEWithLogitsLoss
sourceimpl<'de> Deserialize<'de> for BCEWithLogitsLoss
impl<'de> Deserialize<'de> for BCEWithLogitsLoss
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl OpTrait for BCEWithLogitsLoss
impl OpTrait for BCEWithLogitsLoss
sourcefn apply(&self, input: &[Tensor], output: &[Tensor])
fn apply(&self, input: &[Tensor], output: &[Tensor])
The first is the prediction, the second input is the label ORDER IS IMPORTANT, SECOND ARGUMENT WON’T GET GRADEINT.
sourcefn grad(&self, input: &[Tensor], output_grad: &[Tensor], input_grad: &[Tensor])
fn grad(&self, input: &[Tensor], output_grad: &[Tensor], input_grad: &[Tensor])
Given the forward input value and backward output_grad, Update weight gradient. return backward input gradeint.
sourcefn get_values(&self) -> Vec<Tensor>
fn get_values(&self) -> Vec<Tensor>
access weight values
sourcefn get_input_size(&self) -> usize
fn get_input_size(&self) -> usize
The number of input needs by this op.
sourcefn get_output_size(&self) -> usize
fn get_output_size(&self) -> usize
The number of output produced by this op.
fn set_values(&self, _v: &[Tensor])
fn as_any(&self) -> &dyn Any
sourceimpl Serialize for BCEWithLogitsLoss
impl Serialize for BCEWithLogitsLoss
Auto Trait Implementations
impl !RefUnwindSafe for BCEWithLogitsLoss
impl !Send for BCEWithLogitsLoss
impl !Sync for BCEWithLogitsLoss
impl Unpin for BCEWithLogitsLoss
impl !UnwindSafe for BCEWithLogitsLoss
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more