
     iD                        d dl mZ d dlmZmZmZmZ d dlZd dl	m
Z
 d dlmZ d dlmZ d dlmZ dd	lmZ  G d
 dee      Zy)    )annotations)DictOptionalSequenceUnionN)Protocol)BaseWaveformTransform)Metric)Task   ))SupervisedRepresentationLearningTaskMixinc                  j     e Zd ZdZ	 	 	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZd Z xZS )+SupervisedRepresentationLearningWithArcFacea  Supervised representation learning with ArcFace loss

    Representation learning is the task of ...

    Parameters
    ----------
    protocol : Protocol
        pyannote.database protocol
    duration : float, optional
        Chunks duration in seconds. Defaults to two seconds (2.).
    min_duration : float, optional
        Sample training chunks duration uniformely between `min_duration`
        and `duration`. Defaults to `duration` (i.e. fixed length chunks).
    num_classes_per_batch : int, optional
        Number of classes per batch. Defaults to 32.
    num_chunks_per_class : int, optional
        Number of chunks per class. Defaults to 1.
    margin : float, optional
        Margin. Defaults to 28.6.
    scale : float, optional
        Scale. Defaults to 64.
    num_workers : int, optional
        Number of workers used for generating training samples.
        Defaults to multiprocessing.cpu_count() // 2.
    pin_memory : bool, optional
        If True, data loaders will copy tensors into CUDA pinned
        memory before returning them. See pytorch documentation
        for more details. Defaults to False.
    augmentation : BaseWaveformTransform, optional
        torch_audiomentations waveform transform, used by dataloader
        during training.
    metric : optional
        Validation metric(s). Can be anything supported by torchmetrics.MetricCollection.
        Defaults to AUROC (area under the ROC curve).
    c           
         || _         || _        || _        || _        t        |   |||| j                  ||	|
|       y )N)durationmin_duration
batch_sizenum_workers
pin_memoryaugmentationmetric)num_chunks_per_classnum_classes_per_batchmarginscalesuper__init__r   )selfprotocolr   r   r   r   r   r   r   r   r   r   	__class__s               {/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/pyannote/audio/tasks/embedding/arcface.pyr   z4SupervisedRepresentationLearningWithArcFace.__init__R   sQ     %9!%:"
%#!% 	 		
    c                .   | j                  | j                   j                        j                  \  }}t        j                  j                  t        | j                  j                        || j                  | j                        | j                   _        y )N)r   r   )modelexample_input_arrayshapepytorch_metric_learninglossesArcFaceLosslenspecificationsclassesr   r   	loss_func)r   _embedding_sizes      r!   setup_loss_funcz;SupervisedRepresentationLearningWithArcFace.setup_loss_funcr   sm     JJtzz'E'EFLL>6==II##++,;;**	  J  


r"   )
Ng       @    r   g<@g      P@NFNN)r   r   r   zOptional[float]r   floatr   intr   r3   r   r2   r   r2   r   zOptional[int]r   boolr   zOptional[BaseWaveformTransform]r   z2Union[Metric, Sequence[Metric], Dict[str, Metric]])__name__
__module____qualname____doc__r   r0   __classcell__)r    s   @r!   r   r   &   s    "V )-%'$%%) 8<EI

 &
 	

  #
 "
 
 
 #
 
 6
 C
@	
r"   r   )
__future__r   typingr   r   r   r   pytorch_metric_learning.lossesr'   pyannote.databaser   /torch_audiomentations.core.transforms_interfacer	   torchmetricsr
   pyannote.audio.core.taskr   mixinsr   r    r"   r!   <module>rC      s4   0 # 2 2 % & Q  ) =U
-U
r"   