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§
Source§impl BCEWithLogitsLoss
impl BCEWithLogitsLoss
pub fn new() -> BCEWithLogitsLoss
Trait Implementations§
Source§impl Default for BCEWithLogitsLoss
impl Default for BCEWithLogitsLoss
Source§impl<'de> Deserialize<'de> for BCEWithLogitsLoss
impl<'de> Deserialize<'de> for BCEWithLogitsLoss
Source§fn 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
Source§impl OpTrait for BCEWithLogitsLoss
impl OpTrait for BCEWithLogitsLoss
Source§fn 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.
Source§fn 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.
Source§fn get_values(&self) -> Vec<Tensor>
fn get_values(&self) -> Vec<Tensor>
access weight values
Source§fn get_input_size(&self) -> usize
fn get_input_size(&self) -> usize
The number of input needs by this op.
Source§fn 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
Auto Trait Implementations§
impl Freeze for BCEWithLogitsLoss
impl !RefUnwindSafe for BCEWithLogitsLoss
impl !Send for BCEWithLogitsLoss
impl !Sync for BCEWithLogitsLoss
impl Unpin for BCEWithLogitsLoss
impl !UnwindSafe for BCEWithLogitsLoss
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more