{"QuestionId":51682164,"AnswerCount":0,"Tags":"","CreationDate":"2018-08-04T03:25:29.427","AcceptedAnswerId":null,"OwnerUserId":10178684.0,"Title":"specified in either feed_devices or fetch_devices was not found in the Graph tensorflow","Body":"

I use tensorflow C++ API.I train model on GPU and execute this code(for predict)<\/p>\n\n

<\/pre>\n\n

But, I got unknown error like this.<\/p>\n\n

<\/pre>\n\n

This error occured this code.<\/p>\n\n

<\/pre>\n\n

https:\/\/github.com\/tensorflow\/tensorflow\/blob\/master\/tensorflow\/core\/common_runtime\/graph_execution_state.cc<\/a>\nAt this site explain this error occurs when node name is not equal.\nI create model by keras, not tensorflow.\nSo, I translate model from keras to tensorflow by this code.\nhttps:\/\/github.com\/icchi-h\/keras_to_tensorflow\/blob\/master\/keras_to_tensorflow.py<\/a><\/p>\n\n

I guess it has a connection with training on GPU.\nhttps:\/\/github.com\/tensorflow\/tensorflow\/issues\/5902<\/a><\/p>\n\n

But, I can't get corroboration about this.<\/p>\n\n

Please teach me the solution of this problem.<\/p>\n","answers":[]} {"QuestionId":51682492,"AnswerCount":0,"Tags":"","CreationDate":"2018-08-04T04:42:28.330","AcceptedAnswerId":null,"OwnerUserId":5752875.0,"Title":"Why my tf.profiler.Profiler complains \"Found accelerator operation but misses accelerator stream stats\"","Body":"

I'm using the tf.profiler.Profiler<\/a> trying to get some insight of my model and hopefully to improve its performance. But both of and 's output is missing the GPU timing stats. <\/p>\n\n

Here is some excerpt of the operation profile's output:<\/p>\n\n

<\/pre>\n\n

All the stats in the column is zero.<\/p>\n","answers":[]} {"QuestionId":51682648,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T05:09:32.337","AcceptedAnswerId":51683689.0,"OwnerUserId":8599868.0,"Title":"Using Keras ImageDataGenerator predictions for indexing raises unhashable type error","Body":"

I have created a classifier for <\/a>, created using such as:<\/p>\n\n

<\/pre>\n\n

When running it, I get in the last row of the following code snippet:<\/p>\n\n

<\/pre>\n\n

What might be causing it?<\/p>\n\n

Additionally, how should I proceed to generate a confusion matrix from this classifier results?<\/p>\n\n

This:<\/p>\n\n

<\/pre>\n\n

raises an error .<\/p>\n","answers":[{"AnswerId":"51683689","CreationDate":"2018-08-04T08:02:26.737","ParentId":null,"OwnerUserId":"2550541","Title":null,"Body":"

So, after long lucubrations the issue was within the last list comprehension, as predictions<\/code> was a column numpy array, such as [[1],[1],[0], ..., [0]]<\/code>.<\/p>\n\n

So it was just necessary to access the integer values within:<\/p>\n\n

textual_predictions = [s_label_map[k] for k in predictions.T[0]]\n<\/code><\/pre>\n\n

Additionally there was another error creating the confusion matrix<\/strong>, that had the wrong variables as input:<\/p>\n\n

tn, fp, fn, tp = confusion_matrix(testing_imGen.classes, predictions.T[0]).ravel()\n<\/code><\/pre>\n"}]}
{"QuestionId":51683380,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T07:12:03.663","AcceptedAnswerId":null,"OwnerUserId":4897044.0,"Title":"Why is this simple regression (keras) ANN is failing so bad?","Body":"

I am trying to do a non-linear regression on a very simple data. When running the following code i got really bad results. Almost every time the result is a simple linear regression. When i check the weights of my model most (if not all) neurons are 'dead'. They all have negative weights with negative biases making the ReLu function to return 0 for all inputs (since all inputs are in the range [0,1]). <\/p>\n\n

As far as i can tell this is a problem with the optimizer. I also tried using a very low and a very high learning rate, no luck. The optimizer seems to be getting stuck in a 'very' sub optimal local minima.<\/p>\n\n

I also tried to set the initial weights to be all positive [0,0.1], the optimizer 'cheats' its way into a linear regression by setting all biases roughly at the same value.<\/p>\n\n

Any can help me? what i am doing wrong? Is this really the best a state of the art ANN can achieve on a simple regression problem?<\/p>\n\n

<\/pre>\n\n

predicted outputs versus actual ones.<\/a><\/p>\n","answers":[{"AnswerId":"51685915","CreationDate":"2018-08-04T13:08:29.547","ParentId":null,"OwnerUserId":"8563649","Title":null,"Body":"

Change sigmoid with relu activation and fix your ) type error in the end of sgd.<\/p>\n\n

EDIT<\/p>\n\n

Also add a second dense layer and train for much more epochs, like this:<\/p>\n\n

model <- keras_model_sequential() %>%\n  layer_dense(10, 'relu', input_shape = 1) %>%\n  layer_dense(10, 'relu') %>%\n  layer_dense(1)\n\nmodel %>% compile(\n  optimizer = 'sgd',\nloss = \"mse\"\n)\n\nhistory <- model %>% \n  fit(x = x_train, y = y_train,\n      epochs = 2000,\n      batch_size = 10,\n      validation_data = list(x_test, y_test)\n  )\n<\/code><\/pre>\n"}]}
{"QuestionId":51683471,"AnswerCount":2,"Tags":"","CreationDate":"2018-08-04T07:27:02.153","AcceptedAnswerId":51695373.0,"OwnerUserId":10159342.0,"Title":"How to add custom image sharpening layer in keras?","Body":"

I'm building a model in keras that detects building rooftops from images. I want to add a custom sharpening layer inside model. I know we can sharpen images in preprocessing, but it would be nice if i add a layer. I tried Lambda layer with my custom sharpening function but it didn't worked, then i tried a custom layer and got the same error:<\/p>\n\n

<\/pre>\n\n

Here is my custom layer:<\/p>\n\n

<\/pre>\n\n

Here is the model where i want to put this layer:<\/p>\n\n

<\/pre>\n","answers":[{"AnswerId":"51683552","CreationDate":"2018-08-04T07:41:09.457","ParentId":null,"OwnerUserId":"4866042","Title":null,"Body":"

I think this should be done as part of the preprocessing step as there are no parameters that you would want to train in the sharpening layer in order to aid feature generation or classification, so it does not need to be part of the network model.<\/p>\n\n

Keras Image Pre-processing documentation is here: https:\/\/keras.io\/preprocessing\/image\/<\/a><\/p>\n"},{"AnswerId":"51695373","CreationDate":"2018-08-05T14:52:40.730","ParentId":null,"OwnerUserId":"10159342","Title":null,"Body":"

I found out how to create a custom layer with a custom kernel. Thanks apple apple for the hint of using conv2d.<\/p>\n\n

I used Tensorflow's tf.nn.conv2d, instead of cv2.filter2D, with my custom sharpening filter. Here is that custom layer:<\/p>\n\n

# CUSTOM SHARPEN LAYER\nclass Sharpen(tf.keras.layers.Layer):\n    def __init__(self, num_outputs):\n        super(Sharpen, self).__init__()\n        self.num_outputs = num_outputs\n\n    def build(self, input_shape):\n        self.kernel = np.array([[-2, -2, -2], \n                                [-2, 17, -2], \n                                [-2, -2, -2]])\n        self.kernel = tf.expand_dims(self.kernel, 0)\n        self.kernel = tf.expand_dims(self.kernel, 0)\n        self.kernel = tf.cast(self.kernel, tf.float32)\n\n    def call(self, input_):\n        return tf.nn.conv2d(input_, self.kernel, strides=[1, 1, 1, 1], padding='SAME')\n<\/code><\/pre>\n"}]}
{"QuestionId":51683495,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T07:31:09.370","AcceptedAnswerId":51683707.0,"OwnerUserId":1959884.0,"Title":"what does it mean to set kernel_regularizer to be l2_regularizer in tf.layers.conv2d?","Body":"

I found in other questions that to do L2 regularization in convolutional networks using tensorflow the standard way is as follow.<\/p>\n\n

For each conv2d layer, set the parameter to be like this<\/p>\n\n

<\/pre>\n\n

Then in the loss function, collect the reg loss<\/p>\n\n

<\/pre>\n\n

Many people including me made the mistake skipping the 2nd step. That implies the meaning of is not well understood. I have an assumption that I can't confirm. That is<\/p>\n\n

\n

By setting for a single layer you are telling the network to forward\n the kernel weights at this layer to the loss function at the end of the network such\n that later you will have the option (by another piece of code you write) to include them in the final regularization term in the loss\n function. Nothing more.<\/p>\n<\/blockquote>\n\n

Is it correct or is there a better explanation?<\/p>\n","answers":[{"AnswerId":"51683707","CreationDate":"2018-08-04T08:04:45.520","ParentId":null,"OwnerUserId":"2891324","Title":null,"Body":"

Setting a regularizer to a tf.layer.*<\/code> means to just keep the layer weights, apply the regularization (that means to just create a node in the computational graph that computes this regularization on this specified set of weights and nothing more) and add this node to the tf.GraphKeys.REGULARIZATION_LOSSES<\/code> collection.<\/p>\n\n

After that, is your work to get the elements of this collection and add it to your loss.<\/p>\n\n

In order to do that, you can just use tf.losses.get_regularization_losses<\/code> and sum all the returned terms.<\/p>\n\n

In your code there's an error, you shouldn't add an additional multiplicative constant reg_constant * sum(reg_losses)<\/code> because this term is already added when you specified the regularization for the layer.<\/p>\n"}]} {"QuestionId":51683574,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T07:44:18.663","AcceptedAnswerId":null,"OwnerUserId":5163953.0,"Title":"Running tensorflow with tmux on Ubuntu server error","Body":"

I am trying to run a deep learning program using tmux. However it seems like tensorflow is not available. <\/p>\n\n

To start the tmux environment i run:<\/p>\n\n

<\/pre>\n\n

Then inside the tmux environment I run:<\/p>\n\n

<\/pre>\n\n

Importing other packages than tensorflow such as PIL or cv2 works fine. Importing tensorflow outside of the tmux environment the works. <\/p>\n\n

I am running this on an ubuntu 16 AWS server. What could be the issue?<\/p>\n","answers":[{"AnswerId":"51683936","CreationDate":"2018-08-04T08:43:00.660","ParentId":null,"OwnerUserId":"5163953","Title":null,"Body":"

To wrap this up. As @user2906838 pointed out the problem was that I was inside anaconda virtural environment before I ran tmux. When I exited the environment before running tmux and entered the environment inside of tmux everything worked as usual. <\/p>\n"}]} {"QuestionId":51683647,"AnswerCount":0,"Tags":"","CreationDate":"2018-08-04T07:55:52.303","AcceptedAnswerId":null,"OwnerUserId":6401867.0,"Title":"Keras, different precision and recall on shuffled and not-shuffled test data","Body":"

I'm writing a model, with keras for binary classification based on some values, in my test\/train set I had positive and negative examples separated, for training I shuffle them together. On test set I expect that I do not need to shuffle the data, since there should be no difference in order. While precision of the model without shuffled test data does decrease, the recall and precision stays low. On the other hand when I do shuffle the test data, precision stays the same, but the recall and precision has higher values. I left graphs of precision and recall bellow, so check them.<\/p>\n\n

So first question I have is, why is there a difference between shuffled and un-shuffled data in precision and recall values?<\/p>\n\n

Second question which score should I trust, or should I measure recall and precision differently?<\/p>\n\n

Code bellow:<\/p>\n\n

<\/pre>\n\n

recall function:<\/p>\n\n

<\/pre>\n\n

precision function:<\/p>\n\n

<\/pre>\n\n

Recall with shuffled test data<\/a><\/p>\n\n

Precision with shuffled test data<\/a><\/p>\n\n

Recall withoud suffling test data<\/a><\/p>\n\n

Precision without suffilng test data<\/a><\/p>\n","answers":[]} {"QuestionId":51683852,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T08:30:59.927","AcceptedAnswerId":51690145.0,"OwnerUserId":3856056.0,"Title":"Can't use eager execution in Tensorflow 1.5 on windows7 machine","Body":"

Problem<\/strong><\/h2>\n\n
\n

cant use eager execution in tensorflow version 1.5<\/p>\n<\/blockquote>\n\n

code<\/strong><\/h2>\n\n
<\/pre>\n\n

Stack Trace<\/strong><\/h2>\n\n
\n

C:\\ProgramData\\Anaconda3\\lib\\site-packages\\h5py__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from to is deprecated. In future, it will be treated as .\n from ._conv import register_converters as _register_converters\n Traceback (most recent call last):\n File \"D:\/Users\/hello\/PycharmProjects\/crimeBuster\/main.py\", line 6, in \n tf.enable_eager_execution()\n AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'<\/p>\n<\/blockquote>\n\n

Version<\/strong><\/h2>\n\n
<\/pre>\n","answers":[{"AnswerId":"51690145","CreationDate":"2018-08-04T22:57:42.027","ParentId":null,"OwnerUserId":"4685471","Title":null,"Body":"

Back in version 1.5<\/a>, eager execution was still in the contributed packages, so you need to import it explicitly; the correct usage is: <\/p>\n\n

import tensorflow as tf\nimport tensorflow.contrib.eager as tfe\ntfe.enable_eager_execution()\n<\/code><\/pre>\n\n

Also, just keep in mind that:<\/p>\n\n

\n

For eager execution, we recommend using TensorFlow version 1.8 or newer.<\/p>\n<\/blockquote>\n\n

(from the Github page<\/a>)<\/p>\n\n

Version 1.7 was the first where the command tf.enable_eager_execution()<\/code> was made available, i.e. eager execution was moved out of contrib<\/code> (see v1.7 changes<\/a>).<\/p>\n"}]} {"QuestionId":51683915,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T08:39:47.263","AcceptedAnswerId":51684817.0,"OwnerUserId":305665.0,"Title":"How can I limit regression output between 0 to 1 in keras","Body":"

I am trying to detect the single pixel location of a single object in an image. I have a keras CNN regression network with my image tensor as the input, and a 3 item vector as the output.<\/p>\n\n

First item<\/strong>: Is a 1 (if an object was found) or 0 (no object was found)<\/p>\n\n

Second item<\/strong>: Is a number between 0 and 1 which indicates how far along the x axis is the object<\/p>\n\n

Third item<\/strong>: Is a number between 0 and 1 which indicates how far along the y axis is the object<\/p>\n\n

I have trained the network on 2000 test images and 500 validation images, and the val_loss is far less than 1, and the val_acc is best at around 0.94. Excellent.<\/p>\n\n

But then when I predict the output, I find the values for all three output items are not between 0 and 1, they are actually between -2 and 3 approximately. All three items should be between 0 and 1.<\/p>\n\n

I have not used any non-linear activation functions on the output layer, and have used relus for all non-output layers. Should I be using a softmax, even though it is non-linear? The second and third items are predicting the x and y axis of the image, which appear to me as linear quantities.<\/p>\n\n

Here is my keras network:<\/p>\n\n

<\/pre>\n\n

Can anyone please help? Thanks! :)\nChris<\/p>\n","answers":[{"AnswerId":"51684817","CreationDate":"2018-08-04T10:48:33.807","ParentId":null,"OwnerUserId":"349130","Title":null,"Body":"

The sigmoid activation produces outputs between zero and one, so if you use it as activation of your last layer(the output), the network's output will be between zero and one.<\/p>\n\n

output = Dense(3, activation=\"sigmoid\")(dense)\n<\/code><\/pre>\n"}]}
{"QuestionId":51683967,"AnswerCount":0,"Tags":"","CreationDate":"2018-08-04T08:46:30.187","AcceptedAnswerId":null,"OwnerUserId":6495610.0,"Title":"Python - ImportError: Could not find 'nvcuda.dll'","Body":"

i just want to make object recognition from inception pre trained model using tensorflow & i am using this code:<\/p>\n\n

<\/pre>\n\n

i find this code from this repo<\/a> when i simple run this by giving command in cmd \"python classify.py\" then it show me this error <\/p>\n\n

\n

Traceback (most recent call last):\n File \"C:\\Users---\\Python\\Python36\\lib\\site-packages\\tensorflow\\python\\platform\\self_check.py\", line 62, in preload_check\n ctypes.WinDLL(build_info.nvcuda_dll_name)\n File \"C:\\Users---\\Python\\Python36\\lib\\ctypes__init__.py\", line 348, in init<\/strong>\n self._handle = _dlopen(self._name, mode)\n OSError: [WinError 126] The specified module could not be found<\/p>\n<\/blockquote>\n\n

During handling of the above exception, another exception occurred:<\/p>\n\n

\n

Traceback (most recent call last): File \"obj_recog.py\", line 41, in\n \n import tensorflow as tf File \"C:\\Users---\\Python\\Python36\\lib\\site-packages\\tensorflow__init__.py\",\n line 22, in \n from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import File\n \"C:\\Users---\\Python\\Python36\\lib\\site-packages\\tensorflow\\python__init__.py\",\n line 49, in \n from tensorflow.python import pywrap_tensorflow File \"C:\\Users---\\Python\\Python36\\lib\\site-packages\\tensorflow\\python\\pywrap_tensorflow.py\",\n line 30, in \n self_check.preload_check() File \"C:\\Users---\\Python\\Python36\\lib\\site-packages\\tensorflow\\python\\platform\\self_check.py\",\n line 70, in preload_check\n % build_info.nvcuda_dll_name) ImportError: Could not find 'nvcuda.dll'. TensorFlow requires that this DLL be installed in a\n directory that is named in your %PATH% environment variable. Typically\n it is installed in 'C:\\Windows\\System32'. If it is not present, ensure\n that you have a CUDA-capable GPU with the correct driver installed.<\/p>\n<\/blockquote>\n","answers":[]} {"QuestionId":51684041,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T08:56:57.367","AcceptedAnswerId":51698808.0,"OwnerUserId":8250954.0,"Title":"Stateful LSTM input shape error","Body":"

I am doing a project that handling long sequence multiclass classification.
\nHere is the organization of my data \n
google colab snapshot<\/a>
\nI've segmented the whole sequence into 60 subsequences, each contains 250 samples.
\nThe y_train as below.<\/p>\n\n

<\/pre>\n\n

I have 4 classes for classfication and for this sequence was labeled as '1'(class 1) <\/p>\n\n

And the model defined as below. <\/p>\n\n

<\/pre>\n\n

But when training the model, there's an error that I cannot fully understand.<\/p>\n\n

<\/pre>\n\n

I was wondering why this happened and how to fix it, is something wrong with my input shape or my concepts were errors?
\nPs. In this case, I'm just using only a sequence for testing my model if it could run without errors, and for the next step, I will use a loop to train all the data! Right now I'm stuck on this problem. If somebody could guide me, I would highly appreciate!<\/p>\n","answers":[{"AnswerId":"51698808","CreationDate":"2018-08-05T22:48:52.060","ParentId":null,"OwnerUserId":"1699075","Title":null,"Body":"

Since you have return_sequences=True<\/code> in<\/p>\n\n

model.add(keras.layers.LSTM(250,batch_input_shape=(60,250,1), \nactivation='tanh',return_sequences=True,stateful=True,recurrent_dropout=0.2))<\/code><\/p>\n\n

It returns a 3 dimensional tensor of shape [batch_size, time_step, hidden_dim]<\/code><\/p>\n\n

Now if you want to use a dense layer for such time-series data, you need to use the TimeDistributed<\/a> in Keras the following way,<\/p>\n\n

model.add(TimeDistributed(Dense(4,activation='softmax')))<\/code><\/p>\n"}]} {"QuestionId":51684220,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T09:24:15.147","AcceptedAnswerId":51758333.0,"OwnerUserId":9993397.0,"Title":"google.protobuf.text_format.ParseError: 9:18 : Couldn't parse integer: 03","Body":"

Im using python 3.6 tensorflow 1.5\nim following the link<\/p>\n\n

But got the error:<\/p>\n\n

doe@doe:~\/anaconda3\/envs\/tensorflow\/models\/research\/object_detection$ python3 train.py --logtostderr --train_dir=training\/ --pipeline_config_path=training\/ssd_mobilenet_v1_coco.config\nWARNING:tensorflow:From \/home\/doe\/anaconda3\/lib\/python3.6\/site-packages\/tensorflow\/python\/platform\/app.py:124: main (from main<\/strong>) is deprecated and will be removed in a future version.\nInstructions for updating:\nUse object_detection\/model_main.py.\nTraceback (most recent call last):\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 1500, in _ParseAbstractInteger\n return int(text, 0)\nValueError: invalid literal for int() with base 0: '03'<\/p>\n\n

During handling of the above exception, another exception occurred:<\/p>\n\n

Traceback (most recent call last):\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 1449, in _ConsumeInteger\n result = ParseInteger(tokenizer.token, is_signed=is_signed, is_long=is_long)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 1471, in ParseInteger\n result = _ParseAbstractInteger(text, is_long=is_long)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 1502, in _ParseAbstractInteger\n raise ValueError('Couldn\\'t parse integer: %s' % text)\nValueError: Couldn't parse integer: 03<\/p>\n\n

During handling of the above exception, another exception occurred:<\/p>\n\n

Traceback (most recent call last):\n File \"train.py\", line 184, in \n tf.app.run()\n File \"\/home\/doe\/anaconda3\/lib\/python3.6\/site-packages\/tensorflow\/python\/platform\/app.py\", line 124, in run\n _sys.exit(main(argv))\n File \"\/home\/doe\/anaconda3\/lib\/python3.6\/site-packages\/tensorflow\/python\/util\/deprecation.py\", line 136, in new_func\n return func(*args, **kwargs)\n File \"train.py\", line 93, in main\n FLAGS.pipeline_config_path)\n File \"\/home\/doe\/anaconda3\/envs\/tensorflow\/models\/research\/object_detection\/utils\/config_util.py\", line 94, in get_configs_from_pipeline_file\n text_format.Merge(proto_str, pipeline_config)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 536, in Merge\n descriptor_pool=descriptor_pool)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 590, in MergeLines\n return parser.MergeLines(lines, message)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 623, in MergeLines\n self._ParseOrMerge(lines, message)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 638, in _ParseOrMerge\n self._MergeField(tokenizer, message)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 763, in _MergeField\n merger(tokenizer, message, field)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 837, in _MergeMessageField\n self._MergeField(tokenizer, sub_message)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 763, in _MergeField\n merger(tokenizer, message, field)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 837, in _MergeMessageField\n self._MergeField(tokenizer, sub_message)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 763, in _MergeField\n merger(tokenizer, message, field)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 871, in _MergeScalarField\n value = _ConsumeInt32(tokenizer)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 1362, in _ConsumeInt32\n return _ConsumeInteger(tokenizer, is_signed=True, is_long=False)\n File \"\/home\/doe\/.local\/lib\/python3.6\/site-packages\/google\/protobuf\/text_format.py\", line 1451, in _ConsumeInteger\n raise tokenizer.ParseError(str(e))\ngoogle.protobuf.text_format.ParseError: 9:18 : Couldn't parse integer: 03<\/p>\n","answers":[{"AnswerId":"51758333","CreationDate":"2018-08-09T03:20:08.990","ParentId":null,"OwnerUserId":"10126125","Title":null,"Body":"

I faced a similar problem relating to label_map_path when running on local machine. Solved by removing spaces between lines in the label map pbtxt file. Please check config file as well.<\/p>\n"}]} {"QuestionId":51684475,"AnswerCount":0,"Tags":"","CreationDate":"2018-08-04T10:00:46.087","AcceptedAnswerId":null,"OwnerUserId":5811854.0,"Title":"Keras: split to train and test after adding noise is not working","Body":"

I built a denoising autoencoder for training and testing I had to split dataset(image) to train set and test set. If I split before adding noise its working but if I split after adding nosing its not working. I need to split after adding noise. what is the problem here<\/p>\n\n

<\/pre>\n\n

This is working <\/p>\n\n

<\/pre>\n\n

This is not working<\/p>\n","answers":[]} {"QuestionId":51684594,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T10:16:41.067","AcceptedAnswerId":51684654.0,"OwnerUserId":8410477.0,"Title":"NameError: name 'xrange' is not defined when running tensorflow object detection api","Body":"

I run python object_detection\/builders\/model_builder_test.py with Tensorflow 1.9 of CPU version and Python 3.6 under Ubuntu system, there is NameError: name 'xrange' is not defined, does someone know why this happens and how to deal with it? Thanks. Here is the guide i follow.<\/p>\n\n

https:\/\/github.com\/tensorflow\/models\/blob\/master\/research\/object_detection\/g3doc\/installation.md<\/a><\/p>\n\n

<\/pre>\n","answers":[{"AnswerId":"51684654","CreationDate":"2018-08-04T10:23:46.717","ParentId":null,"OwnerUserId":"7908770","Title":null,"Body":"

xrange()<\/code> was removed from python3<\/code> and was replaced by range()<\/code>. Use range()<\/code> instead (it works exactly the same as xrange()<\/code>).<\/strong><\/p>\n\n

However, if you need to use the range()<\/code> function in python2<\/code> (which you don't in this case), use xrange()<\/code> as range()<\/code> returns a list instead of a generator (as @xdurch0 says in the comments).<\/p>\n"}]} {"QuestionId":51684952,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T11:05:20.053","AcceptedAnswerId":null,"OwnerUserId":9250895.0,"Title":"How to get tf.gradients from keras API model?","Body":"

I would like to know how to get from a model built using the Keras API.<\/p>\n\n

<\/pre>\n\n

First attempt above: my grads are . With my second try below:<\/p>\n\n

<\/pre>\n\n

I get the following error:<\/p>\n\n

<\/pre>\n","answers":[{"AnswerId":"51685828","CreationDate":"2018-08-04T12:59:02.717","ParentId":null,"OwnerUserId":"2099607","Title":null,"Body":"

I think you shouldn't create a new session directly with Tensorflow when using Keras. Instead, it is better to use the session implicitly created by Keras:<\/p>\n\n

import keras.backend as K\n\nsess = K.get_session()\n<\/code><\/pre>\n\n

However, I think in this case you don't need to retrieve the session at all. You can easily use backend functions, like K.gradients()<\/code> and K.function()<\/code>, to achieve your aim.<\/p>\n"}]} {"QuestionId":51685117,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T11:25:51.960","AcceptedAnswerId":51685344.0,"OwnerUserId":8405304.0,"Title":"What kind of shape should I feed into this placeholder in tensorflow?","Body":"

<\/pre>\n\n

[None,] is weird and I don't know what kind of shape of data should I feed in and I get error like this:<\/p>\n\n

<\/pre>\n","answers":[{"AnswerId":"51685344","CreationDate":"2018-08-04T11:58:06.217","ParentId":null,"OwnerUserId":"8037585","Title":null,"Body":"

1-D array is OK, whatever length is.<\/p>\n\n

If length is constrained, None<\/code> should be replaced with a fixed number.\nNormaly, a Tensor has a shape<\/code> attribute and get_shape()<\/code> method to get the static shape.<\/p>\n\n

Details can be found at official tutorial like https:\/\/www.tensorflow.org\/guide\/tensors<\/a> and https:\/\/www.tensorflow.org\/performance\/xla\/shapes<\/a><\/p>\n"}]} {"QuestionId":51685126,"AnswerCount":0,"Tags":"","CreationDate":"2018-08-04T11:26:52.287","AcceptedAnswerId":null,"OwnerUserId":157726.0,"Title":"Variable scopes get a number appended","Body":"

There are some cases where I get a number appended to the variable scope (even if I set )<\/p>\n\n

Let's say I do something like:<\/p>\n\n

<\/pre>\n\n

Why do I see (tensorboard) two groupings (Foo, Foo_1):<\/p>\n\n

\"enter<\/a><\/p>\n\n

I would like A and B to be placed in the same grouping but still keep the two statements separate.<\/p>\n\n

I think a key difference with other existing questions is that I am asking: How do I do this?<\/strong><\/p>\n","answers":[]} {"QuestionId":51685596,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T12:32:47.633","AcceptedAnswerId":51687910.0,"OwnerUserId":4671908.0,"Title":"\"Cannot evaluate tensor using `eval()`: No default session is registered\" while using custom SessionRunHook with Estimator API","Body":"

I'm following this example<\/a> in order to learn how to build a TensorFlow's CNN using Estimator API. In the given example there is a line which would be highly valuable for me if I could obtain those probabilities since I'd like to use them in this small code snippet I wrote:<\/p>\n\n

<\/pre>\n\n

After reading this post<\/a> I wrote my own hook<\/p>\n\n

<\/pre>\n\n

which I'd like to use during the evaluation of the model<\/p>\n\n

<\/pre>\n\n

However, the code crashes with the error<\/p>\n\n

<\/pre>\n\n

Is there any way I could save those probabilities to a human-readable csv file during evaluation or make my code snippet work?<\/p>\n","answers":[{"AnswerId":"51687910","CreationDate":"2018-08-04T17:15:36.697","ParentId":null,"OwnerUserId":"4834515","Title":null,"Body":"

This function eer_eval(y_true, probas)<\/code> is obviously not a tensorflow style. So maybe it's better to let the hook compute y_true<\/code> and probas<\/code>, and give the numpy<\/code> values to eer_eval()<\/code>?<\/p>\n\n

In _EERHook<\/code>:<\/p>\n\n

def before_run(self, run_context):\n    return tf.train.SessionRunArgs((self.labels, self.probas))\n\ndef after_run(self,\n            run_context,  # pylint: disable=unused-argument\n            run_values):\n    results = run_values.results\n    print('labels:', results[0])\n    print('probas:', results[1])\n    # err_eval(results[0], results[1])\n<\/code><\/pre>\n"}]}
{"QuestionId":51685701,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T12:44:13.783","AcceptedAnswerId":null,"OwnerUserId":4582711.0,"Title":"Tensor must be from the same graph as Tensor","Body":"

I was doing some regression and then I tried to add L2 regularization into it. But it showing me following error:<\/p>\n\n

\n

ValueError: Tensor(\"Placeholder:0\", dtype=float32) must be from the\n same graph as Tensor(\"w_hidden:0\", shape=(10, 36), dtype=float32_ref).<\/p>\n<\/blockquote>\n\n

The code looks like as follows:<\/p>\n\n

<\/pre>\n\n

The error shows that I'm using two graphs but I don't know where. <\/p>\n","answers":[{"AnswerId":"56857514","CreationDate":"2019-07-02T17:33:27.810","ParentId":null,"OwnerUserId":"2455494","Title":null,"Body":"

The error message explains that your placeholder for x<\/code> is not in the same graph as the w_hidden<\/code> tensor - this means that we cannot complete an operation using these two tensors (presumably this is thrown when running tf.matmul(weights['hidden'], x)<\/code>)<\/p>\n\n

The reason this has come about is that you have used tf.reset_default_graph()<\/code> after<\/em> you created the reference to weights<\/code> but before<\/em> you created the placeholder x<\/code>. <\/p>\n\n

In order to fix this, you could move the tf.reset_default_graph()<\/code> call before all your operations (or remove it altogether)<\/p>\n"}]} {"QuestionId":51685753,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T12:50:03.353","AcceptedAnswerId":51710366.0,"OwnerUserId":2736559.0,"Title":"AttributeError: 'Image' object has no attribute 'new' occurs when trying to use Pytorchs AlexNet Lighting preprocessing","Body":"

I tried to train my model on using and like preprocessing. I used Fast-ai imagenet training script<\/a> provided script. has support for like preprocessing but for s , we have to implement it ourselves :<\/p>\n\n

<\/pre>\n\n

which is finally used like this :<\/p>\n\n

<\/pre>\n\n

However, the problem is, whenever I run the script I get the:<\/p>\n\n

\n

'AttributeError: 'Image' object has no attribute 'new''<\/p>\n<\/blockquote>\n\n

Which complains about this line:<\/p>\n\n

<\/p>\n\n

I am clueless as to why this is happening. I'm using Pytorch 0.4 by the way.<\/p>\n","answers":[{"AnswerId":"51710366","CreationDate":"2018-08-06T14:50:40.823","ParentId":null,"OwnerUserId":"2736559","Title":null,"Body":"

Thanks to @iacolippo's comment, I finally found the cause! <\/p>\n\n

Unlike the example I wrote here, in my actual script, I had used transforms.ToTensor()<\/code> after the lighting()<\/code> method. Doing so resulted in a PIL<\/code> image being sent as the input for lightining()<\/code>which expects a Tensor and that's why the error occurs.<\/p>\n\n

So basically the snippet I posted in the question is correct and .ToTensor<\/code> has to be used prior to calling Lighting()<\/code>.<\/p>\n"}]} {"QuestionId":51685934,"AnswerCount":2,"Tags":"","CreationDate":"2018-08-04T13:10:39.800","AcceptedAnswerId":51686034.0,"OwnerUserId":2443944.0,"Title":"Calculating tensorflow gradients","Body":"

I am confused by the example in the tensorflow gradient documentation<\/a> for computing the gradient.<\/p>\n\n

<\/pre>\n\n

which gives <\/p>\n\n

I feel like I am really missing something obvious but if is essentially then and therefore . So how does differentiating zero with respect to a and b give you something like .<\/p>\n\n

I believe I am misunderstanding tensorflows structure\/syntax here.<\/p>\n","answers":[{"AnswerId":"51686110","CreationDate":"2018-08-04T13:32:01.057","ParentId":null,"OwnerUserId":"8144434","Title":null,"Body":"

The document describes that the notation you wrote computes the total derivative. You have 2 variables to compute the derivatives: a<\/code> and b<\/code>. So for the derivative for a<\/code>, the derivative of function a+b = a + 2a = 3a<\/code> w.r.t a<\/code> which is 3. For b<\/code>, the derivative of a+b<\/code> w.r.t b<\/code> which is 1. tf.constant(0.)<\/code> means you declared a<\/code> as a constant value. What you may be thinking will happen if you declared a<\/code> as a tf.variable<\/code> instead.<\/p>\n"},{"AnswerId":"51686034","CreationDate":"2018-08-04T13:22:23.847","ParentId":null,"OwnerUserId":"5085211","Title":null,"Body":"

For comparison, consider the real-valued function f<\/em> : R<\/strong> \u2192 R<\/strong> of one real variable, given by f<\/em>(x<\/em>) = 10 x<\/em>. Here, f<\/em>'(x<\/em>) = 10, regardless of the value of x<\/em>, so in particular f<\/em>'(0) = 10.<\/p>\n\n

Similarly, as explained in the tutorial, more or less by definition, the total derivative<\/a> of (a<\/em>, b<\/em>) \u21a6 a<\/em> + b<\/em> for b<\/em>(a<\/em>) = 2 a<\/em> is (3, 1), which is independent of a<\/em>.<\/p>\n\n

For a less trivial example, let us consider<\/p>\n\n

a = tf.constant(5.)\nb = 2 * a\ng = tf.gradients(a**3 + 2*b**2, [a, b])\n\nwith tf.Session() as sess:\n    print(sess.run(g))\n<\/code><\/pre>\n\n

Here, the total derivative with respect to a<\/em> is the derivative of a<\/em> \u21a6 a<\/em>\u00b3 + 2(2 a<\/em>)\u00b2 = a<\/em>\u00b3 + 8 a<\/em>\u00b2 which becomes a<\/em> \u21a6 3 a<\/em>\u00b2 + 16 a<\/em>, while the derivative with respect to b<\/em> is a<\/em> \u21a6 4 b<\/em>(a<\/em>) = 8 a<\/em>. Thus, at a<\/em> = 5, we expect the result to be (3 \u00b7 5\u00b2 + 16 \u00b7 5, 8 \u00b7 5) = (155, 40), and running the code that's exactly what you get.<\/p>\n"}]} {"QuestionId":51686319,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T13:57:52.053","AcceptedAnswerId":null,"OwnerUserId":9453432.0,"Title":"convolutional autoencoder to analyse long 1-D sequences","Body":"

I have a dataset of 1-D vectors each 3001 digits long. I have used a simple convolutional network to perform binary classification on these sequences:<\/p>\n\n

<\/pre>\n\n

The network achieves ~60% accuracy.\nI now would like to create an autoencoder to discover the regular pattern that is distinguishing samples where the label is '1' vs those where it is '0'. i.e. to generate an exemplary sequence- that is representative of the '1' labeled samples.<\/p>\n\n

Based on previous blogs and posts I have tried to put together an autoencoder that can achieve this: <\/p>\n\n

<\/pre>\n\n

This looks as follows:<\/p>\n\n

<\/pre>\n\n

hence everything seems to be going smoothly until I train the netowrk<\/p>\n\n

<\/pre>\n\n

Hence I have tried adding a 'Reshape' layer before the last one.<\/p>\n\n

<\/pre>\n\n

in which case the network looks as follows:<\/p>\n\n

<\/pre>\n\n

But the same error results:<\/p>\n\n

<\/pre>\n\n

My questions are:<\/p>\n\n

1) Is this a feasible way of finding the pattern that is distinguishing samples with label '1' vs '0'?<\/strong><\/p>\n\n

2) how can I make the final layer accept the final output of the last upsampling layer?<\/strong><\/p>\n","answers":[{"AnswerId":"51802635","CreationDate":"2018-08-11T18:34:26.730","ParentId":null,"OwnerUserId":"9453432","Title":null,"Body":"

original = Sequential() \noriginal.add(Conv1D(75,repeat_length,strides=stride, input_shape=shape, activation='relu\u2019,padding=\u2018same\u2019))\noriginal.add(MaxPooling1D(repeat_length))   \noriginal.add(Flatten()) \noriginal.add(Dense(1, activation='sigmoid'))    \noriginal.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy']) \ncalculate_roc(original......)\n\nmod=Sequential()\nmod.add(original.layers[0])\nmod.add(original.layers[1]) \nmod.add(Conv1D(75,window, activation='relu', padding='same'))   \nmod.add(UpSampling1D(window))   \nmod.add(Conv1D(1, 1, activation='sigmoid', padding='same'))\nmod.compile(optimizer='adam', loss='mse', metrics=['accuracy']) \nmod.layers[0].trainable=False   \nmod.layers[1].trainable=False   \nmod.fit(train_X,train_X,epochs=1,batch_size=100)\ndecoded_imgs = mod.predict(test_X)  \nx=decoded_imgs.mean(axis=0) \nplt.plot(x)\n<\/code><\/pre>\n"}]}
{"QuestionId":51686340,"AnswerCount":1,"Tags":"","CreationDate":"2018-08-04T14:00:41.200","AcceptedAnswerId":51686804.0,"OwnerUserId":10128630.0,"Title":"Slice tensor using tf.while_loop","Body":"

I'm trying to slice the tensor into small ones as long as there's still some columns using .
\nNote : I'm using this way because I cannot loop over a value in a placeholder at the graph construction time ( without session ) considered as a tensor and not integer.<\/p>\n\n

<\/pre>\n\n

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

<\/pre>\n\n

However, I get this error : <\/p>\n\n

<\/pre>\n\n

I would like to return the sub tensor everytime<\/p>\n","answers":[{"AnswerId":"51686804","CreationDate":"2018-08-04T15:00:25.943","ParentId":null,"OwnerUserId":"624547","Title":null,"Body":"

There are several problems with your code:<\/p>\n\n