{"QuestionId":42689066,"AnswerCount":5,"Tags":"","CreationDate":"2017-03-09T07:20:54.127","AcceptedAnswerId":55304690.0,"OwnerUserId":7682122.0,"Title":"Convolutional Neural Net-Keras-val_acc Keyerror 'acc'","Body":"

I am trying to implement CNN by Theano. I used Keras library. My data set is 55 alphabet images, 28x28. <\/p>\n\n

In the last part I get this error:\n\"enter<\/a><\/p>\n\n

<\/pre>\n\n

Any help would be much appreciated. Thanks.<\/p>\n\n

This is part of my code:<\/p>\n\n

\r\n
\r\n
<\/pre>\r\n<\/div>\r\n<\/div>\r\n<\/p>\n","answers":[{"AnswerId":"55304690","CreationDate":"2019-03-22T17:12:50.370","ParentId":null,"OwnerUserId":"7978903","Title":null,"Body":"

Your log<\/code> variable will be consistent with the metrics<\/code> when you compile your model.<\/p>\n\n

For example, the following code<\/p>\n\n

model.compile(loss=\"mean_squared_error\", optimizer=optimizer) \nmodel.fit_generator(gen,epochs=50,callbacks=ModelCheckpoint(\"model_{acc}.hdf5\")])\n<\/code><\/pre>\n\n

will gives a KeyError: 'acc'<\/code> because you didn't set metrics=[\"accuracy\"]<\/code> in model.compile<\/code>.<\/p>\n\n

This error also happens when metrics are not matched. For example<\/p>\n\n

model.compile(loss=\"mean_squared_error\",optimizer=optimizer, metrics=\"binary_accuracy\"]) \nmodel.fit_generator(gen,epochs=50,callbacks=ModelCheckpoint(\"model_{acc}.hdf5\")])\n<\/code><\/pre>\n\n

still gives a KeyError: 'acc'<\/code> because you set a binary_accuracy<\/code> metric but asking for accuracy<\/code> later.<\/p>\n\n

If you change the above code to<\/p>\n\n

model.compile(loss=\"mean_squared_error\",optimizer=optimizer, metrics=\"binary_accuracy\"]) \nmodel.fit_generator(gen,epochs=50,callbacks=ModelCheckpoint(\"model_{binary_accuracy}.hdf5\")])\n<\/code><\/pre>\n\n

it will work.<\/p>\n"},{"AnswerId":"58522027","CreationDate":"2019-10-23T11:39:02.243","ParentId":null,"OwnerUserId":"8461820","Title":null,"Body":"

You can use print(history.history.keys())<\/code> to find out what metrics you have and what they are called. In my case also, it was called \"accuracy\"<\/code>, not \"acc\"<\/code><\/p>\n"},{"AnswerId":"42690445","CreationDate":"2017-03-09T08:38:22.220","ParentId":null,"OwnerUserId":"7137636","Title":null,"Body":"

from keras source<\/a> :<\/p>\n\n

warnings.warn('The \"show_accuracy\" argument is deprecated, '\n                          'instead you should pass the \"accuracy\" metric to '\n                          'the model at compile time:\\n'\n                          '`model.compile(optimizer, loss, '\n                          'metrics=[\"accuracy\"])`')\n<\/code><\/pre>\n\n

The right way to get the accuracy is indeed to compile your model like this:<\/p>\n\n

model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=[\"accuracy\"])\n<\/code><\/pre>\n\n

does it work? <\/p>\n"},{"AnswerId":"58282771","CreationDate":"2019-10-08T08:32:58.270","ParentId":null,"OwnerUserId":"9625777","Title":null,"Body":"

In a not-so-common case (as I expected after some tensorflow updates), despite choosing metrics=[\"accuracy\"]<\/strong> in the model definitions, I still got the same error. <\/p>\n\n

The solution was: replacing metrics=[\"acc\"]<\/strong> with metrics=[\"accuracy\"] everywhere<\/strong>. In my case, I was unable to plot the parameters of the history of my training. I had to replace<\/p>\n\n

acc = history.history['acc']\nval_acc = history.history['val_acc']\n\nloss = history.history['loss']\nval_loss = history.history['val_loss']\n<\/code><\/pre>\n\n

to <\/p>\n\n

acc = history.history['accuracy']\nval_acc = history.history['val_accuracy']\n\nloss = history.history['loss']\nval_loss = history.history['val_loss']\n<\/code><\/pre>\n"},{"AnswerId":"58652673","CreationDate":"2019-11-01T00:16:31.903","ParentId":null,"OwnerUserId":"6013016","Title":null,"Body":"

In my case switching from<\/p>\n\n

metrics=[\"accuracy\"]\n<\/code><\/pre>\n\n

to<\/p>\n\n

metrics=[\"acc\"]\n<\/code><\/pre>\n\n

was the solution. So, switching them from one to another might help<\/p>\n"}]} {"QuestionId":42689342,"AnswerCount":2,"Tags":"","CreationDate":"2017-03-09T07:36:56.593","AcceptedAnswerId":null,"OwnerUserId":2813092.0,"Title":"Compare two tensors elementwise (tensorflow)","Body":"

I have two 1D Tensorflow tensors and I want to compare them elementwise and create a new tensor recording the indices at which they differ. For context, they each store indices into a different, 2D tensor, so if I could use them like numpy arrays I might do something like:<\/p>\n\n

<\/pre>\n\n

but in the case where predicted_indices and correct_indices are both tensors, how can I do this?<\/p>\n\n

Also open to other ways to do this. I'm trying to store the specific examples that my model gets wrong at some epoch.<\/p>\n","answers":[{"AnswerId":"42690149","CreationDate":"2017-03-09T08:23:07.277","ParentId":null,"OwnerUserId":"6487788","Title":null,"Body":"

In Tensorflow you build a graph in which you define the operations, before you actually perform the operation. \nIn this case the operation you can use is the tf.equal function where you pass your predicted_indices and input_placeholder as arguments. This returns a boolean tensor. <\/p>\n\n

Check the operation and other comparison operations here: https:\/\/www.tensorflow.org\/versions\/master\/api_docs\/python\/control_flow_ops\/comparison_operators#equal<\/a><\/p>\n\n

Good luck!<\/p>\n"},{"AnswerId":"51246945","CreationDate":"2018-07-09T13:37:17.217","ParentId":null,"OwnerUserId":"3999668","Title":null,"Body":"

There are two aspects to this<\/p>\n\n

sess1=tf.InteractiveSession()\na=np.random.randint(5,size=(1,10))\nb=np.random.randint(5,size=(1,10))\n\na1=tf.convert_to_tensor(a,dtype=tf.float32)\nb1=tf.convert_to_tensor(b,dtype=tf.float32)\n<\/code><\/pre>\n\n

Boolean Comparison<\/strong><\/p>\n\n

print(a1.eval())\nprint(b1.eval())\nresult=tf.equal(a1,b1)\nprint(result.eval())\n<\/code><\/pre>\n\n

Element Comparison<\/strong><\/p>\n\n

print(a1.eval())\nprint(b1.eval())\nresult=tf.add(a1,-a2)\nprint(result.eval())\n<\/code><\/pre>\n\n

Once you have this, you can use this in any capacity that you want<\/p>\n"}]} {"QuestionId":42689902,"AnswerCount":0,"Tags":"","CreationDate":"2017-03-09T08:09:33.827","AcceptedAnswerId":null,"OwnerUserId":7596581.0,"Title":"Run SSD on ssd-windows branch issues","Body":"

I use ssd-windows branch on windows 10,I compiled it successfully.But when I run the ssd_pascal_video.py<\/strong>,I got an error below:<\/p>\n\n

<\/pre>\n\n

The following is the code address.<\/p>\n\n

https:\/\/github.com\/conner99\/caffe<\/a> <\/p>\n\n

Someone know the reason? Thank you!<\/p>\n","answers":[]} {"QuestionId":42690428,"AnswerCount":1,"Tags":"","CreationDate":"2017-03-09T08:37:25.160","AcceptedAnswerId":42691140.0,"OwnerUserId":7683083.0,"Title":"JuPyTer crashes on simple Theano function","Body":"

I just recently installed python and JuPyTeron a new MacOS and wanted to get into DeepLearning. Therefore, I was looking at Theano.<\/p>\n\n

But when I try to execute a very simple function with Theano in the JuPyTer Notebook, it crashes on me, and I don't get why. Can you please help me?<\/p>\n\n

Here is the code:<\/p>\n\n

<\/pre>\n\n

I have isolated the error to the last line, when the following message pops up: <\/p>\n\n

Picture of JuPyTer crash<\/a><\/p>\n","answers":[{"AnswerId":"42691140","CreationDate":"2017-03-09T09:12:27.060","ParentId":null,"OwnerUserId":"7683083","Title":null,"Body":"

After installing the bleeding edge version of Theano via sudo -H pip3 install --upgrade --no-deps git+git:\/\/github.com\/Theano\/Theano.git<\/code> the error vanished. Also, for anyone, who is also trying to troubleshoot their Theano issues: try to run import theano;theano.test()<\/code> and look for the errors and warnings shown.<\/p>\n"}]} {"QuestionId":42690744,"AnswerCount":0,"Tags":"","CreationDate":"2017-03-09T08:54:49.510","AcceptedAnswerId":null,"OwnerUserId":4542398.0,"Title":"Are these two snippets of code equivalent (implementing siamese RNN network using Keras)?","Body":"

I want to implement a siamese RNN network where the two legs of this net are shared and at every time step, the RNN take CNN output as input, like this:<\/p>\n\n

<\/pre>\n\n

I'm implementing it using Keras TimeDistributed Wrapper in this way:<\/p>\n\n

<\/pre>\n\n

I dont know if the above code is equivalent with the following:<\/p>\n\n

<\/pre>\n\n

In both settings, the model can work well with the same input. But is there any difference between these two implementations? Or there is another way to write?<\/p>\n","answers":[]} {"QuestionId":42690755,"AnswerCount":0,"Tags":"","CreationDate":"2017-03-09T08:55:18.883","AcceptedAnswerId":null,"OwnerUserId":3653720.0,"Title":"Output shape error with keras convolutional layer","Body":"

I'm creating fully convolutional network in keras. I have a simple code<\/p>\n\n

<\/pre>\n\n

I have model summary<\/p>\n\n

<\/pre>\n\n

And I have corresponding training sample size<\/p>\n\n

<\/pre>\n\n

But I get error<\/p>\n\n

<\/pre>\n\n

I cannot understand why it expects convolution2d_3 to have shape (None, 1, 800, 1) if in model.summary it is (None, 1, 800, 1360). What problem with it? Please give me advice what's wrong.<\/p>\n","answers":[]} {"QuestionId":42691738,"AnswerCount":0,"Tags":"","CreationDate":"2017-03-09T09:40:57.360","AcceptedAnswerId":null,"OwnerUserId":5571327.0,"Title":"Tensorflow installation issue","Body":"

My computer already installed Python 3.5 with anaconda<\/a>.<\/p>\n\n

<\/p>\n\n

I'm following the Installation instruction<\/a>. There are some errors show up when I want to specify my targetDirectory. <\/p>\n\n

<\/p>\n\n

<\/pre>\n\n

How can I fix the environment issue? <\/p>\n","answers":[]} {"QuestionId":42691762,"AnswerCount":1,"Tags":"","CreationDate":"2017-03-09T09:42:13.177","AcceptedAnswerId":null,"OwnerUserId":1974842.0,"Title":"Why does the dimension of the input of a LSTMCell must match the number of units","Body":"

When I read TensorFlow's where is implemented, I see the following<\/p>\n\n

<\/pre>\n\n

I am wondering why the dimension of must match the number of units () of the LSTM. I would expect them to be completely unrelated but somehow they're not.<\/p>\n\n

Does anyone know why?<\/p>\n","answers":[{"AnswerId":"46767249","CreationDate":"2017-10-16T09:42:12.113","ParentId":null,"OwnerUserId":"3552975","Title":null,"Body":"

It doesn't need to match the number of units(i.e. the hidden dimension) of the cell.<\/p>\n\n

First of all: <\/p>\n\n

\n

num_proj: (optional) int, The output dimensionality for the projection\n matrices. If None, no projection is performed.<\/p>\n<\/blockquote>\n\n

That's to say, num_proj is the dimentionality of the cell's output which can not match the dimension of the num_units(hidden dimension). Usually the output we want while decoding is of the same dimension of the vocabulary(not the dimension of the hidden dimension or number units here). <\/p>\n\n

      if self._num_proj is not None:\n        with vs.variable_scope(\"projection\") as proj_scope:\n          if self._num_proj_shards is not None:\n            proj_scope.set_partitioner(\n                partitioned_variables.fixed_size_partitioner(\n                    self._num_proj_shards))\n          m = _linear(m, self._num_proj, bias=False)\n<\/code><\/pre>\n\n

As you can see above it just transfer the output(m) to be having num_proj dimension by a _linear projection\/transformation. This defaults just to the same as hidden dimension if num_proj is None. <\/p>\n\n

def _linear(args, output_size, bias, bias_start=0.0, scope=None):\n    \"\"\"Linear map: sum_i(args[i] * W[i]), where W[i] is a variable.\n\n    Args:\n      args: a 2D Tensor or a list of 2D, batch x n, Tensors.\n      output_size: int, second dimension of W[i].\n      bias: boolean, whether to add a bias term or not.\n      bias_start: starting value to initialize the bias; 0 by default.\n      scope: VariableScope for the created subgraph; defaults to \"Linear\".\n\n    Returns:\n      A 2D Tensor with shape [batch x output_size] equal to\n      sum_i(args[i] * W[i]), where W[i]s are newly created matrices.\n\n    Raises:\n      ValueError: if some of the arguments has unspecified or wrong shape.\n    \"\"\"\n    if args is None or (isinstance(args, (list, tuple)) and not args):\n        raise ValueError(\"`args` must be specified\")\n    if not isinstance(args, (list, tuple)):\n        args = [args]\n\n    # Calculate the total size of arguments on dimension 1.\n    total_arg_size = 0\n    shapes = [a.get_shape().as_list() for a in args]\n    for shape in shapes:\n        if len(shape) != 2:\n            raise ValueError(\"Linear is expecting 2D arguments: %s\" % str(shapes))\n        if not shape[1]:\n            raise ValueError(\"Linear expects shape[1] of arguments: %s\" % str(shapes))\n        else:\n            total_arg_size += shape[1]\n\n    # Now the computation.\n    with tf.variable_scope(scope or \"Linear\"):\n        matrix = tf.get_variable(\"Matrix\", [total_arg_size, output_size])\n        if len(args) == 1:\n            res = tf.matmul(args[0], matrix)\n        else:\n            res = tf.matmul(tf.concat(axis=1, values=args), matrix)\n        if not bias:\n            return res\n        bias_term = tf.get_variable(\"Bias\", [output_size], initializer=tf.constant_initializer(bias_start))\n    return res + bias_term\n<\/code><\/pre>\n"}]}
{"QuestionId":42692093,"AnswerCount":0,"Tags":"","CreationDate":"2017-03-09T09:55:58.453","AcceptedAnswerId":null,"OwnerUserId":3437428.0,"Title":"How to create a TFRecord in PHP?","Body":"

I would like to create a TFRecord file in PHP, but I'm not sure where to start, so a bit of help would be welcome (I also figure this question could help a few out here).<\/p>\n\n

Here's what the code looks like in Python:<\/p>\n\n

<\/pre>\n\n

Here are the references I've been using (unsuccessfully) so far:<\/p>\n\n