Skip to content

Commit 96047df

Browse files
committed
Formats codebase with rustfmt
Applies rustfmt configuration to ensure consistent code style, including import organization, line breaks for readability, and trailing newlines. Improves maintainability and adheres to Rust formatting standards.
1 parent 04b7a0d commit 96047df

16 files changed

Lines changed: 71 additions & 67 deletions

File tree

crates/birefnet-backbones/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,4 @@ mod tests {
277277
use burn::backend::Cpu;
278278

279279
pub type TestBackend = Cpu;
280-
}
280+
}

crates/birefnet-extra-ops/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ mod tests {
2323
use burn::backend::Cpu;
2424

2525
pub type TestBackend = Cpu;
26-
}
26+
}

crates/birefnet-inference/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ mod tests {
1111
use burn::backend::Cpu;
1212

1313
pub type TestBackend = Cpu;
14-
}
14+
}

crates/birefnet-loss/src/birefnet_loss.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,15 @@ impl<B: Backend> BiRefNetLoss<B> {
246246
let mut total_loss = pixel_loss;
247247

248248
// Add classification loss if enabled and predictions are provided
249-
if let Some(ref cls_loss) = self.classification_loss {
250-
if let (Some(class_preds), Some(class_targets)) = (class_preds, class_targets) {
251-
let cls_loss_value = cls_loss
252-
.forward(class_preds, class_targets, Reduction::Mean)
253-
.mul_scalar(self.classification_weight)
254-
.mul_scalar(self.global_scale);
255-
256-
total_loss = total_loss + cls_loss_value;
257-
}
249+
if let Some(ref cls_loss) = self.classification_loss
250+
&& let (Some(class_preds), Some(class_targets)) = (class_preds, class_targets)
251+
{
252+
let cls_loss_value = cls_loss
253+
.forward(class_preds, class_targets, Reduction::Mean)
254+
.mul_scalar(self.classification_weight)
255+
.mul_scalar(self.global_scale);
256+
257+
total_loss = total_loss + cls_loss_value;
258258
}
259259

260260
Ok(total_loss)
@@ -314,21 +314,21 @@ impl<B: Backend> BiRefNetLoss<B> {
314314
let mut total_loss = pixel_loss;
315315

316316
// Add classification loss if enabled and predictions are provided
317-
if let Some(ref cls_loss) = self.classification_loss {
318-
if let (Some(class_preds), Some(class_targets)) = (class_preds, class_targets) {
319-
let cls_loss_value = cls_loss
320-
.forward(class_preds, class_targets, Reduction::Mean)
321-
.mul_scalar(self.classification_weight)
322-
.mul_scalar(self.global_scale);
323-
324-
total_loss = total_loss.clone() + cls_loss_value.clone();
325-
326-
// Add classification loss to dictionary
327-
loss_dict.insert(
328-
"classification".to_owned(),
329-
cls_loss_value.into_scalar().to_f64(),
330-
);
331-
}
317+
if let Some(ref cls_loss) = self.classification_loss
318+
&& let (Some(class_preds), Some(class_targets)) = (class_preds, class_targets)
319+
{
320+
let cls_loss_value = cls_loss
321+
.forward(class_preds, class_targets, Reduction::Mean)
322+
.mul_scalar(self.classification_weight)
323+
.mul_scalar(self.global_scale);
324+
325+
total_loss = total_loss.clone() + cls_loss_value.clone();
326+
327+
// Add classification loss to dictionary
328+
loss_dict.insert(
329+
"classification".to_owned(),
330+
cls_loss_value.into_scalar().to_f64(),
331+
);
332332
}
333333

334334
// Add total loss to dictionary

crates/birefnet-loss/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ mod tests {
106106
use burn::backend::Cpu;
107107

108108
pub type TestBackend = Cpu;
109-
}
109+
}

crates/birefnet-metric/src/biou.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
//! for evaluating boundary-focused segmentation performance.
55
66
use core::marker::PhantomData;
7-
8-
use birefnet_util::{StructuringElement, erosion};
97
use std::sync::Arc;
108

9+
use birefnet_util::{StructuringElement, erosion};
1110
use burn::{
1211
prelude::*,
1312
tensor::{Tensor, backend::Backend, cast::ToElement},

crates/birefnet-metric/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,20 @@ pub use mse::{MSEMetric, MSEMetricConfig};
9696
// Re-export lesser-used items with warning
9797
#[deprecated(note = "S-measure is not yet fully implemented and tested")]
9898
#[doc(inline)]
99-
pub use s_measure::{SMeasureInput as SMeasureInputDeprecated, SMeasureMetric, SMeasureMetricConfig, calculate_s_measure};
99+
pub use s_measure::{
100+
SMeasureInput as SMeasureInputDeprecated, SMeasureMetric, SMeasureMetricConfig,
101+
calculate_s_measure,
102+
};
100103
#[doc(inline)]
101104
pub use utils::{AllMetricsResult, calculate_all_metrics};
102105
#[doc(inline)]
103-
pub use weighted_f_measure::{WeightedFMeasureMetric, WeightedFMeasureMetricConfig, calculate_weighted_f_measure};
106+
pub use weighted_f_measure::{
107+
WeightedFMeasureMetric, WeightedFMeasureMetricConfig, calculate_weighted_f_measure,
108+
};
104109

105110
#[cfg(test)]
106111
mod tests {
107112
use burn::backend::Cpu;
108113

109114
pub type TestBackend = Cpu;
110-
}
115+
}

crates/birefnet-model/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ mod tests {
4949
pub type TestBackend = Cpu;
5050

5151
pub type TestAutodiffBackend = Autodiff<TestBackend>;
52-
}
52+
}

crates/birefnet-train/src/dataset.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,9 @@ impl<B: Backend> Batcher<B, BiRefNetItem, BiRefNetBatch<B>> for BiRefNetBatcher<
7878

7979
// Apply ImageNet normalization: add batch dimension, normalize, then remove batch dimension
8080
let image_tensor_with_batch = image_tensor.unsqueeze::<4>(); // [C, H, W] -> [1, C, H, W]
81-
let normalized_tensor =
82-
apply_imagenet_normalization(image_tensor_with_batch)
83-
.expect("Failed to apply ImageNet normalization")
84-
.squeeze::<3>(); // [1, C, H, W] -> [C, H, W]
81+
let normalized_tensor = apply_imagenet_normalization(image_tensor_with_batch)
82+
.expect("Failed to apply ImageNet normalization")
83+
.squeeze::<3>(); // [1, C, H, W] -> [C, H, W]
8584

8685
// Convert mask data to tensor [1, H, W]
8786
let mask_tensor = Tensor::<B, 2>::from_data(

crates/birefnet-train/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ mod tests {
1515
use burn::backend::Cpu;
1616

1717
pub type TestBackend = Cpu;
18-
}
18+
}

0 commit comments

Comments
 (0)