{"QuestionId":44938063,"AnswerCount":1,"Tags":"","CreationDate":"2017-07-06T00:40:43.230","AcceptedAnswerId":null,"OwnerUserId":6720221.0,"Title":"Tensorflow : If an LSTM is 're-used' for new inputs, do its hidden states reset? In a single forward pass","Body":"

Question : I have an LSTM cell with variable scope name 'rnn' and assign it as 'scope'.<\/p>\n\n

If I use scope.reuse_variables() within a graph, I know that the weights are reused for a new input X...<\/p>\n\n

But if weights are reused, does the LSTM hidden state automatically reset? ... or do I have to explicitly reset the hidden state every time I call scope.reuse_variables()<\/p>\n\n

Thank you !<\/p>\n","answers":[{"AnswerId":"44976008","CreationDate":"2017-07-07T16:48:06.773","ParentId":null,"OwnerUserId":"6824418","Title":null,"Body":"

The hidden state is not saved with the model. It depends on the input data (which gets fed\/queued\/etc.).<\/p>\n"}]} {"QuestionId":44938147,"AnswerCount":2,"Tags":"","CreationDate":"2017-07-06T00:53:18.917","AcceptedAnswerId":44955176.0,"OwnerUserId":8250436.0,"Title":"This program requires version 3.2.0 of the Protocol Buffer runtime library, but the installed version is 2.6.1","Body":"

I'm trying to train a Caffe model. My .prototxt file uses custom Python Data and Loss layers.<\/p>\n\n

When I execute the training command in terminal, however, this error is raised:<\/p>\n\n

<\/pre>\n\n

My Python Package Manager (pip) has version 3.2.0 of protobuf installed, but the system version is at 2.6.1 for a package called libprotoc. I am not sure how to specify that the pip protobuf version is the one I want to use for caffe.<\/p>\n\n

On another computer which has version 3.3.0 of protobuf installed on pip and 2.6.1 for the system version, I was thrown the same error, except that it said the program required version 3.3.0 rather than version 3.2.0.<\/p>\n\n

Best.<\/p>\n","answers":[{"AnswerId":"44955176","CreationDate":"2017-07-06T17:10:36.200","ParentId":null,"OwnerUserId":"7720259","Title":null,"Body":"

I ran into exactly the same issue today. The workaround that worked for me was to start the training from caffe's python interface as opposed to starting it directly from the shell. Example:<\/p>\n\n

import caffe\n\nweights = '..\/ilsvrc-nets\/vgg16-fcn.caffemodel'\ncaffe.set_device(0)\ncaffe.set_mode_gpu()\n\nsolver = caffe.SGDSolver('solver.prototxt')\nsolver.net.copy_from(weights)\n\nfor _ in range(25):\n    solver.step(4000)\n<\/code><\/pre>\n\n

Off course the above is just an example\/very barebones, you'll have to handle running against the validation set yourself but the pycaffe interface is quite flexible and allows you to do all that. You can find more details on how to use that here:<\/p>\n\n

http:\/\/christopher5106.github.io\/deep\/learning\/2015\/09\/04\/Deep-learning-tutorial-on-Caffe-Technology.html<\/a><\/p>\n"},{"AnswerId":"48342935","CreationDate":"2018-01-19T14:08:49.223","ParentId":null,"OwnerUserId":"6839627","Title":null,"Body":"

I went around it by installing the same version of protobuf via pip, as the one from apt-get.<\/p>\n\n

pip install protobuf==2.6<\/code><\/p>\n\n

Alternative (which I wanted to avoid) was to install protobuf from sources.<\/p>\n\n

https:\/\/github.com\/google\/protobuf\/blob\/master\/src\/README.md<\/a><\/p>\n"}]} {"QuestionId":44938160,"AnswerCount":1,"Tags":"","CreationDate":"2017-07-06T00:54:28.137","AcceptedAnswerId":44938317.0,"OwnerUserId":2985796.0,"Title":"Saving layer weights at each epoch during training into a numpy type\/array? Converting TensorFlow Variable to numpy array?","Body":"

I am working with for the first time and am attempting to write a custom <\/a> which saves the weights of each model layer during . I am having trouble converting the type of to a array (or anything from which I can extract the primitive type value).<\/p>\n\n

From what I can tell (for my model) is a list of that hold either a matrix or matrix. I just cannot seem to get this variable type as a (the of the matrices).<\/p>\n\n

Here is a SSCCE of my issue. <\/p>\n\n

<\/pre>\n\n

I did find this SO answer<\/a> which proposes to use (I think a function) to \"evalute\" the tensors (not exactly sure what that means yet but I think thats the proper terminology) into their underlying type -- Which I assume is a matrix or array. Though follow this seems to lead down another rabbit hole of errors (passing to , resulting in \"the tensor's graph is different from the session's graph.\"). <\/p>\n\n

I have found various callbacks<\/a> which can record layer weights during fitting though from what I can tell none of them return them in the desired format. <\/p>\n\n

How can I convert these weights to some object? Is there an easier way other than what I propose in the SSCCE to accomplish what I want?<\/strong><\/p>\n\n


\n\n

For reference the output of the SSCCE above is:<\/p>\n\n

<\/pre>\n","answers":[{"AnswerId":"44938317","CreationDate":"2017-07-06T01:16:40.833","ParentId":null,"OwnerUserId":"2985796","Title":null,"Body":"

I have found that I need to use the method keras.model.layer.get_weights()<\/code> to get the weights as numpy<\/code> arrays.<\/p>\n\n

For instance my callback would change to something like<\/p>\n\n

def on_epoch_end(self, epoch, logs={}):\n    logs = logs or {}\n    self.epoch.append(epoch)\n    for k, v in logs.items():\n        self.history.setdefault(k, []).append(v)\n\n    modelWeights = []\n    for layer in model.layers:\n        layerWeights = []\n        for weight in layer.get_weights():\n            layerWeights.append(weight)\n        modelWeights.append(layerWeights)\n    self.weights.append(modelWeights)\n<\/code><\/pre>\n"}]}
{"QuestionId":44938705,"AnswerCount":0,"Tags":"","CreationDate":"2017-07-06T02:07:10.257","AcceptedAnswerId":null,"OwnerUserId":8262218.0,"Title":"Different batch size different results with inception_v2 during testing","Body":"

I user inception_v2 as a base network for classification. During training, the batchsize=128. <\/p>\n\n

During testing, if the batchsize=128, everything is ok. However, if the batchsize is smaller than 128 the results are different. And the precision declines as the batchsize drops. If the batchsize=1, the network will failed. I also used inception_v3 and inception_v1, the same problems appered. However, if the base network is replaced with Alex network (tensorflow), everything goes well. I also replace the inception_v2 with vgg (slim), and everything goes well.<\/p>\n\n

I think the bug is associated with inception_v1~v3 or batch normalization. Maybe I have not used inception_v2 properly. Did anyone encounter similar problems?<\/p>\n\n

\n\n<\/i><\/p>\n\n

During testing, is_training=False<\/p>\n\n

\nrestore_list = [v for v in tf.trainable_variables() if (v.name.startswith(\"InceptionV2\"))]\nsaver_googlenet = tf.train.Saver(var_list=restore_list) # var_list=restore_list\nsaver_googlenet.restore(sess, 'inception_v2.ckpt')<\/p>\n\n

saver_all = tf.train.Saver(var_list=tf.global_variables(),max_to_keep=20)<\/p>\n\n

<\/i><\/p>\n","answers":[]} {"QuestionId":44938809,"AnswerCount":1,"Tags":"","CreationDate":"2017-07-06T02:22:50.757","AcceptedAnswerId":46268972.0,"OwnerUserId":5566589.0,"Title":"How to add operations into Tensorflow Android build","Body":"

I am trying to run my Tensorflow model on Android, so I am using the nightly native build in here<\/a> and following the Android demo<\/a>, I have been successfully get the Tensorflow Android lib running and loaded up the model with below code.<\/p>\n\n

<\/pre>\n\n

And the log shows the results are good.<\/p>\n\n

<\/pre>\n\n

However, when I finished feeding all the input nodes<\/p>\n\n

<\/pre>\n\n

Then call the run method<\/p>\n\n

<\/pre>\n\n

The Tensorflow is broken saying that some kernels are not registered<\/p>\n\n

<\/pre>\n\n

I think the \"LessEqual\" for int32 should be defined in Tensorflow but just not built along with Tensorflow Android Lib.<\/p>\n\n

So my question is how to include more kernels in the Android lib build or any other way to resolve this, any help will be much appreciated.<\/strong> <\/p>\n","answers":[{"AnswerId":"46268972","CreationDate":"2017-09-17T21:19:12.660","ParentId":null,"OwnerUserId":"112705","Title":null,"Body":"

I recommending reading this free eBook: Building Mobile Applications with TensorFlow<\/a><\/p>\n\n

It has a section on What Ops Are Available on Mobile?<\/code> (page 33), which explains how to Add the implementation to the build<\/code> for those op kernels which default to being stripped out for mobile builds.<\/p>\n\n

FYI, the eBook is written by Pete Warden (GitHub<\/a>, blog<\/a>), who works at Google and is one of the maintainers of TensorFlow.<\/p>\n"}]} {"QuestionId":44939210,"AnswerCount":2,"Tags":"","CreationDate":"2017-07-06T03:16:50.860","AcceptedAnswerId":null,"OwnerUserId":7476905.0,"Title":"TensorFlow RandomForest vs Deep learning","Body":"

I am using TensorFlow for training model which has 1 output for the 4 inputs. The problem is of regression.<\/p>\n\n

I found that when I use RandomForest to train the model, it quickly converges and also runs well on the test data. But when I use a simple Neural network for the same problem, the loss(Random square error) does not converge. It gets stuck on a particular value. <\/p>\n\n

I tried increasing\/decreasing number of hidden layers, increasing\/decreasing learning rate. I also tried multiple optimizers and tried to train the model on both normalized and non-normalized data. <\/p>\n\n

I am new to this field but the literature that I have read so far vehemently asserts that the neural network should marginally and categorically work better than the random forest.<\/p>\n\n

What could be the reason behind non-convergence of the model in this case? <\/p>\n","answers":[{"AnswerId":"44950403","CreationDate":"2017-07-06T13:30:25.357","ParentId":null,"OwnerUserId":"5587601","Title":null,"Body":"

A useful rule for beginning training models, is not to begin with the more complex methods, for example, a Linear model, which you will be able to understand and debug more easily.<\/p>\n\n

In case you continue with the current methods, some ideas:<\/p>\n\n