{"QuestionId":45982062,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T12:59:43.023","AcceptedAnswerId":45982613.0,"OwnerUserId":8318339.0,"Title":"How to have Keras model do early-stopping in different fit calls","Body":"

Since the data dimension is big for my task, 32 samples would consume nearly 9% of memory in server, of which total free memory is about 105G. So I have to do consecutive calls to fit() in the loop. And I also want to do early-stopping with the consecutive calls to fit().<\/p>\n\n

However, since the callback methods introduced in Keras documents only apply to one single fit() call. <\/p>\n\n

How can I do early-stopping in this case?<\/p>\n\n

Following is my code snippet:<\/p>\n\n

<\/pre>\n","answers":[{"AnswerId":"45982613","CreationDate":"2017-08-31T13:26:03.187","ParentId":null,"OwnerUserId":"5974433","Title":null,"Body":"
    \n
  1. Use fit_generator<\/code><\/a>: as you have generator - you could use generator traning instead of classical fit<\/code>. This method supports Callbacks<\/code> so you could use keras.callbacks.EarlyStopping<\/code><\/a>.<\/p><\/li>\n

  2. When you cannot use fit_generator<\/code>:\nSo - first of all - you need to use train_on_batch<\/code><\/a> method - as fit<\/code> call resets many model states (e.g. optimizer states).<\/p>\n\n

    train_on_batch<\/code> method returns a loss value, but it doesn't accept callbacks. So you need to implement early stopping<\/code> on your own. You can do it e.g. like this:<\/p>\n\n

    from six import next\n\npatience = 4\nbest_loss = 1e6\nrounds_without_improvement = 0\n\nfor epoch_nb in range(nb_of_epochs):\n    losses_list = list()\n    for batch in range(nb_of_batches):\n        x, y = next(train_data_gen)\n        losses_list.append(model.train_on_batch(x, y))\n    mean_loss = sum(losses_list) \/ len(losses_list)\n\n    if mean_loss < best_loss:\n        best_loss = mean_loss\n        rounds_witout_improvement = 0\n    else:\n        rounds_without_improvement +=1\n\n    if rounds_without_improvement == patience:\n        break\n<\/code><\/pre><\/li>\n<\/ol>\n"}]}
    {"QuestionId":45982445,"AnswerCount":0,"Tags":"","CreationDate":"2017-08-31T13:19:06.120","AcceptedAnswerId":null,"OwnerUserId":4446237.0,"Title":"Keras LSTM time series multi-step predictions has same output for any input","Body":"

    I have a time series of data that has values that represent 'activity' collected by the minute. I set up an LSTM in order to model the data. The LSTM is set to input 300 points, and output the next 60 points. <\/p>\n\n

    I've tweaked the architecture of the LSTM slightly, but the loss usually converges after one epoch and the prediction seems to be the same 60 points for any 300 input. <\/p>\n\n

    Is there anything wrong with my code or general approach?<\/strong><\/p>\n\n

    <\/pre>\n\n

    Images:\n\"enter<\/p>\n\n

    Above is a plot of the latest prediction (of the test set: need to use 360 points, where the first 300 are the input to the LSTM, and the last 60 will be compared to the forecast shown in red). For any point I put in, that same jagged line at around value 200 is outputted. Here is a zoomed in look using a different 300 points:<\/p>\n\n

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

    After removing the model.reset_states() in forecast, the RMSEs reduced to and the graph looks different:<\/p>\n\n

    <\/pre>\n\n

    Images:\n\"no\n\"no<\/p>\n\n

    Edit: Adding in a few more points and the output. The same 60 points are being output for any 300 input.<\/p>\n\n

    \"sample300_1\"\n\"sample300_2\"\n\"sample300_3\"<\/p>\n","answers":[]} {"QuestionId":45982900,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T13:39:22.593","AcceptedAnswerId":45983426.0,"OwnerUserId":7022196.0,"Title":"Two Layer Neural network Tensorflow python","Body":"

    <\/pre>\n\n

    Hi I'm new to tensorflow and neural network. I tried to implement a two-layer neural network for digit recognition. The code works fine when there is only one layer but after I add the second layer the accuracy dropped to 0.11xxxx. What's wrong with my code? Thanks in advance<\/p>\n","answers":[{"AnswerId":"45983426","CreationDate":"2017-08-31T14:04:15.940","ParentId":null,"OwnerUserId":"1896918","Title":null,"Body":"

    You may initialize the weights using random_normal. <\/p>\n\n

    w1 = tf.Variable(tf.random_normal([784, 30]))\n...\nw2 = tf.Variable(tf.random_normal([30, 10]))\n<\/code><\/pre>\n"}]}
    {"QuestionId":45983023,"AnswerCount":0,"Tags":"","CreationDate":"2017-08-31T13:44:39.780","AcceptedAnswerId":null,"OwnerUserId":3142067.0,"Title":"Keras: TensorBoard Callback does not show training metrics","Body":"

    I am trying to visualize loss and custom metrics in TensorBoard during training time using:<\/p>\n\n\n\n

    <\/pre>\n\n

    when I go start TensorBoard with: <\/p>\n\n

    TensorBoard shows no scalars or images. Only the Graph is shown. I can see the metrics in the console as outputs. Is there a update frequency one should adjust? Or does Keras only show the metrics on the validation set?<\/p>\n","answers":[]} {"QuestionId":45984128,"AnswerCount":0,"Tags":"","CreationDate":"2017-08-31T14:37:04.750","AcceptedAnswerId":null,"OwnerUserId":8165066.0,"Title":"What if variable of control_dependencies in cycle?","Body":"

    Look at the code<\/a>, the logic is:<\/p>\n\n

    <\/pre>\n\n

    Look at the annotation, total_loss depend on grad_updates and grad_updates depned on total_loss, what will happen?<\/p>\n","answers":[]} {"QuestionId":45984227,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T14:41:53.670","AcceptedAnswerId":null,"OwnerUserId":3862922.0,"Title":"gcloud jobs submit prediction 'can't decode json' with --data-format=TF_RECORD","Body":"

    I pushed up some test data to gcloud for prediction as a binary tfrecord-file. Running my script I got the error . What do you think I am doing wrong?<\/p>\n\n

    To push a prediction job to gcloud, i use this script:<\/p>\n\n

    <\/pre>\n\n

    has been generated from a numpy array, as so:<\/p>\n\n

    <\/pre>\n\n

    Update (following yxshi):<\/p>\n\n

    I define the following serving function<\/p>\n\n

    <\/pre>\n\n

    .., which I pass to generate_experiment_fn as so:<\/p>\n\n

    <\/pre>\n\n

    (aside: note the dirty patch of InputFnOps)<\/p>\n","answers":[{"AnswerId":"45987766","CreationDate":"2017-08-31T18:16:29.073","ParentId":null,"OwnerUserId":"6896656","Title":null,"Body":"

    It looks like the input is not correctly specified in the inference graph. To use tf_record as input data format, your inference graph must accept strings as the input placeholder. In your case, you should have something like below in your inference code:<\/p>\n\n

     examples = tf.placeholder(tf.string, name='input', shape=(None,))\n with tf.name_scope('inputs'):\n   feature_map = {\n     ch: floats_feature(x)\n     for ch, x in zip(D.channels, np_example)\n   }\n   parsed = tf.parse_example(examples, features=feature_map)\n   f1 = parsed['feature_name_1']\n   f2 = parsed['feature_name_2']\n\n ...\n<\/code><\/pre>\n\n

    A close example is here:\nhttps:\/\/github.com\/GoogleCloudPlatform\/cloudml-samples\/blob\/master\/flowers\/trainer\/model.py#L253<\/a><\/p>\n\n

    Hope it helps.<\/p>\n"}]} {"QuestionId":45984253,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T14:43:30.807","AcceptedAnswerId":46127217.0,"OwnerUserId":8543789.0,"Title":"Keras + CNTK: TensorSliceWithMBLayoutFor","Body":"

    I am running into a few problems while migrating an image segmentation code done with Keras+Tensorflow backend into Keras+CNTK backend. The code runs perfectly with a TF backend but crashes with CNTK.<\/p>\n\n

    The model was inspired from https:\/\/github.com\/jocicmarko\/ultrasound-nerve-segmentation\/blob\/master\/train.py<\/a><\/p>\n\n

    Model inputs are defined as , where . <\/p>\n\n

    The error comes from the line trying to fit the model:\n<\/p>\n\n

    Where , , , are all of shape <\/p>\n\n

    The error I keep getting is the following:<\/p>\n\n

    \n

    Traceback (most recent call last):
    \n File \"TrainNetwork_CNTK.py\", line 188, in
    \n history = model.fit(X_train, Y_train, epochs=trainingEpochs, verbose=2, shuffle=True, validation_data=(X_val, Y_val), callbacks=cb_list)
    \n File \"C:\\Users...\\site-packages\\keras\\engine\\training.py\", line 1430, in fit
    \n initial_epoch=initial_epoch)
    \n File \"C:\\Users...\\site-packages\\keras\\engine\\training.py\", line 1079, in _fit_loop
    \n outs = f(ins_batch)
    \n File \"C:\\Users...\\site-packages\\keras\\backend\\cntk_backend.py\", line 1664, in call<\/strong>
    \n input_dict, self.trainer_output)
    \n File \"C:\\Users...\\site-packages\\cntk\\train\\trainer.py\", line 160, in train_minibatch
    \n output_map, device)
    \n File \"C:\\Users...\\site-packages\\cntk\\cntk_py.py\", line 2769, in train_minibatch
    \n return _cntk_py.Trainer_train_minibatch(self, *args)
    \n RuntimeError: Node 'UserDefinedFunction2738' (UserDefinedV2Function operation): TensorSliceWithMBLayoutFor: FrameRange's dynamic axis is inconsistent with data: <\/p>\n<\/blockquote>\n\n

    There seems to be very little activity on CNTK issues here in SO, so anything to try to shine some light to this issue would be very helpful!<\/p>\n","answers":[{"AnswerId":"46127217","CreationDate":"2017-09-09T04:51:34.430","ParentId":null,"OwnerUserId":"8582892","Title":null,"Body":"

    The reason is the loss function:<\/p>\n\n

    def dice_coef(y_true, y_pred):\n    y_true_f = K.flatten(y_true)\n    y_pred_f = K.flatten(y_pred)\n    intersection = K.sum(y_true_f * y_pred_f)\n    return (2. * intersection + smooth) \/ (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)\n<\/code><\/pre>\n\n

    There is a known issue for cntk_keras' flatten implementation, which cause the batch axis shape not matching for this case. Unfortunately, I haven't got a chance to fix it :(<\/p>\n\n

    But for your case, I think we don't need the flatten here, right? As you are using K.sum(x) with default axis option, which will apply reduce sum to all axis to get a scale, we should get the same result without flatten it. I tried the loss function below and it seems works:<\/p>\n\n

    def dice_coef(y_true, y_pred):\n    intersection = K.sum(y_true * y_pred)\n    return (2. * intersection + smooth) \/ (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)\n<\/code><\/pre>\n"}]}
    {"QuestionId":45984349,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T14:48:17.063","AcceptedAnswerId":45989897.0,"OwnerUserId":8224150.0,"Title":"Dynamically changing the neural network structure","Body":"

    I am trying to implement a NEAT-like algorithm which involves dynamically changing the neural network structure like adding or deleting nodes and connections. I've been using Tensorflow for my previous work in supervised learning. But once a network is defined in Tensorflow , it cannot be changed. Is there any other framework available that provides this functionality ?\nThanks.<\/p>\n","answers":[{"AnswerId":"45989897","CreationDate":"2017-08-31T20:51:47.157","ParentId":null,"OwnerUserId":"569046","Title":null,"Body":"

    Unless it's a framework designed specifically for NEAT, no, not really. The nature of symbolic execution necessarily means that there's a \"create the network\" step followed by a \"run\/train the network\" step. Depending on what kind of frequency you're changing the network topology, though, Tensorflow could definitely still be viable: it will mean, every so often, saving all the parameters, and making a new model -- but this might not be terrible, depending on your parameters.<\/p>\n\n

    If you don't like that, you can sort of hack something together more manually using masking. That is, have some neurons \"masked\" out and removed, or some connnections \"masked\" out. You would do this by having a 0-1 valued mask for all your parameters that you pre-multiply into your parameters before applying. Keep the \"allowed\" connections sparse, but densely-connect everything else together as much as possible. It will, to some degree, give you slowdown since there are some additional computations, but a tf.cond<\/code> call might be able to save you most of the time by only conditionally executing. This can't get you totally free topology evolution, but could be very flexible.<\/p>\n"}]} {"QuestionId":45984543,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T14:58:35.720","AcceptedAnswerId":45984649.0,"OwnerUserId":7580897.0,"Title":"Something went wrong with the input pipeline in tensorflow","Body":"

    I am trying to get a batch of 64 images each has [64,224,224,3] dimensions and labels have [64]. There are 8126 _img_class<\/em> and _img_names<\/em>. However, I am getting an unexpected output. Basically, I am getting nothing and script never terminate when I run it. <\/p>\n\n

    <\/pre>\n\n

    When I set enqueue_many=True<\/em> I am getting the following error.<\/p>\n\n

    <\/pre>\n","answers":[{"AnswerId":"45984649","CreationDate":"2017-08-31T15:03:40.353","ParentId":null,"OwnerUserId":"1896918","Title":null,"Body":"

    You need to start the queue_runners<\/code> after calling the _get_images<\/code> function. As queue<\/code> is defined in that function. <\/p>\n\n

     ...\n images,labels = _get_images(shuffle=True)\n tf.global_variables_initializer().run()\n tf.local_variables_initializer().run()\n # Coordinate the loading of image files.\n coord = tf.train.Coordinator()\n threads = tf.train.start_queue_runners(coord=coord)\n image_tensor,labels = sess.run([images,labels])\n<\/code><\/pre>\n"}]}
    {"QuestionId":45984891,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T15:16:53.610","AcceptedAnswerId":45985718.0,"OwnerUserId":3658166.0,"Title":"How are machine learning models loaded in an app?","Body":"

    I'm just getting into Machine Learning and I've been looking at TensorFlow. So let's say I'm building a desktop app that uses TensorFlow and a trained model. I don't understand how you would eventually bundle the application. Would you somehow save the state of the trained model and include it in the app or would all users have to re-train the model themselves when they first start the application? <\/p>\n","answers":[{"AnswerId":"45985718","CreationDate":"2017-08-31T16:00:39.150","ParentId":null,"OwnerUserId":"1257278","Title":null,"Body":"

    There's an awesome article about this by HBO: How HBO\u2019s Silicon Valley built \u201cNot Hotdog\u201d with mobile TensorFlow, Keras & React Native<\/a>. It delves quite deep into the details, though.<\/p>\n\n

    Machine learning models (like neural networks) are defined by their structure and their parameters\/weights. The structure is hard-coded by you, the weights are learned in training. If you have both, you can recreate the model anywhere and run your predictions or whatever it is you're doing.<\/p>\n\n

    Let's call the apps that your users will run \"clients\". No, clients do not have to relearn the model, unless you specifically want them to. Training is an expensive process that takes a large dataset, memory and processing power. A lot of the cool models you see in action, like the one used on FaceApp or other apps, may take weeks of training on a huge cluster to complete. Not to mention that their dataset is probably many many gigabytes in size.<\/p>\n\n

    For a lot of the Deep Learning models, even the learned weights themselves might be too large, and\/or the processing power needed to even do a single forward pass will be too much for a mobile phone or laptop to handle. That's why many ML apps don't actually ship the model with their app, but rather let the model run on a server. The client then simply sends an input and receives the output a few seconds later. That way you save yourself some trouble, but lose offline capabilities and pay quite a bit for hosting.<\/p>\n\n

    So let's forget about hosting the model for a second and assume you have a small, lightweight model that you want to ship with your app. The simplest way would be to store the weights in a file and then pack it with your app. But of course there are many libraries and tools to help you out there. For a TF example, check out TensorFlow mobile: https:\/\/www.tensorflow.org\/mobile\/<\/a>.<\/p>\n"}]} {"QuestionId":45985289,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T15:36:21.460","AcceptedAnswerId":null,"OwnerUserId":8262535.0,"Title":"Test set accuracy of simple Tensorflow CNN segmentation is low","Body":"

    I modified the https:\/\/www.tensorflow.org\/get_started\/mnist\/pros\/<\/a> to pose it as an image segmentation, rather than a classification problem. The inputs are 60x60 downsampled MRI images (reshaped to [1,3600]) and the outputs are segmentations with 0 to 1 range (thresholded at 0.5 to binary masks). When I run it, I get very reasonable segmentations and a high dice (0.99) in the training set. However, the test set only reaches a dice of 0.8. This sounds like overfitting but the model is super simple: conv layer-max pool-conv layer-dropout-prediction. So, there are only 3 sets of weights and biases, and I am not sure over-complexity is the problem. For regularization I am using dropout rate of 10%. I tried dropout of 50%, and also L1-norm regularization - it hasn't made a difference. I originally used 300 images for the training set and 184 for the test set. Went up to 740-740 and it hasn't made a difference. The test set's dice is insisting on being 0.8, almost exactly. When I run the code pretending training data is test data, I get nearly identical (but not absolutely identical) dices. I would greatly appreciate your suggestions. <\/p>\n\n

    <\/pre>\n\n

    P.S.: My loss function is mean squared differences tf.reduce_mean(tf.reduce_mean(tf.multiply(y_-y_conv,y_-y_conv))), not dice explicitly.<\/p>\n","answers":[{"AnswerId":"45986141","CreationDate":"2017-08-31T16:25:50.013","ParentId":null,"OwnerUserId":"4834515","Title":null,"Body":"

    Overfitting indeed: if you'd like to compare number of training examples and number of parameters, number of parameters is far more than number of examples. However, even overfitting, I don't think dice 0.8 is low.<\/p>\n\n

    Suggestions: you may want to know Fully Convolutional Networks (FCN<\/a>). <\/p>\n"}]} {"QuestionId":45985641,"AnswerCount":2,"Tags":"","CreationDate":"2017-08-31T15:56:19.400","AcceptedAnswerId":46031610.0,"OwnerUserId":5470144.0,"Title":"Can TensorFlow run with multiple CPUs (no GPUs)?","Body":"

    I'm trying to learn distributed TensorFlow. Tried out a piece code as explained here<\/a>:<\/p>\n\n

    <\/pre>\n\n

    Getting the following error:<\/strong><\/p>\n\n

    tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation 'MatMul': Operation was explicitly assigned to \/device:CPU:1 but available devices are [ \/job:localhost\/replica:0\/task:0\/cpu:0 ]. Make sure the device specification refers to a valid device.\n     [[Node: MatMul = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false, _device=\"\/device:CPU:1\"](Placeholder, Variable\/read)]]<\/pre>\n\n

    Meaning that TensorFlow does not recognize CPU:1<\/strong>.<\/p>\n\n

    I'm running on a RedHat server with 40 CPUs ().<\/p>\n\n

    Any ideas?<\/p>\n","answers":[{"AnswerId":"45989838","CreationDate":"2017-08-31T20:47:01.993","ParentId":null,"OwnerUserId":"569046","Title":null,"Body":"

    First, just run it on \"one CPU\", and see if Tensorflow distributes threads to all of the CPUs appropriately. It likely will multithread correctly and you won't have to do anything.<\/p>\n\n

    In the case where it doesn't, you should try launching multiple Tensorflow instances with different CPU affinities, and doing a \"distributed\" system. Tensorflow has distributed services for multiple machines; it should work as well with separate processes on one machine, as long as you correctly set up your files so that they aren't writing to the same locations. You can get start at https:\/\/www.tensorflow.org\/deploy\/distributed<\/a> . You might want to set the CPU affinities so that it's one process per physical CPU, a-la https:\/\/askubuntu.com\/questions\/102258\/how-to-set-cpu-affinity-to-a-process<\/a> <\/p>\n"},{"AnswerId":"46031610","CreationDate":"2017-09-04T06:45:56.480","ParentId":null,"OwnerUserId":"5470144","Title":null,"Body":"

    Following the link<\/a> in the comment:<\/p>\n\n

    Turns out the session should be configured to have device count > 1:<\/p>\n\n

    config = tf.ConfigProto(device_count={\"CPU\": 8})\nwith tf.Session(config=config) as sess:\n   ...\n<\/code><\/pre>\n\n

    Kind of shocking that I missed something so basic, and no one could pinpoint to an error which seems too obvious.<\/p>\n\n

    Not sure if it's a problem with me or the TensorFlow code samples and documentation. Since it's Google, I'll have to say that it's me.<\/p>\n"}]} {"QuestionId":45985682,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T15:58:19.960","AcceptedAnswerId":45985930.0,"OwnerUserId":7970018.0,"Title":"Tensorflow Shape of a vector is (col,)","Body":"

    I have been working through Andrew Ng's course lately, and I figured I might as well try to implement what I've learnt in other languages (which so happens to be Python for me), but I've run into a wall.\nHere's my code:<\/p>\n\n

    <\/pre>\n\n

    And then I train a GradientDescentOptimizer using:<\/p>\n\n

    <\/pre>\n\n

    The error I'm getting is (on that last line):<\/p>\n\n

    <\/pre>\n\n

    Any help would be greatly appreciated. Explanations are even better.<\/p>\n","answers":[{"AnswerId":"45985930","CreationDate":"2017-08-31T16:12:58.307","ParentId":null,"OwnerUserId":"1896918","Title":null,"Body":"

    You need to reshape input x<\/code> to (some_number, 4)<\/code> . Also fix the y<\/code> placeholder<\/p>\n\n

    train_x = [[1, 2, 3, 4], [5, 6, 7, 8]]\ntrain_y = [24, 1680]\n\ntrain_x = np.asarray(train_x)\ntrain_y = np.asarray(train_y)\n\nm = train_x.shape[0]\nn = train_x.shape[1]\n\nX = tf.placeholder(tf.float32, [None, n])\nY = tf.placeholder(tf.float32, [None, 1])\n\nW = tf.Variable(tf.random_normal((n, 1)))\nb = tf.Variable(tf.zeros(1, 1))\n\nmodel = tf.add(tf.matmul(X, W), b)\ncost = tf.reduce_sum(tf.pow(model - Y, 2)) \/ (2 * m)\n\n...\nfor i in range(1000):\n    for x, y in zip(train_x, train_y):\n        x = np.reshape(x, (-1, 4))\n        y = np.reshape(y, (-1, 1))\n        sess.run(optimizer, feed_dict={X: x, Y: y})\n<\/code><\/pre>\n"}]}
    {"QuestionId":45985721,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T16:01:03.130","AcceptedAnswerId":45986355.0,"OwnerUserId":3428338.0,"Title":"Keras Progress Bar generates random batch numbers when using fit_generator","Body":"

    I'm using an MLP in Keras for binary classification of a set of tabular data. \nEach data point has 66 features and I have millions of data points.\nIn order to improve memory efficiency when reading my large training set I started to use fit_generator. I put a simple test code here:<\/p>\n\n

    <\/pre>\n\n

    And here is my generator:<\/p>\n\n

    <\/pre>\n\n

    In my training data the first colomn are the labels and the rest are the features.\nIf I have understood fit_generator correctly, I have to stack data in batches and yield them.\nThe training goes on with no problem, but the progress bar is showing random progress which confuses me. Here I used batch_size = 1 for simplicity. The results are something like this:<\/p>\n\n

    <\/pre>\n\n

    I don't get why it suddenly jumps from 1\/18240 to 38\/18240 and then to 72\/18240 and so on. When I use bigger batch sizes it has the same behavior.\nIs there something wrong with my generator or its just how keras progress bar behaves ?<\/p>\n","answers":[{"AnswerId":"45986355","CreationDate":"2017-08-31T16:37:15.807","ParentId":null,"OwnerUserId":"5974433","Title":null,"Body":"

    As you may see in this<\/a> Keras actually checks how much of time passed since last progbar<\/code> update and it prints it only if it's bigger than a set amount of seconds (which is by default set here<\/a>). If your batch computations lasted less than this margin - then progbar<\/code> is not updated and that's why you have different jumps in number of batches. <\/p>\n"}]} {"QuestionId":45986464,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T16:43:33.537","AcceptedAnswerId":45986837.0,"OwnerUserId":7580897.0,"Title":"How to deal with labels in input pipeline?","Body":"

    I do have an images' names and labels as a list and I want to get a batch of 64 images\/labels. I could get the images in a right way but for labels, its dimension is (64,8126). Each column has the same element 64 times. And rows consists 8126 original label values without getting shuffled.<\/p>\n\n

    I understand the problem that for every image tf.train.shuffle_batch considers the 8126 element label vector. But how would I pass only single element for each image? <\/p>\n\n

    <\/pre>\n","answers":[{"AnswerId":"45986837","CreationDate":"2017-08-31T17:08:14.233","ParentId":null,"OwnerUserId":"1896918","Title":null,"Body":"

    you may use tf.train.slice_input_producer<\/code><\/p>\n\n

    # here _img_class should be a list\nlabels_queue = tf.train.slice_input_producer([_img_class])\n...\nimages_batch, label_batch = tf.train.shuffle_batch(\n        [float_image,labels_queue],\n        batch_size=batch_size,\n        num_threads=num_preprocess_threads,\n        capacity=min_queue_examples + 3 * batch_size,\n        min_after_dequeue=min_queue_examples)\n<\/code><\/pre>\n"}]}
    {"QuestionId":45986578,"AnswerCount":2,"Tags":"","CreationDate":"2017-08-31T16:51:51.067","AcceptedAnswerId":45988076.0,"OwnerUserId":4086968.0,"Title":"Cloud ML Engine distributed training default type for custom tf.estimator","Body":"
      \n
    1. Data-parallel training with synchronous updates.<\/li>\n
    2. Data-parallel training with asynchronous updates.<\/li>\n
    3. Model-parallel training.<\/li>\n<\/ol>\n\n

      The tutorial then goes on to suggest that the code that follows performs data-parallel training with asynchronous updates on Cloud ML Engine<\/em> which behaves as \"If you distribute 10,000 batches among 10 worker nodes, each node works on roughly 1,000 batches.\"<\/p>\n\n

      However, it's not clear what portion of the code actually specifies that this is using data-parallel training with asynchronous updates. Is this simply the default for ML engine if you run it in distributed training mode with a custom tf.estimator?<\/p>\n","answers":[{"AnswerId":"45988076","CreationDate":"2017-08-31T18:39:09.717","ParentId":null,"OwnerUserId":"1399222","Title":null,"Body":"

      The short answer is that tf.estimator<\/code> is currently mostly built around Data-parallel training (2).<\/p>\n\n

      You get Model-parallel training simply by using with tf.device()<\/code> statements in your code.<\/p>\n\n

      You could try to use SyncReplicasOptimizer<\/a> and probably accomplish synchronous training (1). <\/p>\n\n

      All of the above applies generally to tf.estimator<\/code>; nothing is different for CloudML Engine.<\/p>\n"},{"AnswerId":"45987027","CreationDate":"2017-08-31T17:22:43.807","ParentId":null,"OwnerUserId":"4392784","Title":null,"Body":"

      Cloud ML Engine doesn't determine the mode of distributed training. This depends on how the user sets up training using the TensorFlow libraries. In the mnist example linked from the article, the code is using TF Learn classes specifically an Estimator is constructed in model.py<\/a><\/p>\n\n

      That code selects the optimizer which in this case is the AdamOptimizer which uses asynchronous updates. If you wanted to do synchronous updates you'd have to use a different optimizer such as SyncReplicasOptimizer.<\/p>\n\n

      For more information on how to setup synchronous training you can refer to this doc<\/a>.<\/p>\n"}]} {"QuestionId":45986655,"AnswerCount":1,"Tags":"","CreationDate":"2017-08-31T16:56:31.937","AcceptedAnswerId":45986928.0,"OwnerUserId":7595201.0,"Title":"Keras resizing images inside Model - ValueError Not a symbolic tensor","Body":"

      I am starting to work my way into Keras.<\/p>\n\n

      Previously I coded my own generator and Network, but here is the problem I preprocessed my data before passing it to the neural network. Now the task is to do this inside keras. <\/p>\n\n

      My earlier Model looked like this: <\/p>\n\n

      <\/pre>\n\n

      This together with my resizing of the images before passing them into the Network to train it worked perfectly well. So to make it possible for my network to take the images from the game, the resizing needs to happen inside the network. But already with creating an InputLayer from which I could resize the images I get a ValueError<\/strong> \nI did not change much inside the network but it now looks like this:<\/p>\n\n

      <\/pre>\n\n

      The error when calling the function is the following<\/p>\n\n

      <\/pre>\n\n

      I already have an idea resizing the images with the original tensorflow<\/p>\n\n

      <\/pre>\n\n

      So the only real problem would be how to actually get this work with this ValueError, I don't know what to do here. Thank you guys<\/p>\n","answers":[{"AnswerId":"45986928","CreationDate":"2017-08-31T17:14:16.970","ParentId":null,"OwnerUserId":"2097240","Title":null,"Body":"

      Try using Input(img_shape)<\/code> instead of InputLayer(input_shape=(None, 160, 320, 3))<\/code>. <\/p>\n\n

      You cannot pass a \"layer\" to another layer, you must pass a \"tensor\". <\/p>\n\n

      The logic of each line when defining the model is:<\/p>\n\n

      outputTensor = SomeLayer(blablabla)(inputTensor)   \n<\/code><\/pre>\n\n

      InputLayer<\/code> itself is not a tensor, but Input<\/code> is.<\/p>\n\n


      \n\n

      Hints: <\/p>\n\n

    This article<\/a> suggests there are three options for distributed training <\/p>\n\n