question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Replace copied createIndex/loadRes/evaluate in references/*/coco_eval.py by calls to original functions + contextlib.redirect_stdout to suppress prints

See original GitHub issue

🚀 The feature

Motivation for the copies is only removing prints. In Python 3 this can easily be achieved by using https://docs.python.org/3/library/contextlib.html?highlight=context#contextlib.redirect_stdout around calls to evaluate/loadRes

Motivation, pitch

Less code to maintain, less code for users to copy-paste/read/understand (since currently references code is invited to be simple scaffolding for users to copy and modify)

Alternatives

No response

Additional context

Also, import torch._six could be eliminated

cc @datumbox

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vadimkantorovcommented, Sep 11, 2021

So I think: https://github.com/facebookresearch/detr/blob/eb9f7e03ed8e2ed2cd55528989fe7df890bc3fc0/datasets/coco_eval.py#L51 : img_ids, eval_imgs = evaluate(coco_eval) could be replaced by coco_eval.evaluate(); eval_imgs = np.asarray(coco_eval.evalImgs).reshape(-1, len(coco_eval.params.areaRng), len(coco_eval.params.imgIds))

And then custom evaluate() could go.

Does it make sense @fmassa?

0reactions
vadimkantorovcommented, Sep 22, 2021

Maybe also simplify synchronize_between_processes, create_common_coco_eval and merge into a single

    def synchronize_between_processes(self):
        for iou_type, coco_eval in self.coco_eval.items():
            self.eval_imgs[iou_type] = np.concatenate(self.eval_imgs[iou_type], 2)

            all_img_ids = utils.all_gather(self.img_ids)
            all_eval_imgs = utils.all_gather(self.eval_imgs[iou_type])

            merged_img_ids = np.array([s for p in all_img_ids for s in p])
            merged_img_ids, idx = np.unique(merged_img_ids, return_index=True)
            merged_eval_imgs = np.concatenate(all_eval_imgs, 2)
            merged_eval_imgs = merged_eval_imgs[..., idx]

            coco_eval.evalImgs = list(merged_eval_imgs.flatten())
            coco_eval.params.imgIds = list(merged_img_ids)
            coco_eval._paramsEval = copy.deepcopy(coco_eval.params)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirecting stdout to "nothing" in python - Stack Overflow
I have a large project consisting of sufficiently large number of modules, each printing something to the standard output. Now ...
Read more >
Redirecting all kinds of stdout in Python
A common task in Python (especially while testing or debugging) is to redirect sys.stdout to a stream or a file while executing some...
Read more >
Suppress Print Output in Python | coding(dose)
Sometimes you don't want output at all to your screen, there are times when I'm writing a function that prints something to the...
Read more >
Python 101: Redirecting stdout
The easiest way to redirect stdout in Python is to just assign it an open file object. Let's take a look at a...
Read more >
Redirecting the Output of an Already Running Process
So, in this article, we'll learn different ways to redirect or copy the output of a running process. This can be useful, for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found