INNER CODE UNIT · Python

__init__

patrickjohncyh/fashion-clip · fashion_clip/fashion_clip.py:105

    def __init__(self, model_name, dataset: FCLIPDataset = None, normalize=True, approx=True, auth_token=None):
        self.device = "cuda" if torch.cuda.is_available() else "mps" if torch.mps.is_available() else "cpu"
        self.model_name = model_name
        self.model, self.preprocess, self.model_hash = self._load_model(model_name, auth_token=auth_token)
        self.model = self.model.to(self.device)
        self.dataset = dataset
        if self.dataset:
            self.dataset_hash = self.dataset.hash()
            self.vector_hash = "_".join([self.model_hash, self.dataset_hash])
        # print(self.vector_hash)
        self.approx = approx
        if dataset is not None:
            self.image_vectors, self.textual_vectors = self._generate_vectors()
            assert self.image_vectors.shape == self.textual_vectors.shape

        if normalize and dataset:
            print('Normalizing Input Vectors...', end='')
            self.image_vectors = self.image_vectors / np.linalg.norm(self.image_vectors, ord=2, axis=-1, keepdims=True)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…