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

UnboundLocalError: local variable 'nH' referenced before assignment #6

Closed
kphretiq opened this issue Aug 1, 2016 · 3 comments
Closed

Comments

@kphretiq
Copy link

kphretiq commented Aug 1, 2016

Having a spot of trouble with prepare_guide, as described in your example code.

Traceback (most recent call last):
  File "./guided-test.py", line 30, in <module>
    features = bc.prepare_guide(Image.open(guide_image), end=layer)
  File "/usr/local/lib/python2.7/dist-packages/batcountry/batcountry.py", line 185, in prepare_guide
    src.reshape(1, 3, nH, nW)
UnboundLocalError: local variable 'nH' referenced before assignment

Here are the pertinent bits of my script.

bc = BatCountry("/home/username/caffe/models/bvlc_googlenet")

input_image = "/home/username/images/monkey.jpg"
output_image = "/home/username/test-guided.jpg"
guide_image = "/home/username/guides/starry-guide.jpg"

layer = "inception_4c/output"

features = bc.prepare_guide(Image.open(guide_image), end=layer)
image = bc.dream(np.float32(
    Image.open(input_image)),
    end=layer,
    iter_n=20,
    objective_fn=BatCountry.guided_objective,
    objective_features=features,
    )

result = Image.fromarray(np.uint8(image))
result.save(output_image)
input_image = output_image

Thanks!

@kphretiq
Copy link
Author

kphretiq commented Aug 1, 2016

I think I see the problem. I installed from pip, and apparently your resize changes have not been pushed.

# whoops! not declared in version on pypi!
src.reshape(1, 3, nH, nW)

@kphretiq
Copy link
Author

kphretiq commented Aug 1, 2016

pip install git+https://github.com/jrosebr1/bat-country.git did the trick.

@kphretiq kphretiq closed this as completed Aug 5, 2016
@jrosebr1
Copy link
Owner

jrosebr1 commented Aug 5, 2016

Thanks for bringing this to my attention @kphretiq. I'll need to create a newly updated version and push it to PyPI.

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

No branches or pull requests

2 participants