clcarwin / sphereface_pytorch

A PyTorch Implementation of SphereFace.
MIT License
715 stars 172 forks source link

Unnecessarily loading file contents of `pairs.txt` into memory `lfw_eval.py` #63

Open sayandipdutta opened 2 years ago

sayandipdutta commented 2 years ago

In lfw_eval.py, the contents of pairs.txt is being loaded into memory, even though it is not used for anything other than iterating over the lines. It will be easier and more memory efficient to iterate over the file object itself.

with open('data/pairs.txt') as f:
    pairs_lines = f.readlines()[1:]

Which will also avoid the __getitem__ call in line 91, making the code more efficient.

for i in range(6000):
    p = pairs_lines[i].replace('\n','').split('\t')