40 lines
1.6 KiB
Rust
40 lines
1.6 KiB
Rust
// Simple validation script for TripletLoss implementation
|
|
|
|
fn main() {
|
|
println!("TripletLoss implementation validation");
|
|
|
|
// Test that we can create the basic types
|
|
use rtx_losses::{TripletLoss, MinimalTensor, MinimalDevice, DistanceMetric};
|
|
|
|
let device = MinimalDevice::cpu();
|
|
let loss = TripletLoss::new()
|
|
.with_margin(1.0)
|
|
.with_distance_metric(DistanceMetric::Euclidean);
|
|
|
|
println!("✓ Created TripletLoss with margin: {}", loss.margin());
|
|
println!("✓ Distance metric: {:?}", loss.distance_metric());
|
|
|
|
// Test basic tensor creation
|
|
match MinimalTensor::from_data(vec![0.0, 1.0], &[1, 2], &device) {
|
|
Ok(tensor) => println!("✓ Created tensor with shape: {:?}", tensor.shape()),
|
|
Err(e) => println!("✗ Failed to create tensor: {}", e),
|
|
}
|
|
|
|
// Test basic forward pass
|
|
let anchor = MinimalTensor::from_data(vec![0.0, 0.0], &[1, 2], &device).unwrap();
|
|
let positive = MinimalTensor::from_data(vec![1.0, 0.0], &[1, 2], &device).unwrap();
|
|
let negative = MinimalTensor::from_data(vec![3.0, 0.0], &[1, 2], &device).unwrap();
|
|
|
|
match loss.forward_triplets(&anchor, &positive, &negative) {
|
|
Ok(result) => {
|
|
let loss_value = result.item().unwrap();
|
|
println!("✓ Forward pass successful, loss: {}", loss_value);
|
|
if loss_value >= 0.0 && loss_value.is_finite() {
|
|
println!("✓ Loss value is valid (non-negative and finite)");
|
|
}
|
|
},
|
|
Err(e) => println!("✗ Forward pass failed: {}", e),
|
|
}
|
|
|
|
println!("TripletLoss validation complete!");
|
|
} |