Tag Archives: VSLAM

[Solved] TUM associate.py Scripte Error: AttributeError: ‘dict_keys‘ object has no attribute ‘remove‘

Running the script file reports an error


Cause of error.
Version difference between python2 and python3
In Python 3, dict.keys() returns the dict_keys object without the remove method. Unlike Python 2, Python 2 dict.keys() returns the list object.
In Python 3, dict.keys() returns a dict_ keys object (a view of the dictionary) which does not have remove method; unlike Python 2, where dict.keys() returns a list object.

 

Solution:
(1) Directly run with Python 2 forcely:

python2 associate.py rgb.txt depth.txt > associate.txt

(2) Still run it in python 3. Make a small change to the original source code

	for diff, a, b in potential_matches:
        if a in first_keys and b in second_keys:
            first_keys.remove(a)
            second_keys.remove(b)
            matches.append((a, b))
    
    matches.sort()
    return matches

Add two sentences above to change dict into list

	# two new lines
	first_keys = list(first_keys)
    second_keys = list(second_keys)
    for diff, a, b in potential_matches:
        if a in first_keys and b in second_keys:
            first_keys.remove(a)
            second_keys.remove(b)
            matches.append((a, b))
    
    matches.sort()
    return matches

Run again (Python here points to python3 by default)

python associate.py rgb.txt depth.txt > associate.txt