Skip to content

Commit

Permalink
removed legacy code
Browse files Browse the repository at this point in the history
  • Loading branch information
timojl authored Oct 24, 2022
1 parent 41d9ba2 commit ac8f4d0
Showing 1 changed file with 0 additions and 26 deletions.
26 changes: 0 additions & 26 deletions models/clipseg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,6 @@
from torch.nn.modules.activation import ReLU


def precompute_clip_vectors():

from trails.initialization import init_dataset
lvis = init_dataset('LVIS_OneShot3', split='train', mask='text_label', image_size=224, aug=1, normalize=True,
reduce_factor=None, add_bar=False, negative_prob=0.5)

all_names = list(lvis.category_names.values())

import clip
from models.clip_prompts import imagenet_templates
clip_model = clip.load("ViT-B/32", device='cuda', jit=False)[0]
prompt_vectors = {}
for name in all_names[:100]:
with torch.no_grad():
conditionals = [t.format(name).replace('_', ' ') for t in imagenet_templates]
text_tokens = clip.tokenize(conditionals).cuda()
cond = clip_model.encode_text(text_tokens).cpu()

for cond, vec in zip(conditionals, cond):
prompt_vectors[cond] = vec.cpu()

import pickle

pickle.dump(prompt_vectors, open('precomputed_prompt_vectors.pickle', 'wb'))


def get_prompt_list(prompt):
if prompt == 'plain':
return ['{}']
Expand Down

0 comments on commit ac8f4d0

Please sign in to comment.