{"action":"created","issue":{"url":"https://api.github.com/repos/gabrieldemarmiesse/heatmaps/issues/7","repository_url":"https://api.github.com/repos/gabrieldemarmiesse/heatmaps","labels_url":"https://api.github.com/repos/gabrieldemarmiesse/heatmaps/issues/7/labels{/name}","comments_url":"https://api.github.com/repos/gabrieldemarmiesse/heatmaps/issues/7/comments","events_url":"https://api.github.com/repos/gabrieldemarmiesse/heatmaps/issues/7/events","html_url":"https://github.com/gabrieldemarmiesse/heatmaps/issues/7","id":301538811,"number":7,"title":"MemoryError on Raspberry Pi","user":{"login":"abdualhag","id":25646205,"avatar_url":"https://avatars0.githubusercontent.com/u/25646205?v=4","gravatar_id":"","url":"https://api.github.com/users/abdualhag","html_url":"https://github.com/abdualhag","followers_url":"https://api.github.com/users/abdualhag/followers","following_url":"https://api.github.com/users/abdualhag/following{/other_user}","gists_url":"https://api.github.com/users/abdualhag/gists{/gist_id}","starred_url":"https://api.github.com/users/abdualhag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abdualhag/subscriptions","organizations_url":"https://api.github.com/users/abdualhag/orgs","repos_url":"https://api.github.com/users/abdualhag/repos","events_url":"https://api.github.com/users/abdualhag/events{/privacy}","received_events_url":"https://api.github.com/users/abdualhag/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-03-01T19:58:13Z","updated_at":"2018-03-03T18:51:16Z","closed_at":null,"author_association":"NONE","body":"Hi, so I was playing around with raspberry pi and tried using Keras to see how it handle which by the was not so well but it worked. When I tried to run the heatmap demo however, I always get a memory error even after reducing the size of the output image which is probably not what causes the crash to start with. I looked it up on-line and the solution seem to related to batch size, something which you would be able to refer me to where in the package I might find. The error I receive is found bellow, the same error appears with python2:\r\n\r\n```\r\npi@raspberrypi:~/heatmaps/examples $ python3 demo.py \r\n/usr/lib/python3/dist-packages/h5py/__init__.py:34: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\r\n  from ._conv import register_converters as _register_converters\r\nUsing Theano backend.\r\nTraceback (most recent call last):\r\n  File \"demo.py\", line 38, in <module>\r\n    model = VGG16()\r\n  File \"/home/pi/.local/lib/python3.5/site-packages/keras/applications/vgg16.py\", line 146, in VGG16\r\n    x = Dense(4096, activation='relu', name='fc1')(x)\r\n  File \"/home/pi/.local/lib/python3.5/site-packages/keras/engine/topology.py\", line 590, in __call__\r\n    self.build(input_shapes[0])\r\n  File \"/home/pi/.local/lib/python3.5/site-packages/keras/layers/core.py\", line 842, in build\r\n    constraint=self.kernel_constraint)\r\n  File \"/home/pi/.local/lib/python3.5/site-packages/keras/legacy/interfaces.py\", line 91, in wrapper\r\n    return func(*args, **kwargs)\r\n  File \"/home/pi/.local/lib/python3.5/site-packages/keras/engine/topology.py\", line 414, in add_weight\r\n    constraint=constraint)\r\n  File \"/home/pi/.local/lib/python3.5/site-packages/keras/backend/theano_backend.py\", line 154, in variable\r\n    strict=False)\r\n  File \"/usr/local/lib/python3.5/dist-packages/theano/compile/sharedvalue.py\", line 268, in shared\r\n    allow_downcast=allow_downcast, **kwargs)\r\n  File \"/usr/local/lib/python3.5/dist-packages/theano/tensor/sharedvar.py\", line 54, in tensor_constructor\r\n    value=np.array(value, copy=(not borrow)),\r\nMemoryError: you might consider using 'theano.shared(..., borrow=True)'\r\n\r\n```\r\n**Update:**\r\n\r\nThe issue is exclusive to vgg16, any call to vgg16  by any code causes the problem. I will close the issue after your reply as it does not seem to be an issue related to your package.\r\n\r\nI do however have an issue as things work fine vgg16 but not much so with ResNet50 as I always receive the following error even on my usual machine.\r\n```\r\n\r\nUsing Theano backend.\r\nModel type detected: local pooling - flatten\r\nModel cut at layer: 173\r\nPool size infered: 1\r\nTraceback (most recent call last):\r\n  File \"demo.py\", line 39, in <module>\r\n    new_model = to_heatmap(model)\r\n  File \"/home/pi/heatmaps/heatmap/heatmap.py\", line 259, in to_heatmap\r\n    x = copy_last_layers(model, index + 3, x)\r\n  File \"/home/pi/heatmaps/heatmap/heatmap.py\", line 182, in copy_last_layers\r\n    if last_activation == 'softmax':\r\nUnboundLocalError: local variable 'last_activation' referenced before assignment\r\n\r\n```\r\n\r\nIt also does not work with InceptionV3 as it yield the following error.\r\n\r\n```\r\nUsing Theano backend.\r\nModel type detected: global pooling\r\nModel cut at layer: 310\r\nTraceback (most recent call last):\r\n  File \"demo.py\", line 40, in <module>\r\n    new_model = to_heatmap(model)\r\n  File \"/home/abdu/anaconda2/envs/theano/heatmaps/heatmap/heatmap.py\", line 239, in to_heatmap\r\n    x = copy_last_layers(model, index + 1, x)\r\n  File \"/home/abdu/anaconda2/envs/theano/heatmaps/heatmap/heatmap.py\", line 169, in copy_last_layers\r\n    x = add_reshaped_layer(layer, x, 1, no_activation=True)\r\n  File \"/home/abdu/anaconda2/envs/theano/heatmaps/heatmap/heatmap.py\", line 209, in add_reshaped_layer\r\n    x = new_layer(x)\r\n  File \"/home/abdu/anaconda2/envs/theano/lib/python2.7/site-packages/keras/engine/topology.py\", line 573, in __call__\r\n    self.assert_input_compatibility(inputs)\r\n  File \"/home/abdu/anaconda2/envs/theano/lib/python2.7/site-packages/keras/engine/topology.py\", line 472, in assert_input_compatibility\r\n    str(K.ndim(x)))\r\nValueError: Input 0 is incompatible with layer predictions: expected ndim=4, found ndim=2\r\n\r\n```\r\nUsing DenseNet121 and Theano:\r\n```\r\n\r\nUsing Theano backend.\r\nModel type detected: global pooling\r\nModel cut at layer: 425\r\nTraceback (most recent call last):\r\n  File \"demo.py\", line 40, in <module>\r\n    new_model = to_heatmap(model)\r\n  File \"/home/abdu/anaconda2/envs/theano/heatmaps/heatmap/heatmap.py\", line 239, in to_heatmap\r\n    x = copy_last_layers(model, index + 1, x)\r\n  File \"/home/abdu/anaconda2/envs/theano/heatmaps/heatmap/heatmap.py\", line 169, in copy_last_layers\r\n    x = add_reshaped_layer(layer, x, 1, no_activation=True)\r\n  File \"/home/abdu/anaconda2/envs/theano/heatmaps/heatmap/heatmap.py\", line 209, in add_reshaped_layer\r\n    x = new_layer(x)\r\n  File \"/home/abdu/anaconda2/envs/theano/lib/python2.7/site-packages/keras/engine/topology.py\", line 573, in __call__\r\n    self.assert_input_compatibility(inputs)\r\n  File \"/home/abdu/anaconda2/envs/theano/lib/python2.7/site-packages/keras/engine/topology.py\", line 472, in assert_input_compatibility\r\n    str(K.ndim(x)))\r\nValueError: Input 0 is incompatible with layer fc1000: expected ndim=4, found ndim=2\r\n\r\n```\r\n\r\n**Another Update:**\r\n\r\nSo I test some other models using TesorFlow backend and I basically recive the same error which as follow, note that vgg16 model run with no issue.\r\n```\r\n\r\nModel type detected: global pooling\r\nTraceback (most recent call last):\r\n  File \"demo.py\", line 39, in <module>\r\n    new_model = to_heatmap(model)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/heatmaps/heatmap/heatmap.py\", line 234, in to_heatmap\r\n    x = middle_model(img_input)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/engine/topology.py\", line 617, in __call__\r\n    output = self.call(inputs, **kwargs)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/engine/topology.py\", line 2078, in call\r\n    output_tensors, _, _ = self.run_internal_graph(inputs, masks)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/engine/topology.py\", line 2229, in run_internal_graph\r\n    output_tensors = _to_list(layer.call(computed_tensor, **kwargs))\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/layers/normalization.py\", line 185, in call\r\n    self.momentum),\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py\", line 1001, in moving_average_update\r\n    x, value, momentum, zero_debias=True)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/training/moving_averages.py\", line 70, in assign_moving_average\r\n    update_delta = _zero_debias(variable, value, decay)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/training/moving_averages.py\", line 180, in _zero_debias\r\n    \"biased\", initializer=biased_initializer, trainable=False)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py\", line 1065, in get_variable\r\n    use_resource=use_resource, custom_getter=custom_getter)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py\", line 962, in get_variable\r\n    use_resource=use_resource, custom_getter=custom_getter)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py\", line 367, in get_variable\r\n    validate_shape=validate_shape, use_resource=use_resource)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py\", line 352, in _true_getter\r\n    use_resource=use_resource)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/tensorflow/python/ops/variable_scope.py\", line 664, in _get_single_variable\r\n    name, \"\".join(traceback.format_list(tb))))\r\nValueError: Variable block1_conv1_bn/moving_mean/biased already exists, disallowed. Did you mean to set reuse=True in VarScope? Originally defined at:\r\n\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/backend/tensorflow_backend.py\", line 1001, in moving_average_update\r\n    x, value, momentum, zero_debias=True)\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/layers/normalization.py\", line 185, in call\r\n    self.momentum),\r\n  File \"/home/abdu/anaconda2/envs/tensorflowGpu/lib/python2.7/site-packages/keras/engine/topology.py\", line 617, in __call__\r\n    output = self.call(inputs, **kwargs)\r\n\r\n```\r\nI would not wanna bother you with all these models but it would be great i I could at least get it to work with either MobileNet or DenseNet121 as they are light models which is what I need for Raspberry Pi. You should also note how errors are different based on the backend I am using, same error using TensorFlow while different errors based on the model used with Theano.\r\n \r\nThanks"},"comment":{"url":"https://api.github.com/repos/gabrieldemarmiesse/heatmaps/issues/comments/370170712","html_url":"https://github.com/gabrieldemarmiesse/heatmaps/issues/7#issuecomment-370170712","issue_url":"https://api.github.com/repos/gabrieldemarmiesse/heatmaps/issues/7","id":370170712,"user":{"login":"gabrieldemarmiesse","id":12891691,"avatar_url":"https://avatars1.githubusercontent.com/u/12891691?v=4","gravatar_id":"","url":"https://api.github.com/users/gabrieldemarmiesse","html_url":"https://github.com/gabrieldemarmiesse","followers_url":"https://api.github.com/users/gabrieldemarmiesse/followers","following_url":"https://api.github.com/users/gabrieldemarmiesse/following{/other_user}","gists_url":"https://api.github.com/users/gabrieldemarmiesse/gists{/gist_id}","starred_url":"https://api.github.com/users/gabrieldemarmiesse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gabrieldemarmiesse/subscriptions","organizations_url":"https://api.github.com/users/gabrieldemarmiesse/orgs","repos_url":"https://api.github.com/users/gabrieldemarmiesse/repos","events_url":"https://api.github.com/users/gabrieldemarmiesse/events{/privacy}","received_events_url":"https://api.github.com/users/gabrieldemarmiesse/received_events","type":"User","site_admin":false},"created_at":"2018-03-03T18:51:16Z","updated_at":"2018-03-03T18:51:16Z","author_association":"OWNER","body":"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."}}
{"actor":{"display_login":"gabrieldemarmiesse"}}