(gallery, num)
return gallery[rand_inds]
Random select some elements from the gallery.

        It seems that Pytorch's implementation is slower than numpy so we use
        numpy to randperm the indices.
Random select some elements from the gallery.
Random select some elements from the gallery .
def random_choice(gallery, num):
        """Random select some elements from the gallery.

        It seems that Pytorch's implementation is slower than numpy so we use
        numpy to randperm the indices.
        """
        assert len(gallery) >= num
        if isinstance(gallery, list):
            gallery = np.array(gallery)
        cands = np.arange(len(gallery))
        np.random.shuffle(cands)
        rand_inds = cands[:num]
        if not isinstance(gallery, np.ndarray):
            rand_inds = torch.from_numpy(rand_inds).long().to(gallery.device)
        return gallery[rand_inds]
def random_choice ( gallery , num ) : assert len ( gallery ) >= num if isinstance ( gallery , list ) : gallery = np . array ( gallery ) cands = np . arange ( len ( gallery ) ) np . random . shuffle ( cands ) rand_inds = cands [ : num ] if not isinstance ( gallery , np . ndarray ) : rand_inds = torch . from_numpy ( rand_inds ) . long ( ) . to ( gallery . device ) return gallery [ rand_inds ]