Code Monkey home page Code Monkey logo

Comments (17)

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

Hi!
Thanks for reporting me all this! The memory error isn't surprising as the vgg16 is around 400MB already but models like onception are more around 100MB. I will look at the other models you mentioned this weekend and see why it didn't work out.

from heatmaps.

abdualhag avatar abdualhag commented on June 14, 2024

Looking forward to hear back from you.

from heatmaps.

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

Hi!
I just pushed a fix for the resnet. I tested it with tensorflow but it should also work with Theano. I'm going to look into the other networks. Please keep me updated if you find any issue.

from heatmaps.

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

I pushed the fix for densenet and inception. Mobilenet isn't working yet.

from heatmaps.

abdualhag avatar abdualhag commented on June 14, 2024

Hi!
Thanks you so much. I just reinstalled the package and ResNet50 worked well with Theano. This however was not the case with Tensorflow as I receive the following error:


Model type detected: local pooling - flatten
Traceback (most recent call last):
  File "demo.py", line 39, in <module>
    new_model = to_heatmap(model)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/heatmaps/heatmap/heatmap.py", line 234, in to_heatmap
    x = middle_model(img_input)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/engine/topology.py", line 617, in __call__
    output = self.call(inputs, **kwargs)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/engine/topology.py", line 2078, in call
    output_tensors, _, _ = self.run_internal_graph(inputs, masks)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/engine/topology.py", line 2229, in run_internal_graph
    output_tensors = _to_list(layer.call(computed_tensor, **kwargs))
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/layers/normalization.py", line 185, in call
    self.momentum),
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 1001, in moving_average_update
    x, value, momentum, zero_debias=True)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/training/moving_averages.py", line 70, in assign_moving_average
    update_delta = _zero_debias(variable, value, decay)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/training/moving_averages.py", line 180, in _zero_debias
    "biased", initializer=biased_initializer, trainable=False)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 1065, in get_variable
    use_resource=use_resource, custom_getter=custom_getter)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 962, in get_variable
    use_resource=use_resource, custom_getter=custom_getter)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 367, in get_variable
    validate_shape=validate_shape, use_resource=use_resource)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 352, in _true_getter
    use_resource=use_resource)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py", line 664, in _get_single_variable
    name, "".join(traceback.format_list(tb))))
ValueError: Variable bn_conv1/moving_mean/biased already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:

  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py", line 1001, in moving_average_update
    x, value, momentum, zero_debias=True)
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/layers/normalization.py", line 185, in call
    self.momentum),
  File "/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/engine/topology.py", line 617, in __call__
    output = self.call(inputs, **kwargs)

You should know that I am using tensorflow gpu. I will go a head and test the rest.
Thanks

from heatmaps.

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

Thanks for that. You can run the tests/test.py to check what is working on your end and what is not. I use tensorflow cpu for testing but I don't think it has any influence. Anyway, I don't think I can fix a bug that I can't reproduce sadly. Keep me updated. Maybe I'll understand how to fix it.

from heatmaps.

abdualhag avatar abdualhag commented on June 14, 2024

Okay. I just finished testing denenet and inception using theano backend and they both work poorly on demo.py with the dog class. See comparison below:

ResNet50
resnet50

DenseNet121

desnet121

InceptionV3
inceptionv3

This is worrying because the class is definitely being recognized as a dog. Here is the output from DenseNet

 Using Theano backend.
('Predicted:', [(u'n02113023', u'Pembroke', 0.51888126), (u'n02109961', u'Eskimo_dog', 0.18552731), (u'n02110185', u'Siberian_husky', 0.12073633)])

I will test tensorflow and let you know how it ended.

from heatmaps.

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

I just had this error, you need to change the preprocessing.

from heatmaps.

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

For example, if you want to try with inception resnet, you need to change the preprocessing like this:

import matplotlib.pyplot as plt
import numpy as np
from keras.applications.inception_resnet_v2 import preprocess_input
from keras.applications import *
from keras.preprocessing import image
from keras import backend as K

from heatmap import synset_to_dfs_ids
from heatmap import to_heatmap


def display_heatmap(new_model, img_path, ids, preprocessing=None):
    # The quality is reduced.
    # If you have more than 8GB of RAM, you can try to increase it.
    img = image.load_img(img_path, target_size=(800, 1280))
    x = image.img_to_array(img)
    x = np.expand_dims(x, axis=0)
    if preprocessing is not None:
        x = preprocess_input(x)

    out = new_model.predict(x)

    heatmap = out[0]  # Removing batch axis.

    if K.image_data_format() == 'channels_first':
        heatmap = heatmap[ids]
        if heatmap.ndim == 3:
            heatmap = np.sum(heatmap, axis=0)
    else:
        heatmap = heatmap[:, :, ids]
        if heatmap.ndim == 3:
            heatmap = np.sum(heatmap, axis=2)

    plt.imshow(heatmap, interpolation="none")
    plt.show()


model = InceptionResNetV2()
new_model = to_heatmap(model)

s = "n02084071"  # Imagenet code for "dog"
ids = synset_to_dfs_ids(s)
display_heatmap(new_model, "./dog.jpg", ids, preprocess_input)

You just have to import the preprocessing from the module from which the model comes from.

from heatmaps.

abdualhag avatar abdualhag commented on June 14, 2024

In regard to tensorflow, all except VGG16 broke down with the same error as before. My guess is that my environment in a weird state. I will test a different environment and see if things changes. Really surprise that classifying work however.

from heatmaps.

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

I just pushed the fix for mobilenets. All was tested under tensorflow cpu - python 3.6. But since keras is very good at hiding the backends, I'm pretty sure it should work for Theano and tensorflow-gpu too.

from heatmaps.

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

Indeed it's possible that there is there is a problem in your environnement. Maybe update tensorflow? It's just a wild guess.

from heatmaps.

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

can you give me the output of a pip freeze?

from heatmaps.

abdualhag avatar abdualhag commented on June 14, 2024

First thing first, I really appreciate your help. Just finished testing all models on tensorflow cpu environment and everything worked well. Also, changing the preprocessing fixed the issue of the poor heatmap. As for the tensorflow gpu environment, below is the output of pip freeze:

(tensorflowGpu) abdu@abdu-Default-string:~/anaconda2/envs/tensorflowGpu$ pip freeze
attrs==17.4.0
backports-abc==0.5
backports.functools-lru-cache==1.5
backports.ssl-match-hostname==3.5.0.1
backports.weakref==1.0rc1
bleach==1.5.0
certifi==2016.2.28
cycler==0.10.0
funcsigs==1.0.2
functools32==3.2.3.post2
h5py==2.7.1
html5lib==0.9999999
Keras==2.1.3
-e git+https://github.com/gabrieldemarmiesse/heatmaps.git@415b6cc19d8d71aaf647bb3a36b903f4f6bbda06#egg=Keras_to_heatmaps
Markdown==2.2.0
matplotlib==2.1.1
mock==2.0.0
numpy==1.14.0
pbr==3.1.1
Pillow==5.0.0
pluggy==0.6.0
protobuf==3.5.1
py==1.5.2
pycairo==1.10.0
pyparsing==2.2.0
pytest==3.4.1
python-dateutil==2.6.1
pytz==2017.3
PyYAML==3.12
scipy==1.0.0
singledispatch==3.4.0.3
six==1.11.0
subprocess32==3.2.7
tensorflow-gpu==1.2.0
tornado==4.5.3
Werkzeug==0.14.1

I will try to reinstall tensorflow gpu and let you know how did it go.

from heatmaps.

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

Tensorflow is right now at version 1.6. Yours is at 1.2. Maybe this is the issue.

from heatmaps.

abdualhag avatar abdualhag commented on June 14, 2024

That is probably why. This will take forever to fix as I need to update all dependency. I will let you know how it turned out when I fix everything. Thanks for the help.

from heatmaps.

gabrieldemarmiesse avatar gabrieldemarmiesse commented on June 14, 2024

I'm glad to help, and thanks for reporting the bugs!

from heatmaps.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.