{"QuestionId":58156573,"AnswerCount":1,"Tags":"","CreationDate":"2019-09-29T15:19:08.867","AcceptedAnswerId":58156835.0,"OwnerUserId":10490334.0,"Title":"AMD plaidml vs CPU Tensorflow - Unexpected results","Body":"

I am currently running a simple script to train the dataset.<\/p>\n\n

Running the training through my CPU via Tensorflow is giving me and a 3e epoch using the following code:-<\/p>\n\n

<\/pre>\n\n

When I run the dataset through my AMD Pro 580 using the via plaidml setup I get the following results with a 15s epoch, using the following code:-<\/p>\n\n

<\/pre>\n\n

I can see my CPU firing up for the CPU test and my GPU maxing out for the GPU test, but I am very confused as to why the CPU is out performing the GPU by a factor of 5.<\/p>\n\n

Should this be the expected results?<\/p>\n\n

Am I doing something wrong in my code?<\/p>\n","answers":[{"AnswerId":"58156835","CreationDate":"2019-09-29T15:52:02.113","ParentId":null,"OwnerUserId":"306739","Title":null,"Body":"

I think there are two aspects of the observed situation:<\/p>\n\n

    \n
  1. plaidml is not that great in my experience and I\u2019ve had similar results, sadly.<\/li>\n
  2. Moving data to the gpu is slow. In this case, the MNIST data is really small and the time to move the data there outweighs the \u201cbenefit\u201d of paralleling the computation. Actually the TF CPU probably does parallel matrix multiplication as well but it\u2019s much faster as the data is smal and closer to the processing unit.<\/li>\n<\/ol>\n"}]} {"QuestionId":58156676,"AnswerCount":0,"Tags":"","CreationDate":"2019-09-29T15:31:30.127","AcceptedAnswerId":null,"OwnerUserId":11811413.0,"Title":"Modify tensor value","Body":"

    I have a Matrix and i want to set every 0 to a 1. But i get the following error<\/p>\n\n

    \n

    'Tensor' object does not support item assignment<\/p>\n<\/blockquote>\n\n

    How can i change the value of a Tensor the easiest way ?<\/p>\n\n

    <\/pre>\n\n

    i want to turn this [[1, 1, 0], [0, 1, 1], [1, 0, 1]] \ninto this: [[1, 1, 1], [1, 1, 1], [1, 1, 1]]\nwhat would be the easiest solution ?<\/p>\n","answers":[]} {"QuestionId":58157219,"AnswerCount":0,"Tags":"","CreationDate":"2019-09-29T16:41:01.970","AcceptedAnswerId":null,"OwnerUserId":3235916.0,"Title":"Why does this RNN in tensorflow not learn?","Body":"

    I am trying to train an RNN without using the RNN API in tensorflow (2) in Python 3.7, so the code is very basic. Something is going really wrong, but I'm not sure what it is.<\/p>\n\n

    As a reference, I am using a dataset from this tensorflow tutorial<\/a> so I know what the error should roughly converge to. My RNN code is the following. What it is trying to do is use the previous 20 timesteps to predict the value of a series at the 21st timestep. I am training in batches of size 256.<\/p>\n\n

    While there is a decrease in loss over time, the ceiling is approximately 10x what it is if I follow the tutorial approach. Could it be some problem with the backpropagation through time?<\/p>\n\n

    <\/pre>\n","answers":[]}
    {"QuestionId":58157413,"AnswerCount":0,"Tags":"","CreationDate":"2019-09-29T17:06:41.863","AcceptedAnswerId":null,"OwnerUserId":7648650.0,"Title":"Validation loss lower than training loss but worse accuracy","Body":"

    I am training a FFNN for classification and wonder why my validation loss always seems to be to low compared to training loss, as accuracy is also worse for validation than training. <\/p>\n\n

    I found some similar questions leading to the point that it's per se possible to have better performance in validation data set than in the training set, but not in the scenario of lower loss AND lower accuracy.<\/p>\n\n

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

    here's the code i use for training my pytorch NN including the loss calculation:<\/p>\n\n

    <\/pre>\n","answers":[]}
    {"QuestionId":58157457,"AnswerCount":2,"Tags":"","CreationDate":"2019-09-29T17:12:19.507","AcceptedAnswerId":null,"OwnerUserId":8066148.0,"Title":"Keras CONV1D: Error when checking target: expected decoded output to have shape (50, 50) but got array with shape (50, 1)","Body":"

    I have this trouble: Error when checking target: expected decoded_output to have shape (50, 50) but got array with shape (50, 1) With this code, an autoencoder with CONV1D and two output, but the trouble is the reconstruction output (decode_output):<\/p>\n\n

    <\/pre>\n\n

    The input (X) has shape (50000,50) but since Conv1D recives a 3D input I reshape to:<\/p>\n\n

    <\/pre>\n\n

    (50000,50,1)<\/p>\n\n

    And y (the second output) is<\/p>\n\n

    <\/pre>\n\n

    (50000,1)<\/p>\n\n

    And here the model summary<\/p>\n\n

    <\/pre>\n","answers":[{"AnswerId":"58158241","CreationDate":"2019-09-29T18:52:04.403","ParentId":null,"OwnerUserId":"5597718","Title":null,"Body":"

    TAM_VECTOR should be replaced with 1 in the following line. <\/p>\n\n

    Replace <\/p>\n\n

    decoded = Conv1D(TAM_VECTOR, kernel_size=1, activation='relu', name='decode_output')(decoded)\n<\/code><\/pre>\n\n

    with<\/p>\n\n

    decoded = Conv1D(1, kernel_size=1, activation='relu', name='decode_output')(decoded)\n<\/code><\/pre>\n\n

    The decoded output shape should match the input shape of the AutoEncoder (50,1).<\/p>\n\n

    from keras.layers import Conv1D, Flatten, Dense, Input\nfrom keras.models import Model\nimport numpy as np\n\nTAM_VECTOR = 50\ninput_tweet = Input(shape=(TAM_VECTOR,1))\n\nencoded = Conv1D(64, kernel_size=1, activation='relu')(input_tweet)\nencoded = Conv1D(32, kernel_size=1, activation='relu')(encoded)\n\ndecoded = Conv1D(32, kernel_size=1, activation='relu')(encoded)\ndecoded = Conv1D(64, kernel_size=1, activation='relu')(decoded)\ndecoded = Conv1D(1, kernel_size=1, activation='relu', name='decode_output')(decoded)\n\nencoded = Flatten()(encoded)\nsecond_output = Dense(1, activation='linear', name='second_output')(encoded)\n\nautoencoder = Model(inputs=input_tweet, outputs=[decoded, second_output])\n\nautoencoder.compile(optimizer=\"adam\",\n                    loss={'decode_output': 'mse', 'second_output': 'mse'},\n                    loss_weights={'decode_output': 0.001, 'second_output': 0.999},\n                    metrics=[\"mae\"])\n\nautoencoder.fit(np.ones((1,50,1)), [np.ones((1,50,1)), np.ones((1,1))])\n<\/code><\/pre>\n\n

    1\/1 [==============================] - 0s 407ms\/step - loss: 0.9112 - decode_output_loss: 0.9549 - second_output_loss: 0.9111 - decode_output_mean_absolute_error: 0.9772 - second_output_mean_absolute_error: 0.9545<\/p>\n"},{"AnswerId":"58167407","CreationDate":"2019-09-30T11:53:48.777","ParentId":null,"OwnerUserId":"8066148","Title":null,"Body":"

    This are the errros:\nError 1):<\/p>\n\n

    InvalidArgumentError: 2 root error(s) found.\n(0) Invalid argument: You must feed a value for placeholder tensor 'decode_output_sample_weights_32' with dtype float and shape [?]\n[[{{node decode_output_sample_weights_32}}]]\n [[loss_2\/second_output_loss\/Mean_3\/_3217]]\n  (1) Invalid argument: You must feed a value for placeholder tensor 'decode_output_sample_weights_32' with dtype float and shape [?]\n     [[{{node decode_output_sample_weights_32}}]]\n0 successful operations.\n0 derived errors ignored.\n<\/code><\/pre>\n\n

    Error 2):<\/p>\n\n

    InvalidArgumentError: You must feed a value for placeholder tensor 'decode_output_target_17' with dtype float and shape [?,?,?] [[{{node decode_output_target_17}}]]\n<\/code><\/pre>\n\n

    Error 3):<\/p>\n\n

    UnknownError: 2 root error(s) found.\n  (0) Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.\n     [[{{node conv1d_1\/convolution}}]]\n     [[loss\/add\/_157]]\n  (1) Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.\n     [[{{node conv1d_1\/convolution}}]]\n0 successful operations.\n0 derived errors ignored.\n<\/code><\/pre>\n\n

    Error 4):<\/p>\n\n

    UnknownError: 2 root error(s) found.\n  (0) Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.\n     [[{{node conv1d_25\/convolution}}]]\n     [[loss_6\/second_output_loss\/Mean_3\/_1025]]\n  (1) Unknown: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.\n     [[{{node conv1d_25\/convolution}}]]\n0 successful operations.\n0 derived errors ignored.\n<\/code><\/pre>\n"}]}
    {"QuestionId":58157523,"AnswerCount":1,"Tags":"","CreationDate":"2019-09-29T17:20:38.603","AcceptedAnswerId":58158572.0,"OwnerUserId":12139349.0,"Title":"RuntimeError: Expected object of scalar type Long but got scalar type Float for argument #2 'mat2' how to fix it?","Body":"
    <\/pre>\n\n

    error:<\/p>\n\n

    \n

    line 49, in prediction = netSECOND(netFIRST(x))<\/p>\n \n

    line 1371, in linear; output = input.matmul(weight.t())<\/p>\n \n

    RuntimeError: Expected object of scalar type Long but got scalar type\n Float for argument #2 'mat2'<\/p>\n<\/blockquote>\n\n

    I don't really see what I'm doing wrong. I have tried to turn everything in a in every possible way. I don't really get the way typing works for pytorch. Last time I tried something with just one layer and it forced me to use type .\nCould someone explain how the typing is established in pytorch and how to prevent and fix errors like this??\nA lot I mean an awful lot of thanks in advance, this problem really bothers me and I can't seem to fix it no matter what I try.<\/p>\n","answers":[{"AnswerId":"58158572","CreationDate":"2019-09-29T19:39:03.867","ParentId":null,"OwnerUserId":"4080129","Title":null,"Body":"

    The weights are Floats, the inputs are Longs. This is not allowed. In fact, I don't think torch supports anything else than Floats in neural networks.<\/p>\n\n

    If you remove all<\/em> calls to long, and define your input as floats, it will work (it does, I tried).<\/p>\n\n

    (You will then get another unrelated error: you need to sum your loss)<\/p>\n"}]} {"QuestionId":58158006,"AnswerCount":0,"Tags":"","CreationDate":"2019-09-29T18:24:43.493","AcceptedAnswerId":null,"OwnerUserId":10157533.0,"Title":"Strange differences in tf.keras model construction in versions 1.4 and 2.0","Body":"

    I have noticed differences in net topology building in tf.keras in 1.4 and 2.0 versions. I'd like to build net with sharing layers like that:<\/p>\n\n

    <\/pre>\n\n

    And if you check connections between layers (i'm interested in input layers) then you'll get smth like that:<\/p>\n\n

    <\/pre>\n\n

    The question: Is it a bug or a feature, cause I use this stuff for keras models convertion in custom framework format. And i would like to maintain tf2 compatability.<\/p>\n\n

    There is a code for printing connections:<\/p>\n\n

    <\/pre>\n\n

    Thanks in advance!<\/p>\n","answers":[]} {"QuestionId":58158497,"AnswerCount":1,"Tags":"","CreationDate":"2019-09-29T19:28:40.153","AcceptedAnswerId":null,"OwnerUserId":12139694.0,"Title":"What am I doing wrong with the MLP model?","Body":"

    I am developing a time series forecast model using python MLP model. My training sample has 550 events with 9 variables. I have a separate file for testing. I want to forecast at t+1 just one of the 9 variable. Since it is a time series I did 547 portions of 3 events walking one time each timefor X (547, 3, 9). And y (547,) is one variable at t+1.<\/p>\n\n

    <\/pre>\n\n

    ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 547 arrays: <\/p>\n\n

    <\/pre>\n","answers":[{"AnswerId":"58158799","CreationDate":"2019-09-29T20:08:33.823","ParentId":null,"OwnerUserId":"12102280","Title":null,"Body":"

    For a model with a single input you need to give a single array where the first dimension are the samples. You are giving a list. Convert to array (e.g. using np.stack(X)).<\/p>\n"}]} {"QuestionId":58158525,"AnswerCount":0,"Tags":"","CreationDate":"2019-09-29T19:32:45.160","AcceptedAnswerId":null,"OwnerUserId":7886651.0,"Title":"Choosing The right hyperparameters when initial random seed is set","Body":"

    I have a simple model of 3 dense layers. In each layer, I would like to set the number of hidden nodes to be chosen from a list. Hence, for I have: ; for and I have . <\/p>\n\n

    Now since the weight initialization makes a difference in model training, I found that with the same model configurations, I may achieve some times an accuracy or 0.6, sometimes 0.7 and some times 0.725, after every training run (for 30 epochs). My first problem is that I have small dataset.<\/p>\n\n

    As a result, how can I chose between my model configurations if the result varies tremendously between alternative runs to my code, and to the same model configuration?<\/p>\n\n

    In other words, if we assume that the following model configuration is the best (unknown) model config that achieve the highest accuracy on the testing dataset: <\/p>\n\n

    <\/pre>\n\n

    after several runs I get the following results (NOTE: Initial seed is not set in code):<\/p>\n\n

    <\/pre>\n\n

    And if the true second best (unknown) model is:<\/p>\n\n

    <\/pre>\n\n

    after several runs I may get the following results:<\/p>\n\n

    <\/pre>\n\n

    Therefore, in order to correctly evaluate a model, I should train and test the SAME<\/strong> model 5 times. Thus, this will require a huge amount of time.<\/p>\n\n

    But if I set the initial seed, and (train and test) both models only 1 time, I may get and that of the second model: .<\/p>\n\n

    What should I do in this case, how to chose model 1 against model 2? <\/p>\n\n

    Please note that my models are tested in tensorflow and I guess the same problem could be faced with any other DNN framework.<\/p>\n\n

    Any help is much appreciated!!<\/p>\n","answers":[]} {"QuestionId":58158620,"AnswerCount":1,"Tags":"","CreationDate":"2019-09-29T19:44:44.230","AcceptedAnswerId":58170238.0,"OwnerUserId":4547188.0,"Title":"Concatenate input tensor with multiple of neg 1 tensors","Body":"

    Similar Posts:<\/strong> Firstly, these 2 posts are similar if not the same. I tried to implement these in vain. So I'm missing something probably because of my inexperience in Keras.\nsimilar 1<\/a> ,\nsimilar 2<\/a><\/p>\n\n

    The problem:<\/strong>\nI have a data generator to feed data into various models to evaluate model performance and to learn Keras. <\/p>\n\n

    <\/pre>\n\n

    One of the inputs produced by this generator is a tensor \"labels\" of shape=[batch_size, num_letters]. This tensor is the first input to <\/p>\n\n

    <\/pre>\n\n

    similar to image_ocr.py<\/a> line 369.<\/p>\n\n

    The above \"keras example\" creates an RNN\/GRU where each output step of the RNN is one input to the ctc, where there are num_letters steps in the RNN and the labels is of shape (?, num_letters). This worked fine for the first 6 models I have tested so far.<\/p>\n\n

    I am testing a new model where each step of the RNN\/GRU output is \"1 to n\" inputs to the ctc and leaving it to training to optimize the output of each step. So my ctc needs as it's first input a tensor of shape=(?,num_letters*n) but the data generator produces shape=(?, num_letters).<\/p>\n\n

    Side note: The RNN in my model actually produce as a whole shape=(?, n, num_letters). I know how to convert this to (?, n*num_letters).<\/p>\n\n

    Solution 1<\/strong> is a hack, change the generator so that it's unique for this model being tested. This generator will produce tensors of shape=(?,num_letters*n). I don't like this because the generator is also being evaluated and would like it to be constant for each model being evaluated.<\/p>\n\n

    Solution 2<\/strong> is a hack, create a generator that encapsulates the original generator and augments the produced output.<\/p>\n\n

    Solution 3:<\/strong> have the model take an input of shape=(?, num_letters) and concatenate the necessary padding so the shape is (?,num_letters*n) that the ctc wants.<\/p>\n\n

    Here is what I tried:<\/strong><\/p>\n\n

    <\/pre>\n\n

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

      \n
    1. could have made constant shape=[num_letters*(n-1)] and drop the tile, but the same problem of missing batch size remains.<\/li>\n
    2. if I place batch_size as first dimensions, then it still fails complaining of (?, 3) can not be concatenated with (1, 12)<\/li>\n<\/ol>\n\n

      Thank you in advance.<\/p>\n","answers":[{"AnswerId":"58170238","CreationDate":"2019-09-30T14:43:32.050","ParentId":null,"OwnerUserId":"4547188","Title":null,"Body":"

      I found the solution for a model that takes in <\/p>\n\n

      # a batch of size 1, for a tensor of shape =[3]\nd1 = numpy.array([[1, 2, 3]])\n<\/code><\/pre>\n\n

      and produces as output<\/p>\n\n

      out = my_model.predict( [ d1 ] )\nprint(out)\n# [[ 1.  2.  3. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1. -1.]]\n<\/code><\/pre>\n\n

      The big lesson is that keras.layers<\/strong> want as input, the output of other keras.layers<\/strong>. So functionality from keras.backend<\/strong> like tile<\/strong> must be wrapped in keras.layers.Lambda<\/strong> before feeding them as input to keras.layer<\/strong>.<\/p>\n\n

      Thank you to<\/p>\n\n