prototypical
euclidean_dist(query, prototypes, sen=True, eps_pos=1.0, eps_neg=-1e-07, eps=1e-07)
¶
Compute euclidean distance between two tensors. SEN dissimilarity from https://www.ecva.net/papers/eccv_2020/papers_ECCV/papers/123680120.pdf Args: query: feature of the network prototypes: prototypes of the center sen: Sen dissimilarity flag eps_pos: similarity arg eps_neg: similarity arg eps: similarity arg.
Returns:
-
Tensor
–Euclidian loss
Source code in quadra/losses/classification/prototypical.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
|
prototypical_loss(coords, target, n_support, prototypes=None, sen=True, eps_pos=1.0, eps_neg=-1e-07)
¶
Prototypical loss implementation.
Inspired by https://github.com/jakesnell/prototypical-networks/blob/master/protonets/models/few_shot.py Compute the barycentres by averaging the features of n_support samples for each class in target, computes then the distances from each samples' features to each one of the barycentres, computes the log_probability for each n_query samples for each one of the current classes, of appartaining to a class c, loss and accuracy are then computed and returned.
Parameters:
-
coords
(
Tensor
) –The model output for a batch of samples
-
target
(
Tensor
) –Ground truth for the above batch of samples
-
n_support
(
int
) –Number of samples to keep in account when computing barycentres, for each one of the current classes
-
prototypes
(
Tensor | None
, default:None
) –if not None, is used for classification
-
sen
(
bool
, default:True
) –Sen dissimilarity flag
-
eps_pos
(
float
, default:1.0
) –Sen positive similarity arg
-
eps_neg
(
float
, default:-1e-07
) –Sen negative similarity arg
Source code in quadra/losses/classification/prototypical.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|