CLIP Training Code
Not really an issue, I just want to share my training code since some people still have some difficulties to write the training code. Just modify the code to suit your usage. Feel free to ask or point out any mistakes in my code. ```python # Latest Update : 18 July 2022, 09:55 GMT+7 # TO ADD : # Gradient Checkpointing # Filter out bias from weight decay # Decaying learning rate with cosine schedule # Half-precision Adam statistics # Half-precision stochastically rounded text encoder weights were used #BATCH_SIZE must larger than 1 device = "cuda:0" if torch.cuda.is_available() else "cpu" # If using GPU then use mixed precision training. model, preprocess = clip.load("ViT-B/32",device=device,jit=False) #Must set jit=False for training class image_title_dataset(Dataset): def __init__(self, list_image_path,list_txt): self.image_path = list_image_path self.title = clip.tokenize(list_txt) #you can tokenize everything at once in here(slow at the beginning), or tokenize it in the training loop. def __len__(self): return len(self.title) def __getitem__(self, idx): image = preprocess(Image.open(self.image_path[idx])) # Image from PIL module title = self.title[idx] return image,title # use your own data list_image_path = ['folder/image1.jpg','folder2/image2.jpg'] list_txt = ['description for image1.jpg' , 'description for image2.jpg'] dataset = image_title_dataset(list_image_path,list_txt) train_dataloader = DataLo
Posted by vinson2233 on Apr 8, 2021, 6:30 AM
Tags
Related issues
Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments
github (EdTech)
Message limit 10000 team edition
[NEW] Data Tiering - Valkey as general data store not just in-memory data store
Info: No releases on google play for now
proposal: spec: sum types based on general interfaces
Users can't use IdPs outside of the ones enumerated by RPs
CLIP Training Code
CLIP Training Code
Not really an issue, I just want to share my training code since some people still have some difficulties to write the training code. Just modify the code to suit your usage. Feel free to ask or point out any mistakes in my code. ```python # Latest Update : 18 July 2022, 09:55 GMT+7 # TO ADD : # Gradient Checkpointing # Filter out bias from weight decay # Decaying learning rate with cosine schedule # Half-precision Adam statistics # Half-precision stochastically rounded text encoder weights were used #BATCH_SIZE must larger than 1 device = "cuda:0" if torch.cuda.is_available() else "cpu" # If using GPU then use mixed precision training. model, preprocess = clip.load("ViT-B/32",device=device,jit=False) #Must set jit=False for training class image_title_dataset(Dataset): def __init__(self, list_image_path,list_txt): self.image_path = list_image_path self.title = clip.tokenize(list_txt) #you can tokenize everything at once in here(slow at the beginning), or tokenize it in the training loop. def __len__(self): return len(self.title) def __getitem__(self, idx): image = preprocess(Image.open(self.image_path[idx])) # Image from PIL module title = self.title[idx] return image,title # use your own data list_image_path = ['folder/image1.jpg','folder2/image2.jpg'] list_txt = ['description for image1.jpg' , 'description for image2.jpg'] dataset = image_title_dataset(list_image_path,list_txt) train_dataloader = DataLo
Comments (0)
No comments yet. Start the discussion.