pub struct StyleTransfer {
pub content_model: Model,
pub style_model: Model,
pub iterations: usize,
pub content_weight: f32,
pub style_weight: f32,
pub learning_rate: f32,
}Expand description
Style transfer engine.
Fields§
§content_model: Model§style_model: Model§iterations: usize§content_weight: f32§style_weight: f32§learning_rate: f32Implementations§
Source§impl StyleTransfer
impl StyleTransfer
pub fn new(content_model: Model, style_model: Model) -> Self
Sourcepub fn from_preset(preset: StylePreset) -> Self
pub fn from_preset(preset: StylePreset) -> Self
Create a style transfer engine from a preset.
Sourcepub fn gram_matrix(features: &Tensor) -> Tensor
pub fn gram_matrix(features: &Tensor) -> Tensor
Compute the Gram matrix: G = F^T * F, where F has shape (C, N). If the input is flattened or 1-D, reshape to (sqrt, sqrt) approximately.
Sourcepub fn content_loss(generated: &Tensor, target: &Tensor) -> f32
pub fn content_loss(generated: &Tensor, target: &Tensor) -> f32
Content loss: mean squared error between generated and target features.
Sourcepub fn style_loss(generated_gram: &Tensor, target_gram: &Tensor) -> f32
pub fn style_loss(generated_gram: &Tensor, target_gram: &Tensor) -> f32
Style loss: MSE between Gram matrices of generated and target features.
Auto Trait Implementations§
impl Freeze for StyleTransfer
impl RefUnwindSafe for StyleTransfer
impl Send for StyleTransfer
impl Sync for StyleTransfer
impl Unpin for StyleTransfer
impl UnsafeUnpin for StyleTransfer
impl UnwindSafe for StyleTransfer
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.