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

fix typo in datasets/custom.py #1079

Closed
wants to merge 1 commit into from
Closed

fix typo in datasets/custom.py #1079

wants to merge 1 commit into from

Conversation

YimianDai
Copy link

Motivation

fix typo in datasets/custom.py.

Modification

Change the docs about results from list[tuple[torch.Tensor] to list[list[torch.Tensor]

The reason why it is list[list[torch.Tensor], not list[tuple[torch.Tensor] is listed as follows in parts of Chinese:

看一下脱水的 single_gpu_test 代码:

results = []
for batch_indices, data in zip(loader_indices, data_loader):
    with torch.no_grad():
        result = model(return_loss=False, **data)
    result = dataset.pre_eval(result, indices=batch_indices)
    results.extend(result)

也就是说 dataset.pre_eval 返回的 resulttuple[torch.Tensor]. 不过我们先来看下 model 返回的结果.

对于 mmseg 来说, model 就是 EncoderDecoder 了, 在 validation 的时候, model(・) 其实就是 EncoderDecoder.forward_test(・).

flowchart TD
%%{init: {'theme': 'base', 'themeVariables': { 'fontSize': '13px', 'fontFamily': 'Monaco'}}}%%

single_gpu_test --> EncoderDecoder.forward --> EncoderDecoder.forward_test --> EncoderDecoder.simple_test --> EncoderDecoder.inference --> EncoderDecoder.whole_inference --> EncoderDecoder.encode_decode --> EncoderDecoder._decode_head_forward_test

虽然如上图所示, forward_test 的调用链条很长, 但其实返回的 result 就是 simple_test 的返回结果. 而 simple_test 的代码如下

def simple_test(self, img, img_meta, rescale=True):
    seg_logit = self.inference(img, img_meta, rescale)
    seg_pred = seg_logit.argmax(dim=1)
    seg_pred = seg_pred.cpu().numpy()
    # unravel batch dim
    seg_pred = list(seg_pred)
    return seg_pred
  • seg_logit(N, C, H, W) 的 Tensor
  • seg_logit.argmax(dim=1) 得到的 seg_pred(N, H, W) 的 Tensor;
  • 经过 seg_pred = list(seg_pred) 得到的 seg_predlist[np.ndarray].

因此, model(・) 也就是 EncoderDecoder.forward_test(・) 返回的 resultlist[np.ndarray]. 接下来要看一下 dataset.pre_eval 的代码.

  • pre_eval 这个函数的功能本身就是 Collect eval result from each iteration. 从下面的代码可以看到, 返回的 pre_eval_results 还是一个 list[torch.Tensor].
  • 注意, intersect_and_union 这个函数会将 np.ndarray 的输入变为 torch.Tensor 再计算, 所以返回的结果是 torch.Tensor, 因此, 返回的 pre_eval_results 就是 list[torch.Tensor].
def pre_eval(self, preds, indices):
    pre_eval_results = []

    for pred, index in zip(preds, indices):
        seg_map = self.get_gt_seg_map_by_idx(index)
        pre_eval_results.append(
            intersect_and_union(pred, seg_map, len(self.CLASSES),
                                self.ignore_index, self.label_map,
                                self.reduce_zero_label))

    return pre_eval_results

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repos?

No. It is only a modification to the comments.

@CLAassistant
Copy link

CLAassistant commented Nov 26, 2021

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Nov 26, 2021

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.50%. Comparing base (f0426c9) to head (16a8c8e).
Report is 293 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1079   +/-   ##
=======================================
  Coverage   89.50%   89.50%           
=======================================
  Files         120      120           
  Lines        6670     6670           
  Branches     1040     1040           
=======================================
  Hits         5970     5970           
  Misses        496      496           
  Partials      204      204           
Flag Coverage Δ
unittests 89.50% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@YimianDai YimianDai closed this Nov 26, 2021
@YimianDai
Copy link
Author

I withdraw it. The original doc is right.

aravind-h-v pushed a commit to aravind-h-v/mmsegmentation that referenced this pull request Mar 27, 2023
* [GitBot] Automatically close issues after inactivitiy

* improve

* Add unstale

* typo

Co-authored-by: anton-l <anton@huggingface.co>
wjkim81 pushed a commit to wjkim81/mmsegmentation that referenced this pull request Dec 3, 2023
* update fap (open-mmlab#1070)

* fix a bug in post_dark_udp

* fix a bug in post_dark_udp

* Modified a bad comment

* add unit test for udp

* add unit test for udp

* use numpy instead math for math ops

* fix lint

Co-authored-by: Jas <jinsheng@sensetime.com>
Co-authored-by: quyang <quyang@qiyi.com>
Co-authored-by: ly015 <liyining0712@gmail.com>
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

Successfully merging this pull request may close these issues.

2 participants