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

local variable 'arr' referenced before assignment due to list of lists #206

Open
sgbaird opened this issue Oct 8, 2022 · 0 comments
Open
Labels
bug Something isn't working

Comments

@sgbaird
Copy link
Member

sgbaird commented Oct 8, 2022

The PIL images from imagen-pytorch were returning this error during xc.png2xtal(images). Not sure if this is something wrong on my side or the imagen-pytorch side.

[[<PIL.Image.Image image mode=L size=64x64 at 0x7F417391E9D0>],
 [<PIL.Image.Image image mode=L size=64x64 at 0x7F42CBAF9F90>],
 [<PIL.Image.Image image mode=L size=64x64 at 0x7F42C4FD9050>],
 [<PIL.Image.Image image mode=L size=64x64 at 0x7F42C4FD9210>],
 [<PIL.Image.Image image mode=L size=64x64 at 0x7F42CBBBDF10>],
 [<PIL.Image.Image image mode=L size=64x64 at 0x7F42CBBBDC90>],
 [<PIL.Image.Image image mode=L size=64x64 at 0x7F42CBBBDED0>],
 [<PIL.Image.Image image mode=L size=64x64 at 0x7F42CBBBDE90>],
 [<PIL.Image.Image image mode=L size=64x64 at 0x7F42C515D590>],
 [<PIL.Image.Image image mode=L size=64x64 at 0x7F417391E410>]]
---------------------------------------------------------------------------
UnboundLocalError                         Traceback (most recent call last)
[<ipython-input-29-5af3e9711054>](https://localhost:8080/#) in <module>
----> 1 gen_structures = xc.png2xtal(gen_images)
      2 mptm.evaluate_and_record(fold, gen_structures)
      3 print(mptm.recorded_metrics)

[/usr/local/lib/python3.7/dist-packages/xtal2png/core.py](https://localhost:8080/#) in png2xtal(self, images, save)
    569             if mode == "RGB":
    570                 arr = arr.transpose(2, 0, 1)
--> 571             data_tmp.append(arr)
    572 
    573         data = np.stack(data_tmp, axis=0)

UnboundLocalError: local variable 'arr' referenced before assignment

The issue was that I had a list of lists instead of just a list of PIL objects. Not a very helpful error, but maybe a type hint would have revealed this issue. Not sure if I have the right type hint for that.

@sgbaird sgbaird added the bug Something isn't working label Oct 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant