{"QuestionId":54989594,"AnswerCount":1,"Tags":"","CreationDate":"2019-03-04T18:43:55.473","AcceptedAnswerId":54992048.0,"OwnerUserId":6197534.0,"Title":"Is it possible to use a Conv2D layer without a model or a running Session?","Body":"

I'm writing an article about Conv2D nets and I want to preview the effect of a Conv2D net on an image, I could get this using a simple keras model and getting the output of first layer (which is the conv), but I wanted a simpler way.<\/p>\n\n

So I did this:<\/p>\n\n

<\/pre>\n\n

The code above works fine and I end up with a tensor .\nThe problem is<\/strong> I couldn't manage to read the data from this tensor. \nis there anyway to do it without having to use the function that requires a running session?<\/p>\n","answers":[{"AnswerId":"54992048","CreationDate":"2019-03-04T21:47:25.513","ParentId":null,"OwnerUserId":"9393102","Title":null,"Body":"

The only way to avoid sessions is to use eager execution:<\/p>\n\n

import tensorflow as tf\ntf.enable_eager_execution()\n<\/code><\/pre>\n\n

Note that you need to enable it before using any TF ops! Now, TF ops are evaluated as they are defined. In your example you can use<\/p>\n\n

layer = Conv2D(10, (3, 3), input_shape=[1080, 1080, 3])\ntensor_in = tf.convert_to_tensor(img, dtype=\"float\")\ntensor_out = layer(tensor_in)\nresult = tensor_out.numpy()\n<\/code><\/pre>\n\n

to get a numpy array for further processing. For more information on eager execution read the basic tutorials<\/a> and\/or the guide<\/a> on the TF website.<\/p>\n"}]} {"QuestionId":54989634,"AnswerCount":0,"Tags":"","CreationDate":"2019-03-04T18:46:21.983","AcceptedAnswerId":null,"OwnerUserId":8314637.0,"Title":"manipulate keras layers with unknown shape","Body":"

I have seq2seq model with attention written in keras. Program should be able to make text translation. <\/p>\n\n

All sentenses in original and translated languages are tokenized and pad to the same maximum length.\nmax_len_input - maximum length of the original sentences, max_len_target - maximum length of the translated sentences<\/p>\n\n

Layers scheme is the following:<\/p>\n\n

<\/pre>\n\n

max_len_input and max_len_target values are defined at the beginning of my programe so everything works fine, \nbut I want to use keras fit_generator method - tokenize and pad not entirely all sentences before layers creation, but after - in fit_generator method \n- then the problem appears - \nI get max_len_input and max_len_target values after keras layers creation. I get them after all my model was initialized.\nAnd this max values changes from batch to batch.<\/p>\n\n

it becomes impossible to use Repeat layer and iterate in for loop over max_len_target. <\/p>\n\n

How to be in this case?<\/p>\n\n

Thank You. <\/p>\n","answers":[]} {"QuestionId":54989687,"AnswerCount":1,"Tags":"","CreationDate":"2019-03-04T18:49:32.380","AcceptedAnswerId":null,"OwnerUserId":9175500.0,"Title":"Apply a different conv1d filter to each input channel","Body":"

I'm working on a Tensorflow model in which a separate 1d convolution should be applied to each of N input channels. I've played around with the various convXd functions. So far I've got something working where each filter is applied to each channel, resulting in N x N outputs, from which I can select a diagonal. But this seems quite inefficient. Any ideas on how to only convolve filter i with input channel i? Thanks for any suggestions!<\/p>\n\n

Code illustrating my best working example:<\/p>\n\n

<\/pre>\n\n

Here's a revised version incorporating the suggestion to use depthwise_conv2d:<\/p>\n\n

<\/pre>\n","answers":[{"AnswerId":"54991926","CreationDate":"2019-03-04T21:37:57.853","ParentId":null,"OwnerUserId":"9393102","Title":null,"Body":"

Sounds like you're looking for depthwise convolution<\/a>. This builds separate filters for each input channel. Unfortunately there does not seem to be a 1D version built-in, however most 1D convolution implementations just use 2D under the hood anyway. You can do something like this:<\/p>\n\n

inp = ...  # assume this is your input, shape batch x time (or width or whatever) x channels\ninp_fake2d = inp[:, tf.newaxis, :, :]  # add a fake second spatial dimension\nfilters = tf.random_normal([1, w, channels, 1])\nout_fake2d = tf.nn.depthwise_conv2d(inp_fake2d, filters, [1,1,1,1], \"valid\")\nout = out_fake2d[:, 0, :, :]\n<\/code><\/pre>\n\n

This adds a \"fake\" second spatial dimension of size 1, then convolves a filter (that is also size 1 in the fake dimension, no nothing is convolved in that direction) and finally removes the fake dimension again. Note that the fourth dimension in the filter tensor (which is also size 1) is the number of filters per input channel. Since you want just one separate filter for each channel, this number is 1.<\/p>\n\n

I hope I understood the question correctly, because I'm a bit confused by the fact that your input X<\/code> is 4D to begin with (usually you would use 1D convolution for 3D inputs). However you might be able to adapt this to your needs.<\/p>\n"}]} {"QuestionId":54989937,"AnswerCount":1,"Tags":"","CreationDate":"2019-03-04T19:05:55.450","AcceptedAnswerId":null,"OwnerUserId":9451356.0,"Title":"maximum number of labels in corss_entropy classification is 300?","Body":"

I found that with sparse_softmax_cross_entropy_with_logits ou can only have at maximum 300 labels?<\/p>\n\n

I found nothing about that. <\/p>\n\n

What if I have more?<\/p>\n\n

EDIT:<\/p>\n\n

If I do not limit to 300 classes, I get evrytime the following trace:<\/p>\n\n

<\/pre>\n\n

Everytime I get this range upt to 300. Why?!<\/p>\n\n

<\/pre>\n","answers":[{"AnswerId":"54991036","CreationDate":"2019-03-04T20:27:47.900","ParentId":null,"OwnerUserId":"648946","Title":null,"Body":"

When I took part in YouTube8M Kaggle competition it had about 5k classes and we used a loss provided by competition organizers, i.e. Google \nHave a look https:\/\/github.com\/mpekalski\/Y8M\/blob\/master\/video_level_code\/losses.py<\/a><\/p>\n"}]} {"QuestionId":54990054,"AnswerCount":1,"Tags":"","CreationDate":"2019-03-04T19:13:05.923","AcceptedAnswerId":54996919.0,"OwnerUserId":1637126.0,"Title":"How do I get Caffe failure stack trace to display?","Body":"

Debugging a Python script which is calling pycaffe which in turn is calling Google protobuf.<\/p>\n\n

When I run the script I get the error:<\/p>\n\n

<\/pre>\n\n

But no failure stack trace. How do I get the stack trace to print?<\/p>\n","answers":[{"AnswerId":"54996919","CreationDate":"2019-03-05T06:48:19.877","ParentId":null,"OwnerUserId":"1714410","Title":null,"Body":"

You might need to change the value of your environment variable GLOG_minloglevel<\/code><\/a><\/p>\n\n

export GLOG_minloglevel=2\n<\/code><\/pre>\n\n

before running caffe.<\/p>\n"}]} {"QuestionId":54990510,"AnswerCount":0,"Tags":"","CreationDate":"2019-03-04T19:47:18.033","AcceptedAnswerId":null,"OwnerUserId":779856.0,"Title":"How to allocate multiple TPUs and adjust code to run on all of them","Body":"

as a part of my R&D I was given access to multiple TPUs, but I can't find documentation how to allocate them together for my training purposes, both node-wise and code-wise. The documentation said but this command allocates only single TPU. And, similar what changes should I add to my code if I want to use multiple TPUs? So far I've used this call to check for TPU, what should be changed (if any) to check if I can access multiple TPUs?<\/p>\n","answers":[]} {"QuestionId":54990568,"AnswerCount":0,"Tags":"","CreationDate":"2019-03-04T19:52:27.133","AcceptedAnswerId":null,"OwnerUserId":6721603.0,"Title":"keras reshape conv1d to conv2d","Body":"

I have a multivariate time-series that has 160 features and 25000 samples, i.e. dimension (25000, 160). I reshape it to 3 dimensions for LSTM\/Conv1D with the following argument to process 10 time-steps at a time:<\/p>\n\n

<\/pre>\n\n

That results in the dimension (25000, 10, 160), which I think stands for 25000 samples, 10 time-steps and 160 features and hence is what I wanted. I can pass this to a Conv1D layer. <\/p>\n\n

However, how to I reshape it the dimension (25000, 10, 160, 2) to fit it into a convolutional layer with 2 channels? I want the Convolutional layer to scan the 10x160 matrix in a 2d way. <\/p>\n","answers":[]} {"QuestionId":54991087,"AnswerCount":1,"Tags":"","CreationDate":"2019-03-04T20:31:04.840","AcceptedAnswerId":null,"OwnerUserId":10880049.0,"Title":"Running tensorflow from another code base","Body":"

I'm hoping someone can help me out here as I feel like I've literally tried everything. <\/p>\n\n

I've followed the tensorflow for poets tutorial for image classification and it works great. I've now built a node application and I'm using a package called python-shell which lets you run python scripts, which also works (I am aware of tensorflow js but I need the performance of py). I've plugged it up so that it can run my tensorflow image classifier and it seems to work...ish. The scripts are definitely executing but when it comes to reading retrained_labels.txt this is where it fails. <\/p>\n\n

The error I get back is: <\/p>\n\n

<\/p>\n\n

From what I've read this is a paths issue and I've already tried to specify absolute paths in my retrain script, but it doesn't solve the issue. However the issue isn't really with tensorflow as that works perfectly as a stand alone script. <\/p>\n\n

I'm at a complete loss so any suggestion is much appreciated. <\/p>\n\n

For some more context the code I need to run is: <\/p>\n\n

<\/p>\n\n

In my node app I'm running this (and I've also played with different script paths, absolute paths, relative paths and every combination I can think of for the last 6 hours)<\/p>\n\n

<\/pre>\n\n

Is there a way I can maybe run a python script which then goes and runs this?<\/p>\n\n

<\/p>\n","answers":[{"AnswerId":"54991424","CreationDate":"2019-03-04T20:56:33.983","ParentId":null,"OwnerUserId":"10880049","Title":null,"Body":"

Finally fixed by hard coding absolute path in image_label.py <\/p>\n"}]} {"QuestionId":54991235,"AnswerCount":0,"Tags":"","CreationDate":"2019-03-04T20:43:20.027","AcceptedAnswerId":null,"OwnerUserId":10555987.0,"Title":"Implementing a Convolution Neural Network from Scratch","Body":"

I have a simple question. I am trying to implement a CNN in pure python to understand how the magic happens.<\/p>\n\n

I have input a set of RGB images, in size.<\/p>\n\n

I made a convolutional filter that converts this vector<\/p>\n\n

to and then I apply a maxpool layer which makes the size .<\/p>\n\n

My question is how do I classify by applying a softmax now?<\/p>\n\n

How can I pass gradients if I apply softmax on the 16 x 16 dimensional vector?<\/p>\n","answers":[]} {"QuestionId":54991874,"AnswerCount":0,"Tags":"","CreationDate":"2019-03-04T21:32:55.340","AcceptedAnswerId":null,"OwnerUserId":10812389.0,"Title":"Deep Q learning, LSTM and Q-values convergence","Body":"

I am implementing a Reinforcement Learning agent that takes action given a time series of prices. The actions are, classically, buy sell or wait. The neural network gets as input one batch at the time, the window size is 96 steps, and I have around 80 features. So the input is something like 1x96x80. The algorithm is online and takes a random sample, every 96 new observations, from a replay memory that saves the last 480 observations (s,a,r,s'). I give a reward signal for each action for each timestep, and where the reward for buy is +1, the one for sell is -1 and so on. Thus I do not have to bother about exploration. I am using the standard way of calculating the loss (as in the Deep Mind original DQN paper), with two networks, one for the estimation of the Q values and the other that acts as a target and gets a soft update every step. <\/p>\n\n

The agent picks at each step the action with the highest estimated Q values - as shown in the graphs below. My issue is with how the Q values behave depending on the architecture of the model. In the standard case I have two dense 'elu' layers, two LSTM layers and a final dense 'linear' layer with 3 units. With this configuration, the Q values fluctuate too heavily, I get a new high max every almost every step and the greedy policy picks different actions too frequently incurring in high transaction costs that destroy the performance (fig 1). In the other case (fig 2) I simply add another dense linear layer of 3 units before the last one, and in this case the Q values evolve much slower, increasing performance as it doesn't incur into high costs, but the tradeoff here is that I get a much less efficient learner which is slow in adapting to new conditions and keeps picking suboptimal actions for longer time, thus harming performance (but still, way better than before). For completeness, I tried with the LSTM returning the whole sequence and updating the gradient on that, and with only the last step. No real difference between the two. <\/p>\n\n

Without a second linear layer<\/a>\nWith a double linear layer<\/a> The blue line is sell (and keep the short position), the orange is wait or close position, and the green is buy (or keep the long position). A position is therefore kept for longer periods if a curve is consistently higher than the others. <\/p>\n\n

Ideally, I would like to find a way to fine tune between these two extremes, however, the second behavior appears only when I add a second dense layer of 3 units before the last one (it can be linear again or tanh), therefore I am not able to get all possibilities in between. Tuning other parameters, like the discount factor, the learning rate or the bias for LSTM does not really help (increasing the bias for LSTM to 5 does help but only in the first iterations, the it goes back to the same behaviour). Also, using GRU instead of LSTM does not change significantly the dynamics of the Q values. <\/p>\n\n

I am at a dead end, any suggestion? I also do not understand why adding a simple linear final layer slows down the estimation of Q values so much. <\/p>\n\n

EDIT: After enough iterations, even the second case (2 linear layers) slowly converge to the case where Q values are way too volatile. So the desired behaviour only last a few tens thousands of steps. <\/p>\n","answers":[]} {"QuestionId":54992535,"AnswerCount":2,"Tags":"","CreationDate":"2019-03-04T22:25:54.063","AcceptedAnswerId":null,"OwnerUserId":5520333.0,"Title":"tf.data.Dataset feedable iterator for training and inference","Body":"

I have a TensorFlow<\/strong> model that uses tf.data.Dataset feedable<\/strong> iterators to switch between training and validation. Both dataset share the same structure, that is they have a features matrix and the corresponding labels vector. In order to use the same model and iterator for inference (no labels vector only featurex matrix) I need to ideally supply a zero labels vector. Is there a more efficient and elegant way to use the dataset API for both training (validation) and inference?<\/p>\n\n

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

<\/pre>\n\n

Features and lables are used inside the model as input placeholders. \nIn order to switch between dataset I need to create one iterator for each dataset:<\/p>\n\n

<\/pre>\n\n

then create the handle<\/p>\n\n

<\/pre>\n\n

And use the to select which dataset to use, for example:<\/p>\n\n

<\/pre>\n\n

Now, what happens if I have inference data with no labels?<\/p>\n\n

<\/pre>\n\n

If I add this iterator it will throw and exception because \"Number of components does not match: expected 2 types but got 1.\"\nAny suggestions?<\/p>\n\n

This post How to use tf.Dataset design in both training and inferring?<\/a> is related to this question, but tf.data.Dataset does not have an unzip method. <\/p>\n\n

What are the best practices for this problem? <\/p>\n","answers":[{"AnswerId":"54992819","CreationDate":"2019-03-04T22:50:00.960","ParentId":null,"OwnerUserId":"4790871","Title":null,"Body":"

If your graph code I assume you are trying to extract a value for labels y<\/code> from the dataset right? At inference time that was probably baked into the tensorflow dependency graph. <\/p>\n\n

You have a few choices here. Probably the easiest solution is to recreate the graph from code (run your build_graph()<\/code> function, then load the weights using something like saver.restore(sess, \"\/tmp\/model.ckpt\")<\/code>). If you do it this way you can re-create the graph without the labels y<\/code>. I assume there are no other dependencies on y<\/code> (sometimes tensorboard summaries add dependencies you need to check too). Your problem should now be solved.<\/p>\n\n

However, now that I've written the above comment (which I'll leave as-is because it's still useful information), I realize you might not even need that. At inference time you should not be using the labels anywhere (again, double check tensorboard summaries). If you don't need y<\/code> then tensorflow should not run any of the operations that use y<\/code>. This should include not trying to extract them from the dataset. Double check that you are not asking tensorflow to use your labels anywhere at inference time.<\/p>\n"},{"AnswerId":"55290367","CreationDate":"2019-03-21T22:47:17.900","ParentId":null,"OwnerUserId":"5520333","Title":null,"Body":"

I think that the first solution proposed by David Parks looks like this, and I think is better than messing with tf.cond in the code.<\/p>\n\n

import tensorflow as tf\nimport numpy as np\n\ndef build_model(features, labels=None, train=False):\n    linear_model = tf.layers.Dense(units=1)\n    y_pred = linear_model(features)\n    if train:\n        loss = tf.losses.mean_squared_error(labels=labels, predictions=y_pred)\n        optimizer = tf.train.GradientDescentOptimizer(1e-4)\n        train = optimizer.minimize(loss)\n        return train, loss\n    else:\n        return y_pred\n\nX_train = np.random.random(100).reshape(-1, 1)\ny_train = np.random.random(100).reshape(-1, 1)\n\ntraining_dataset = tf.data.Dataset.from_tensor_slices((X_train, y_train))\ntraining_dataset = training_dataset.batch(10)\ntraining_dataset = training_dataset.shuffle(20)\nhandle = tf.placeholder(tf.string, shape=[])\niterator = tf.data.Iterator.from_string_handle(handle, training_dataset.output_types, training_dataset.output_shapes)\n\nfeatures, labels = iterator.get_next()\ntraining_iterator = training_dataset.make_one_shot_iterator()\n\ntrain, loss = build_model(features, labels, train=True)\n\nsaver = tf.train.Saver()\ninit = tf.global_variables_initializer()\n\nsess = tf.Session()\ntraining_handle = sess.run(training_iterator.string_handle())\n\nsess.run(init)\nfor i in range(10):\n    _, loss_value = sess.run((train, loss), feed_dict={handle: training_handle})\n    print(loss_value)\n\nsaver.save(sess, \"tmp\/model.ckpt\")\nsess.close()\n\ntf.reset_default_graph()\n\nX_test = np.random.random(10).reshape(-1, 1)\ninference_dataset = tf.data.Dataset.from_tensor_slices(X_test)\ninference_dataset = inference_dataset.batch(5)\n\nhandle = tf.placeholder(tf.string, shape=[])\niterator_inference = tf.data.Iterator.from_string_handle(handle, inference_dataset.output_types, inference_dataset.output_shapes)\n\ninference_iterator = inference_dataset.make_one_shot_iterator()\n\nfeatures_inference = iterator_inference.get_next()\n\ny_pred = build_model(features_inference)\n\nsaver = tf.train.Saver()\nsess = tf.Session()\ninference_handle = sess.run(inference_iterator.string_handle())\nsaver.restore(sess, \"tmp\/model.ckpt\") # Restore variables from disk.\nprint(sess.run(y_pred, feed_dict={handle: inference_handle}))\nsess.close()\n<\/code><\/pre>\n"}]}
{"QuestionId":54992552,"AnswerCount":0,"Tags":"","CreationDate":"2019-03-04T22:27:42.600","AcceptedAnswerId":null,"OwnerUserId":11131331.0,"Title":"I just want to use Deep Style Transfer on Tensorflow GPU, I don't understand this error","Body":"

i am now at the closest i have got to getting it to work on GPU and i have no idea about this error.<\/p>\n\n

I am now using anaconda version 2.7, but in a virtual environment running <\/p>\n\n

python 3.5.6\ni manually installed<\/p>\n\n

<\/pre>\n\n

however i install tensorflow by \nand running conda list gives this result <\/p>\n\n

<\/pre>\n\n

This is the error I receive when trying to run the script<\/p>\n\n

<\/pre>\n\n

The initial guides require 3 other dependacies which i have installed by using the pip3 command inside the activated enviroment but im not sure if Cuda is using these and perhaps this is causing the error? and if so how do i tell cuda to install those .whl's<\/p>\n\n

please help, I do not know what to do.<\/p>\n","answers":[]} {"QuestionId":54993055,"AnswerCount":1,"Tags":"","CreationDate":"2019-03-04T23:14:43.127","AcceptedAnswerId":null,"OwnerUserId":11150891.0,"Title":"TensorFlow Object Detection API: Export process killed","Body":"

I have been working through the TensorFlow Object Detection guide to training an object detector on images of pets TensorFlow Link<\/a> step-by-step, and now have trained files in . However, when I run , the process is killed without error message and no frozen inference file is created.<\/p>\n\n

Run:<\/p>\n\n

<\/pre>\n\n

The last few lines:<\/p>\n\n

<\/pre>\n\n

Does anyone know what might be going wrong?<\/p>\n","answers":[{"AnswerId":"58815664","CreationDate":"2019-11-12T09:29:57.410","ParentId":null,"OwnerUserId":"4093278","Title":null,"Body":"

I had a similar situation when running a TensorFlow Python application in a Docker container.<\/p>\n\n

Situation:<\/strong><\/p>\n\n

The container starts fine, it's only when the classifiers models get loaded (at runtime) that the container starts to struggle. By default, my docker environment imposed a 1Gb upper limit on my Docker container's RAM allocation. Because this was not enough, the OS thrashed and eventually killed the container.<\/p>\n\n

Solution:<\/strong><\/p>\n\n

Depending on your setup, you may be able to change the default RAM allocation of Docker via global settings (in my case, Docker Desktop for Windows). Otherwise, it's possible to start the container using docker run --memory=4g ...<\/code>, which will allocate 4Gb of RAM to your container.<\/p>\n"}]} {"QuestionId":54993293,"AnswerCount":0,"Tags":"","CreationDate":"2019-03-04T23:41:20.650","AcceptedAnswerId":null,"OwnerUserId":11150971.0,"Title":"Custom initialization of weights for object of Conv1D class in PyTorch","Body":"

I am looking into torch.nn.Conv1D class that I would like to initialize with custom weights. <\/p>\n\n

I would like these weights to be \"differentiable\" as they will be derived based on some other parameters.<\/p>\n\n

Here is an example of what I would like to do:<\/p>\n\n

<\/pre>\n\n

This last assignment fails with <\/p>\n\n

\n

TypeError: cannot assign 'torch.DoubleTensor' as parameter 'weight' (torch.nn.Parameter or None expected)<\/p>\n<\/blockquote>\n\n

This seams to be due to m.weight being of the type torch.nn.parameter.Parameter \nWhat would be a good ways of performing the assignment\/initialization of the Conv1D object m? <\/p>\n\n

Instead of that last line I can do this assignment:<\/p>\n\n

<\/pre>\n","answers":[]}
{"QuestionId":54993384,"AnswerCount":1,"Tags":"","CreationDate":"2019-03-04T23:52:32.553","AcceptedAnswerId":null,"OwnerUserId":11133375.0,"Title":"AIY image classification project on ubuntu","Body":"

(venv) nvidia@tegra-ubuntu:~\/tensorflow-for-poets-2$ IMAGE_SIZE=128\n(venv) nvidia@tegra-ubuntu:~\/tensorflow-for-poets-2$ ARCHITECTURE='mobilenet_0.25_128_quantized'\n(venv) nvidia@tegra-ubuntu:~\/tensorflow-for-poets-2$ ARCHITECTURE=\"mobilenet_0.25_128_quantized\"<\/p>\n\n

(venv) nvidia@tegra-ubuntu:~\/tensorflow-for-poets-2$ python -m scripts.retrain \\<\/p>\n\n

I used the code above for training a mobilenet on ubuntu and the training works fine....However, when i try testing on new images, i used the code below.<\/h1>\n\n

(venv) nvidia@tegra-ubuntu:~\/tensorflow-for-poets-2$ python -m scripts.label_image \\<\/p>\n\n

\n
<\/pre>\n<\/blockquote>\n\n

i got this error.<\/h1>\n\n

would really appreciate anyone's help to resolve this. I have been stuck on this since last week....Thanks in advance<\/h1>\n\n

ValueError: Cannot feed value of shape (1, 224, 224, 3) for Tensor 'import\/input:0', which has shape '(1, 128, 128, 3)'<\/p>\n","answers":[{"AnswerId":"55002568","CreationDate":"2019-03-05T12:12:12.080","ParentId":null,"OwnerUserId":"8742334","Title":null,"Body":"

Make sure to adjust the input image resolution in your 'label_image' script.<\/p>\n\n

It might be adjusted to be using the full resolution model be default with an input size of 224x224. This should fix your dimension error. :)<\/p>\n\n

Fix this:<\/p>\n\n

def read_tensor_from_image_file(file_name,\n                            input_height=224,\n                            input_width=224,\n                            input_mean=0,\n                            input_std=255):\n<\/code><\/pre>\n\n

To <\/p>\n\n

def read_tensor_from_image_file(file_name,\n                            input_height=128,\n                            input_width=128,\n                            input_mean=0,\n                            input_std=255):\n<\/code><\/pre>\n"}]}
{"QuestionId":54993855,"AnswerCount":0,"Tags":"","CreationDate":"2019-03-05T00:51:51.583","AcceptedAnswerId":null,"OwnerUserId":10536486.0,"Title":"Tensorflow: batch not shaping correctly for labels","Body":"

I am using an for a network I'm working on. \nWhen fed a single input of size [6, 3169] and an output of [-1, 3169] (casts to input size), it operates properly and predicts. The problem comes when I try and batch those same inputs. With a batch of 100, the input reshapes fine, but the output broadcasts into [600, 3169]. I have tried setting the placeholder specs exactly to the specified input length, but the same error happened. I'm pretty confident that my data is in the correct shape. I run the batch generator and print the output sizes afterward.<\/p>\n\n

Here's my network:<\/p>\n\n

<\/pre>\n\n

my batch generator:<\/p>\n\n

<\/pre>\n\n

and my setup:<\/p>\n\n

<\/pre>\n","answers":[]}
{"QuestionId":54994047,"AnswerCount":2,"Tags":"","CreationDate":"2019-03-05T01:17:00.537","AcceptedAnswerId":null,"OwnerUserId":9743695.0,"Title":"Simple keras model shape issue","Body":"

Starting to learn Keras and TensorFlow. Why is the shape wrong, and how can I fix it?<\/p>\n\n

(temperature input to predict electricity load output)<\/p>\n\n

<\/pre>\n\n

When I print the shape of my arrays, they are both . Why does Keras think the input array is ?<\/p>\n","answers":[{"AnswerId":"54994342","CreationDate":"2019-03-05T01:56:16.220","ParentId":null,"OwnerUserId":"10878733","Title":null,"Body":"

In the line,<\/p>\n\n

load.shape()\n# Output is ( 35064 , )\n<\/code><\/pre>\n\n

The number 35064 shows the number pf samples in the load<\/code> array. The subarrays don't have a definite shape and hence there is a ,<\/code> after 35064. The unknown dimension in Keras is treated as None. So the fix could be,<\/p>\n\n

input_tensor = Input(shape=(None,))\n# Should fix the problem!\n<\/code><\/pre>\n\n
\n

The None dimension can handle any other dimension value. In Keras, the input shape must not include the num_of_samples.<\/p>\n<\/blockquote>\n\n

The model which gave the error would have input shape as ( 35064 , 35064 )<\/p>\n\n

The fixed error would result in the input shape of ( 35064 , None ).<\/p>\n"},{"AnswerId":"54997510","CreationDate":"2019-03-05T07:28:59.160","ParentId":null,"OwnerUserId":"349130","Title":null,"Body":"

The first dimension of your array is always the samples dimension, which is not something you have to put in the input_shape. You can reshape your array to (35064, 1), which means that you have to change your input shape.<\/p>\n\n

Use this:<\/p>\n\n

load = load.reshape((35064, 1))\ntemp = temp.reshape((35064, 1))\n\ninput_tensor = Input(shape=(1,))\n<\/code><\/pre>\n"}]}
{"QuestionId":54994347,"AnswerCount":1,"Tags":"","CreationDate":"2019-03-05T01:57:27.227","AcceptedAnswerId":null,"OwnerUserId":10435242.0,"Title":"How can I improve the accuracy of this keras Neural Network?","Body":"

I'm working with the Heart Disease<\/a> dataset from Machine Learning Repository and I want to improve the accuracy 0.8533 of my NN.<\/p>\n\n

I've tried many things and I got the best results with this settings<\/p>\n\n

<\/pre>\n\n

I've changes the number of nodes to 10 and 5, respectively, changed the optimizer to rmsprop and sgd, changed the kernel_initializer to 'normal' and 'random_uniform'. Even though, the accuracy hasn't improved.<\/p>\n\n

What tips could you guys give me to make the accuracy higher?<\/p>\n","answers":[{"AnswerId":"54999733","CreationDate":"2019-03-05T09:43:15.433","ParentId":null,"OwnerUserId":"8784825","Title":null,"Body":"

If you do not have overfitting try reducing the Dropout rate. Have you studied the dataset? Maybe there are unnecesary features and you can reduce dimensionality with PCA for example. Try using K-Fold with your dataset to get a more realisting accuracy. Have you tried other classifiers? Neural Networks are very cool but sometimes SVM, LR, RandomForest, XGBoost work pretty decently and are easier to tune if you use a Grid with sklearn. Good luck!<\/p>\n"}]} {"QuestionId":54994533,"AnswerCount":0,"Tags":"","CreationDate":"2019-03-05T02:25:19.797","AcceptedAnswerId":null,"OwnerUserId":11151005.0,"Title":"TensorFlow model to TFlite conversion errors","Body":"

I am trying to convert a Keras model (LSTM) into TFlite for deployment on Android in 2 steps.<\/p>\n\n

    \n
  1. To convert Keras to .pb, I have used the code found in this GitHub repo<\/a>.<\/li>\n
  2. To convert Pb to .lite, I am using tflite_converter. It fails both from saved model and the frozen graph, in terminal and in python.<\/li>\n<\/ol>\n\n

    I have tweaked the code and combined it with my model:<\/p>\n\n

    <\/pre>\n\n

    All of the above works (or seems to).<\/p>\n\n

    The errors:\nWith tfile_converter<\/strong> from GraphDef<\/strong>:<\/p>\n\n

    <\/pre>\n\n

    The gist of it is that it repeats \"Converting unsupported operation\" and \"Op node missing\", but I have no idea how to fix it.<\/p>\n\n

    With tflite_convert<\/strong> from saved_model<\/strong>:<\/p>\n\n

    <\/pre>\n\n

    Again, I have investigated this error, but couldn't fix it.<\/p>\n\n

    I have tried other ways of doing keras to .pb conversion to see if this could be the cause of the error, but they also failed in step 2. I have also tried converting it from a GraphDef from session, and with tfile_converter using python (rather than console) - long story short, that didn't work either.<\/p>\n\n

    I am aware of this<\/a> and this<\/a> posts (and many other sad unanswered posts), but they had different errors from mine.<\/p>\n\n

    Thank you! Any help is really appreciated!<\/p>\n","answers":[]} {"QuestionId":54994658,"AnswerCount":2,"Tags":"","CreationDate":"2019-03-05T02:43:35.060","AcceptedAnswerId":54994818.0,"OwnerUserId":11151353.0,"Title":"How does pytorch's nn.Module register submodule?","Body":"

    \n

    When I read the source code(python) of torch.nn.Module , I found the\n attribute has been used in many functions like\n , etc. However, I didn't find any functions\n updating it. So, where will the be updated?\n Furthermore, how does pytorch's register submodule?<\/p>\n<\/blockquote>\n\n

    <\/pre>\n","answers":[{"AnswerId":"57638781","CreationDate":"2019-08-24T14:19:13.720","ParentId":null,"OwnerUserId":"6769366","Title":null,"Body":"

    Add some details to Jiren Jin's answer:<\/p>\n\n

Ok, so I am trying to run a deep style transfer from windows so I can process an image sequence to create a video. I successfully managed to get the CPU version of this<\/a> working, following this guide<\/a> \nI have spent many days on this now, and I have tried a great deal of methods to get this to work I created a previous question with a bunch of unsolved issues and what I have tried\nhere<\/a><\/p>\n\n