Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

task_name #40

Open
wjkbigface opened this issue Mar 25, 2024 · 3 comments
Open

task_name #40

wjkbigface opened this issue Mar 25, 2024 · 3 comments

Comments

@wjkbigface
Copy link

Hello! What does it mean to achieve task_name in print(f"Task: {task_name}: {index]} - {text_probs[0][index]}")?

@Algolzw
Copy link
Owner

Algolzw commented Mar 26, 2024

Hello! Where is this code? (I forget why but I guess I wanted to print whether the predicted degradation type is correct.)

@wjkbigface
Copy link
Author

import torch
from PIL import Image
import open_clip

checkpoint = 'pretrained/daclip_ViT-B-32.pt'
model, preprocess = open_clip.create_model_from_pretrained('daclip_ViT-B-32', pretrained=checkpoint)
tokenizer = open_clip.get_tokenizer('ViT-B-32')

image = preprocess(Image.open("haze_01.png")).unsqueeze(0)
degradations = ['motion-blurry','hazy','jpeg-compressed','low-light','noisy','raindrop','rainy','shadowed','snowy','uncompleted']
text = tokenizer(degradations)

with torch.no_grad(), torch.cuda.amp.autocast():
text_features = model.encode_text(text)
image_features, degra_features = model.encode_image(image, control=True)
degra_features /= degra_features.norm(dim=-1, keepdim=True)
text_features /= text_features.norm(dim=-1, keepdim=True)

text_probs = (100.0 * degra_features @ text_features.T).softmax(dim=-1)
index = torch.argmax(text_probs[0])

print(f"Task: {task_name}: {degradations[index]} - {text_probs[0][index]}")there

@Algolzw
Copy link
Owner

Algolzw commented Mar 27, 2024

Ok, according to the code, I think I just want to know whether the predicted degradation type is correct. The task name should be pre-defined like image dehazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants