jrosebr1 / bat-country

A lightweight, extendible, easy to use Python package for deep dreaming and image generation with Caffe and CNNs.
MIT License
246 stars 62 forks source link

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

Closed kphretiq closed 8 years ago

kphretiq commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

jrosebr1 commented 8 years ago

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