-
Notifications
You must be signed in to change notification settings - Fork 82
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
add mscoco generative benchmark #63
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a4bfac9
add initial generative benchmark
gpucce 3a4d1b7
add pycocoeval dep
gpucce e486893
muse generate_beamsearch
gpucce 51f3e9d
update to generate
gpucce c475e1c
Merge branch 'main' into add_generative_benchmarks
rom1504 f8f1ca3
Merge branch 'main' into add_generative_benchmarks
rom1504 e858d77
clean generate
gpucce 4f29133
Merge branch 'add_generative_benchmarks' of https://github.com/gpucce…
gpucce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import json | ||
from pycocoevalcap.eval import COCOEvalCap | ||
from open_clip import tokenize | ||
from tqdm.auto import tqdm | ||
from open_clip.tokenizer import _tokenizer | ||
|
||
def evaluate(model, dataloader, batch_size, device, transform, train_dataloader=None, num_workers=None, amp=True, verbose=False): | ||
coco = dataloader.dataset.coco | ||
indexer = dataloader.dataset.ids | ||
results = [] | ||
for idx, (img, _) in enumerate(tqdm(dataloader)): | ||
n_samples = img.shape[0] # for last batch | ||
idxs = [indexer[idx * batch_size + id] for id in range(n_samples)] | ||
out = model.generate(img.to(device), seq_len=30, generation_type="beam_search",num_beams=6, num_beam_groups=3, sot_token_id=49406, eos_token_id=49407) | ||
decoded = [_tokenizer.decode(i).split("<end_of_text>")[0].replace("<start_of_text>", "").strip() for i in out.cpu().numpy()] | ||
for image_id, caption in zip(idxs, decoded): | ||
results.append({"image_id":image_id, "caption":caption}) | ||
temp_res_file = "temp_results.json" | ||
with open(temp_res_file, "w") as jf: | ||
json.dump(results, jf) | ||
|
||
coco_result = coco.loadRes(temp_res_file) | ||
coco_eval = COCOEvalCap(coco, coco_result) | ||
coco_eval.evaluate() | ||
metrics = coco_eval.eval | ||
|
||
# print output evaluation scores | ||
for metric, score in metrics.items(): | ||
print(f'{metric}: {score:.3f}') | ||
|
||
return metrics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is all this still needed @gpucce ?