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

12.1 Activation Optimization --imresize and pilatus800.jpg issues and solutions #74

Open
mikechen66 opened this issue May 8, 2020 · 1 comment

Comments

@mikechen66
Copy link

mikechen66 commented May 8, 2020

I found out the two issues that stopped the example application running. I have corrected them as follows.

1. imresize issue:

Issue:
ImportError: cannot import name 'imresize' from 'scipy.misc'

Solution:

First install scikit-image
$ pip install scikit-image
or
$ conda install -c conda-forge scikit-image

And then change
from scipy.misc import imresize
to
from skimage.transform import resize

Please have a look at the skimage example at the official website ad follows.

skimage: https://scikit-image.org/docs/stable/auto_examples/transform/plot_rescale.html

2. pilatus800.jpg issue

Issue:
No directory of data/pilatus800.jpg

Solution:

Need to download pilatus800.jpg at the resource as follows.
pilatus800.jpg: //github.com/Spidy20/Data-scince-ML-project/tree/master/Deep%20dream

And then save pilatus800.jpg in the directory of /dl-cookbook/data/.

At last change data/pilatus800.jpg to /home/user/Documents/dl-cookbook/data/pilatus800.jpg in the page of 12.1 Activation Optimization by jupyter notebook.

@mikechen66 mikechen66 changed the title 12.1 Activation Optimization --imresize and pilatus800.jpgs issues and solutions 12.1 Activation Optimization --imresize and pilatus800.jpg issues and solutions May 8, 2020
@mikechen66
Copy link
Author

mikechen66 commented May 8, 2020

With regard to the RuntimeError, the small modification will make the example script run correctly.

RuntimeError: Variable += value not supported. Use variable.assign_add(value) to modify the variable value and variable = variable + value to get a new Tensor object.

1. Issue


RuntimeError Traceback (most recent call last)
in
14 loss += coeff * K.sum(K.square(x[:, :, 2: -2, 2: -2])) / scaling
15 else:
---> 16 loss += coeff * K.sum(K.square(x[:, 2: -2, 2: -2, :])) / scaling
17
18 grads = K.gradients(loss, input_img)[0]

~/miniconda3/lib/python3.7/site-packages/tensorflow_core/python/ops/resource_variable_ops.py in iadd(self, unused_other)
1220
1221 def iadd(self, unused_other):
-> 1222 raise RuntimeError("Variable += value not supported. Use "
1223 "variable.assign_add(value) to modify the variable "
1224 "value and variable = variable + value to get a new "

RuntimeError: Variable += value not supported. Use variable.assign_add(value) to modify the variable value and variable = variable + value to get a new Tensor object.

2. Solution

Change the original scripts

    if K.image_data_format() == 'channels_first':
        loss += coeff * K.sum(K.square(x[:, :, 2: -2, 2: -2])) / scaling
    else:
        loss += coeff * K.sum(K.square(x[:, 2: -2, 2: -2, :])) / scaling

to the following scripts.

    if K.image_data_format() == 'channels_first':
        loss = loss + coeff * K.sum(K.square(x[:, :, 2: -2, 2: -2])) / scaling
    else:
        loss = loss + coeff * K.sum(K.square(x[:, 2: -2, 2: -2, :])) / scaling

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

1 participant