kaggle_imet/data.py
def binary_mapping(
        encoding: Tensor,
        lut_label: Dict[int, str],
        thr: float = 0.5,
        label_required: bool = True,
    ) -> Union[str, List[str]]:
        """Convert Model outputs to string labels

        Args:
            encoding: one-hot encoding
            lut_label: look-up-table with labels
            thr: threshold for label binarization
            label_required: if it is required to return any label and no label is above `thr`, use argmax
        """
        assert lut_label
        # on case it is not one hot encoding but single label
        if encoding.nelement() == 1:
            return lut_label[encoding[0]]
        labels = [lut_label[i] for i, s in enumerate(encoding) if s >= thr]
        # in case no reached threshold then take max
        if not labels and label_required:
            idx = torch.argmax(encoding).item()
            labels = [lut_label[idx]]
        return sorted(labels)
Convert Model outputs to string labels

        Args:
            encoding: one-hot encoding
            lut_label: look-up-table with labels
            thr: threshold for label binarization
            label_required: if it is required to return any label and no label is above `thr`, use argmax
        
Convert Model outputs to string labels
Convert Model outputs to string labels
def binary_mapping(
        encoding: Tensor,
        lut_label: Dict[int, str],
        thr: float = 0.5,
        label_required: bool = True,
    ) -> Union[str, List[str]]:
        assert lut_label
        if encoding.nelement() == 1:
            return lut_label[encoding[0]]
        labels = [lut_label[i] for i, s in enumerate(encoding) if s >= thr]
        if not labels and label_required:
            idx = torch.argmax(encoding).item()
            labels = [lut_label[idx]]
        return sorted(labels)
def binary_mapping ( encoding : Tensor , lut_label : Dict [ int , str ] , thr : float = 0.5 , label_required : bool = True , ) -> Union [ str , List [ str ] ] : assert lut_label if encoding . nelement ( ) == 1 : return lut_label [ encoding [ 0 ] ] labels = [ lut_label [ i ] for i , s in enumerate ( encoding ) if s >= thr ] if not labels and label_required : idx = torch . argmax ( encoding ) . item ( ) labels = [ lut_label [ idx ] ] return sorted ( labels )
Convert Model outputs to string labels
Convert Model outputs to string labels
"""Convert Model outputs to string labels

        Args:
            encoding: one-hot encoding
            lut_label: look-up-table with labels
            thr: threshold for label binarization
            label_required: if it is required to return any label and no label is above `thr`, use argmax
        """ # on case it is not one hot encoding but single label # in case no reached threshold then take max
encoding
Tensor
None
lut_label
Dict[int, str]
look-up-table with labels
look - up - table with labels
thr
float
threshold for label binarization
threshold for label binarization
label_required
bool
if it is required to return any label and no label is above `thr`, use argmax
if it is required to return any label and no label is above ` thr ` use argmax