pub struct QuantumVisionConfig {
pub num_qubits: usize,
pub encoding_method: ImageEncodingMethod,
pub backbone: VisionBackbone,
pub task_config: VisionTaskConfig,
pub preprocessing: PreprocessingConfig,
pub quantum_enhancement: QuantumEnhancement,
}Expand description
Quantum computer vision pipeline configuration
Fields§
§num_qubits: usizeNumber of qubits for encoding
encoding_method: ImageEncodingMethodImage encoding method
backbone: VisionBackboneVision backbone type
task_config: VisionTaskConfigTask-specific configuration
preprocessing: PreprocessingConfigPreprocessing configuration
quantum_enhancement: QuantumEnhancementQuantum enhancement level
Implementations§
Source§impl QuantumVisionConfig
impl QuantumVisionConfig
Sourcepub fn default() -> Self
pub fn default() -> Self
Create default configuration
Examples found in repository?
examples/computer_vision.rs (line 266)
262fn classification_demo() -> Result<()> {
263 println!(" Quantum image classification demo...");
264
265 // Create classification pipeline
266 let config = QuantumVisionConfig::default();
267 let mut pipeline = QuantumVisionPipeline::new(config)?;
268
269 // Create synthetic dataset
270 let num_classes = 10;
271 let num_samples = 20;
272 let (train_data, val_data) = create_classification_dataset(num_samples, num_classes)?;
273
274 println!(
275 " Dataset: {} training, {} validation samples",
276 train_data.len(),
277 val_data.len()
278 );
279
280 // Train the model (simplified)
281 println!("\n Training quantum classifier...");
282 let history = pipeline.train(
283 &train_data,
284 &val_data,
285 5, // epochs
286 OptimizationMethod::Adam,
287 )?;
288
289 // Display training results
290 println!("\n Training results:");
291 for (epoch, train_loss, val_loss) in history
292 .epochs
293 .iter()
294 .zip(history.train_losses.iter())
295 .zip(history.val_losses.iter())
296 .map(|((e, t), v)| (e, t, v))
297 {
298 println!(
299 " Epoch {}: train_loss={:.4}, val_loss={:.4}",
300 epoch + 1,
301 train_loss,
302 val_loss
303 );
304 }
305
306 // Test on new images
307 println!("\n Testing on new images...");
308 let test_images = create_test_image(5, 3, 224, 224)?;
309 let predictions = pipeline.forward(&test_images)?;
310
311 match predictions {
312 TaskOutput::Classification { probabilities, .. } => {
313 for (i, prob_row) in probabilities.outer_iter().enumerate() {
314 let (predicted_class, confidence) = prob_row
315 .iter()
316 .enumerate()
317 .max_by(|(_, a), (_, b)| a.partial_cmp(b).unwrap())
318 .map(|(idx, &prob)| (idx, prob))
319 .unwrap_or((0, 0.0));
320
321 println!(
322 " Image {}: Class {} (confidence: {:.2}%)",
323 i + 1,
324 predicted_class,
325 confidence * 100.0
326 );
327 }
328 }
329 _ => {}
330 }
331
332 // Analyze quantum advantage
333 let quantum_advantage = analyze_classification_quantum_advantage(&pipeline)?;
334 println!("\n Quantum advantage analysis:");
335 println!(
336 " - Parameter efficiency: {:.2}x classical",
337 quantum_advantage.param_efficiency
338 );
339 println!(
340 " - Feature expressiveness: {:.2}x",
341 quantum_advantage.expressiveness
342 );
343 println!(
344 " - Training speedup: {:.2}x",
345 quantum_advantage.training_speedup
346 );
347
348 Ok(())
349}Sourcepub fn object_detection(num_classes: usize) -> Self
pub fn object_detection(num_classes: usize) -> Self
Create configuration for object detection
Examples found in repository?
examples/computer_vision.rs (line 356)
352fn object_detection_demo() -> Result<()> {
353 println!(" Quantum object detection demo...");
354
355 // Create detection pipeline
356 let config = QuantumVisionConfig::object_detection(80); // 80 classes (COCO-like)
357 let mut pipeline = QuantumVisionPipeline::new(config)?;
358
359 // Test image
360 let test_images = create_test_image(2, 3, 416, 416)?;
361
362 println!(
363 " Processing {} images for object detection...",
364 test_images.dim().0
365 );
366
367 // Run detection
368 let detections = pipeline.forward(&test_images)?;
369
370 match detections {
371 TaskOutput::Detection {
372 boxes,
373 scores,
374 classes,
375 } => {
376 println!(" Detection results:");
377
378 for batch_idx in 0..boxes.dim().0 {
379 println!("\n Image {}:", batch_idx + 1);
380
381 // Filter detections by score threshold
382 let threshold = 0.5;
383 let mut num_detections = 0;
384
385 for det_idx in 0..boxes.dim().1 {
386 let score = scores[[batch_idx, det_idx]];
387
388 if score > threshold {
389 let class_id = classes[[batch_idx, det_idx]];
390 let bbox = boxes.slice(ndarray::s![batch_idx, det_idx, ..]);
391
392 println!(" - Object {}: Class {}, Score {:.3}, Box [{:.1}, {:.1}, {:.1}, {:.1}]",
393 num_detections + 1, class_id, score,
394 bbox[0], bbox[1], bbox[2], bbox[3]);
395
396 num_detections += 1;
397 }
398 }
399
400 if num_detections == 0 {
401 println!(" - No objects detected above threshold");
402 } else {
403 println!(" Total objects detected: {}", num_detections);
404 }
405 }
406 }
407 _ => {}
408 }
409
410 // Analyze detection performance
411 println!("\n Detection performance analysis:");
412 println!(" - Quantum anchor generation improves localization");
413 println!(" - Entangled features enhance multi-scale detection");
414 println!(" - Quantum NMS reduces redundant detections");
415
416 Ok(())
417}Sourcepub fn segmentation(num_classes: usize) -> Self
pub fn segmentation(num_classes: usize) -> Self
Create configuration for segmentation
Examples found in repository?
examples/computer_vision.rs (line 424)
420fn segmentation_demo() -> Result<()> {
421 println!(" Quantum semantic segmentation demo...");
422
423 // Create segmentation pipeline
424 let config = QuantumVisionConfig::segmentation(21); // 21 classes (Pascal VOC-like)
425 let mut pipeline = QuantumVisionPipeline::new(config)?;
426
427 // Test images
428 let test_images = create_test_image(1, 3, 512, 512)?;
429
430 println!(" Processing image for semantic segmentation...");
431
432 // Run segmentation
433 let segmentation = pipeline.forward(&test_images)?;
434
435 match segmentation {
436 TaskOutput::Segmentation {
437 masks,
438 class_scores,
439 } => {
440 println!(" Segmentation results:");
441 println!(" - Mask shape: {:?}", masks.dim());
442 println!(" - Class scores shape: {:?}", class_scores.dim());
443
444 // Analyze segmentation quality
445 let seg_metrics = analyze_segmentation_quality(&masks, &class_scores)?;
446 println!("\n Segmentation metrics:");
447 println!(" - Mean IoU: {:.3}", seg_metrics.mean_iou);
448 println!(
449 " - Pixel accuracy: {:.1}%",
450 seg_metrics.pixel_accuracy * 100.0
451 );
452 println!(
453 " - Boundary precision: {:.3}",
454 seg_metrics.boundary_precision
455 );
456
457 // Class distribution
458 println!("\n Predicted class distribution:");
459 let class_counts = compute_class_distribution(&masks)?;
460 for (class_id, count) in class_counts.iter().take(5) {
461 let percentage = *count as f64 / (512.0 * 512.0) * 100.0;
462 println!(" - Class {}: {:.1}% of pixels", class_id, percentage);
463 }
464 }
465 _ => {}
466 }
467
468 // Quantum advantages for segmentation
469 println!("\n Quantum segmentation advantages:");
470 println!(" - Quantum attention captures long-range dependencies");
471 println!(" - Hierarchical encoding preserves multi-scale features");
472 println!(" - Entanglement enables pixel-to-pixel correlations");
473
474 Ok(())
475}Trait Implementations§
Source§impl Clone for QuantumVisionConfig
impl Clone for QuantumVisionConfig
Source§fn clone(&self) -> QuantumVisionConfig
fn clone(&self) -> QuantumVisionConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for QuantumVisionConfig
impl RefUnwindSafe for QuantumVisionConfig
impl Send for QuantumVisionConfig
impl Sync for QuantumVisionConfig
impl Unpin for QuantumVisionConfig
impl UnwindSafe for QuantumVisionConfig
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.