Skip to content

Conversation

Joris-Kuehl-TU-Berlin
Copy link

Motivation

The method init_model in mmseg/apis/inference.py has an unsafe dictionary access in line 61. The key 'meta' is accessed directly, even though the following lines always use checkpoint.get('meta') to ensure it even exists and have functional handling for the case that it doesn't (in the else case). As a result, the program will throw a KeyError before ever reaching the already implemented handling of this very case. This bug is the reason for #3558.

Modification

Simply moving the dictionary access AFTER the check that the key exists will suffice. This will allow init_model to reach the else case when checkpoint['meta'] does not exist.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Aug 5, 2024

CLA assistant check
All committers have signed the CLA.

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