{
  "id": 294290,
  "title": "Tensorflow - generator",
  "url": "/competitions/cs5785-fall-2021-final/discussion/294290",
  "author_name": "Danish Virani",
  "post_date": "2021-12-09T16:09:24.159000",
  "votes": 1,
  "comment_count": 13,
  "views": 0,
  "content": "<p>When i attempt to fit my tensorflow model with the following code</p>\n<p>model.fit(gen(list_images_train, captions_train, batch_size= 32),<br>\n         use_multiprocessing=True, epochs=10000, verbose=2, workers=4, steps_per_epoch=300, callbacks=[checkpoint, reduce])</p>\n<p>I get a cant pickle a generator error. When I google the error I see people saying when you use a generator in the fitting process you have to turn use_multiprocessing to false. </p>\n<p>But when I do that and try to fit the kernel always dies.</p>\n<p>Does anyone have any idea what I can try to do from here? </p>",
  "messages": [
    {
      "id": 1613506,
      "postDate": "2021-12-10T03:44:06.693Z",
      "content": "<p><a href=\"https://www.kaggle.com/danishvirani\" target=\"_blank\">@danishvirani</a> or anyone else in a similar spot - I recommend taking a look at this simple model that's available out of the box from scikit learn: <a href=\"https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html#sklearn.neural_network.MLPRegressor\" target=\"_blank\">https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html#sklearn.neural_network.MLPRegressor</a></p>\n<p>It definitely isn't as built out or robust as torch/tf, but I think you may find it easier to get started with if you're just looking to do something simple. They call out the limitations and expected uses here: <a href=\"https://scikit-learn.org/stable/modules/neural_networks_supervised.html#neural-networks-supervised\" target=\"_blank\">https://scikit-learn.org/stable/modules/neural_networks_supervised.html#neural-networks-supervised</a></p>",
      "rawMarkdown": "@danishvirani or anyone else in a similar spot - I recommend taking a look at this simple model that's available out of the box from scikit learn: https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html#sklearn.neural_network.MLPRegressor\n\nIt definitely isn't as built out or robust as torch/tf, but I think you may find it easier to get started with if you're just looking to do something simple. They call out the limitations and expected uses here: https://scikit-learn.org/stable/modules/neural_networks_supervised.html#neural-networks-supervised",
      "votes": 1
    },
    {
      "id": 1613619,
      "postDate": "2021-12-10T06:39:08.593Z",
      "content": "<p>Is this tripletNN? If it is, I also found the same source, and my model did start running with our data.</p>\n<p>However, there is a memory leak to this model, I don't know if it is caused by the structure of the model or it's an issue with Keras, but I did try all the methods available to prevent memory leak on Keras, none of them worked).  It will stop training after 12 epochs, and the result is not very well. The model trained with 12 epochs is able to find the similarities among images pretty well, however, it doesn't build a strong connection between text and images.</p>\n<p>I think the leak is caused by the gen function, but I have no idea on how to fix it. When you make it work, I would recommend you keep track of the memory usage after every epoch, if it keeps increasing, then it indicates the memory is leaking.</p>",
      "rawMarkdown": "Is this tripletNN? If it is, I also found the same source, and my model did start running with our data.\n\nHowever, there is a memory leak to this model, I don't know if it is caused by the structure of the model or it's an issue with Keras, but I did try all the methods available to prevent memory leak on Keras, none of them worked).  It will stop training after 12 epochs, and the result is not very well. The model trained with 12 epochs is able to find the similarities among images pretty well, however, it doesn't build a strong connection between text and images.\n\nI think the leak is caused by the gen function, but I have no idea on how to fix it. When you make it work, I would recommend you keep track of the memory usage after every epoch, if it keeps increasing, then it indicates the memory is leaking.",
      "replies": [
        {
          "id": 1614070,
          "postDate": "2021-12-10T15:00:56.853Z",
          "content": "<p>Good tip about the memory leakage. <br>\nI did not encounter memory leakage in the generator function. <br>\nI am not using a generator function anymore.<br>\nIf you want i'd be happy to share the generator function I was using. </p>",
          "rawMarkdown": "Good tip about the memory leakage. \nI did not encounter memory leakage in the generator function. \nI am not using a generator function anymore.\nIf you want i'd be happy to share the generator function I was using. "
        }
      ]
    },
    {
      "id": 1613134,
      "postDate": "2021-12-09T16:40:37.007Z",
      "content": "<p>Thanks James.</p>\n<p>I did manage to fix the GPU issue, i think. <br>\nI changed the environment settings a bit and i can run my tutorial models and the hand written numbers kaggle challenge. </p>\n<p>Now my issue is:</p>\n<pre><code>ValueError: Layer \"model\" expects 3 input(s), but it received 4 input tensors. Inputs received: [&lt;tf.Tensor 'IteratorGetNext:0' shape=(1, 224, 224, 3) dtype=float32&gt;, &lt;tf.Tensor 'IteratorGetNext:1' shape=(1, 70) dtype=int32&gt;, &lt;tf.Tensor 'IteratorGetNext:2' shape=(1, 70) dtype=int32&gt;, &lt;tf.Tensor 'IteratorGetNext:3' shape=(1, 225) dtype=float32&gt;]\n</code></pre>\n<p>I believe i am formatting the inputs into the model fit incorrectly. </p>\n<p>To answer your question:</p>\n<p>My captions get embedded in the pipeline for the modeling. I'd be happy to show you. <br>\nAt this point i couldn't care less about the exam I just want to know what I did wrong/get it to work. </p>",
      "rawMarkdown": "Thanks James.\n\nI did manage to fix the GPU issue, i think. \nI changed the environment settings a bit and i can run my tutorial models and the hand written numbers kaggle challenge. \n\nNow my issue is:\n\n    ValueError: Layer \"model\" expects 3 input(s), but it received 4 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(1, 224, 224, 3) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(1, 70) dtype=int32>, <tf.Tensor 'IteratorGetNext:2' shape=(1, 70) dtype=int32>, <tf.Tensor 'IteratorGetNext:3' shape=(1, 225) dtype=float32>]\n\n\nI believe i am formatting the inputs into the model fit incorrectly. \n\n\n\n\nTo answer your question:\n\nMy captions get embedded in the pipeline for the modeling. I'd be happy to show you. \nAt this point i couldn't care less about the exam I just want to know what I did wrong/get it to work. ",
      "replies": [
        {
          "id": 1613144,
          "postDate": "2021-12-09T16:54:44.230Z",
          "rawMarkdown": "",
          "votes": 1,
          "isDeleted": true
        },
        {
          "id": 1613158,
          "postDate": "2021-12-09T17:15:07.980Z",
          "content": "<p>I did manage to fix the batch size issue. </p>\n<p>I'm pretty sure my input itself is what i expect it to be </p>\n<p>The form it's in is:</p>\n<p>[ [X1, X2, X3], Y]</p>\n<p>The model is defined as</p>\n<p>x = Concatenate(axis=-1)([x1, x2, x3])<br>\nmodel = Model([input_1, input_2, input_3], x)</p>\n<p>But the model was made for the generator which was in the form of a tuple. So maybe the model should look like below. Or maybe my input should look like ( [X1, X2, X3], Y )  *a tuple instead of a list.<br>\nmodel = Model( [[input_1, input_2, input_3], x] )</p>\n<p>I feel this shouldn't be causing the issues but I'll try them. </p>",
          "rawMarkdown": "I did manage to fix the batch size issue. \n\nI'm pretty sure my input itself is what i expect it to be \n\nThe form it's in is:\n\n[ [X1, X2, X3], Y]\n\n\nThe model is defined as\n\nx = Concatenate(axis=-1)([x1, x2, x3])\nmodel = Model([input_1, input_2, input_3], x)\n\nBut the model was made for the generator which was in the form of a tuple. So maybe the model should look like below. Or maybe my input should look like ( [X1, X2, X3], Y )  *a tuple instead of a list.\nmodel = Model( [[input_1, input_2, input_3], x] )\n\nI feel this shouldn't be causing the issues but I'll try them. \n"
        },
        {
          "id": 1613165,
          "postDate": "2021-12-09T17:28:54.443Z",
          "rawMarkdown": "",
          "isDeleted": true
        },
        {
          "id": 1613202,
          "postDate": "2021-12-09T17:57:45.893Z",
          "content": "<p>I am attempting to use keras funcitonal api. </p>\n<p>The code looks like below:</p>\n<p>input_1 = Input(shape=(None, None, 3))<br>\ninput_2 = Input(shape=(None,))<br>\ninput_3 = Input(shape=(None,))<br>\n<em>model stuff</em><br>\nx = Concatenate(axis=-1)([x1, x2, x3])<br>\nmodel = Model( [input_1, input_2, input_3], x)<br>\nmodel.compile(loss=LossFunction, optimizer=Adam(lr))</p>\n<p>Current error (changed 70 to 50):</p>\n<p>ValueError: Layer \"model\" expects 3 input(s), but it received 4 input tensors. Inputs received: [, , , ]</p>\n<p>Yes i'm aware they gave us resnet output. I just wanted to try playing around with it myself and trying out some other image encoders and filters. </p>\n<p>Model: \"model\"</p>\n<hr>\n<h1> Layer (type)                   Output Shape         Param #     Connected to                     </h1>\n<p>input_2 (InputLayer)           [(None, None)]       0           []                               </p>\n<p>input_3 (InputLayer)           [(None, None)]       0           []                               </p>\n<p>embed (Embedding)              (None, None, 50)     123600      ['input_2[0][0]',                <br>\n                                                                  'input_3[0][0]']                </p>\n<p>input_1 (InputLayer)           [(None, None, None,  0           []                               <br>\n                                 3)]                                                              </p>\n<p>spatial_dropout1d (SpatialDrop  (None, None, 50)    0           ['embed[0][0]']                  <br>\n out1D)                                                                                           </p>\n<p>spatial_dropout1d_1 (SpatialDr  (None, None, 50)    0           ['embed[1][0]']                  <br>\n opout1D)                                                                                         </p>\n<p>resnet50 (Functional)          (None, None, None,   23587712    ['input_1[0][0]']                <br>\n                                2048)                                                             </p>\n<p>gru_1 (Bidirectional)          (None, None, 512)    473088      ['spatial_dropout1d[0][0]',      <br>\n                                                                  'spatial_dropout1d_1[0][0]']    </p>\n<p>global_max_pooling2d (GlobalMa  (None, 2048)        0           ['resnet50[0][0]']               <br>\n xPooling2D)                                                                                      </p>\n<p>global_max_pooling1d (GlobalMa  (None, 512)         0           ['gru_1[0][0]']                  <br>\n xPooling1D)                                                                                      </p>\n<p>global_max_pooling1d_1 (Global  (None, 512)         0           ['gru_1[1][0]']                  <br>\n MaxPooling1D)                                                                                    </p>\n<p>dense_image_1 (Dense)          (None, 50)           102450      ['global_max_pooling2d[0][0]']   </p>\n<p>dense_text_1 (Dense)           (None, 50)           25650       ['global_max_pooling1d[0][0]',   <br>\n                                                                  'global_max_pooling1d_1[0][0]'] </p>\n<p>lambda (Lambda)                (None, 50)           0           ['dense_image_1[0][0]',          <br>\n                                                                  'dense_text_1[0][0]',           <br>\n                                                                  'dense_text_1[1][0]']           </p>\n<p>concatenate (Concatenate)      (None, 150)          0           ['lambda[0][0]',                 <br>\n                                                                  'lambda[1][0]',                 <br>\n                                                                  'lambda[2][0]']                 </p>\n<p>I do have a text and a image model that are separate and working. I think the issue comes from just the input. The image/text model i have seperate and all the other tutorials i could find to follow have inputs of (X1,Y1) but I have inputs of ([X1,X2,X3],Y1) and I think that's where the error is coming from. </p>",
          "rawMarkdown": "I am attempting to use keras funcitonal api. \n\nThe code looks like below:\n\ninput_1 = Input(shape=(None, None, 3))\ninput_2 = Input(shape=(None,))\ninput_3 = Input(shape=(None,))\n*model stuff*\nx = Concatenate(axis=-1)([x1, x2, x3])\nmodel = Model( [input_1, input_2, input_3], x)\nmodel.compile(loss=LossFunction, optimizer=Adam(lr))\n\n\n\nCurrent error (changed 70 to 50):\n\nValueError: Layer \"model\" expects 3 input(s), but it received 4 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(32, 224, 224, 3) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(32, 50) dtype=int32>, <tf.Tensor 'IteratorGetNext:2' shape=(32, 50) dtype=int32>, <tf.Tensor 'IteratorGetNext:3' shape=(32, 150) dtype=float32>]\n\nYes i'm aware they gave us resnet output. I just wanted to try playing around with it myself and trying out some other image encoders and filters. \n\n\nModel: \"model\"\n__________________________________________________________________________________________________\n Layer (type)                   Output Shape         Param #     Connected to                     \n==================================================================================================\n input_2 (InputLayer)           [(None, None)]       0           []                               \n                                                                                                  \n input_3 (InputLayer)           [(None, None)]       0           []                               \n                                                                                                  \n embed (Embedding)              (None, None, 50)     123600      ['input_2[0][0]',                \n                                                                  'input_3[0][0]']                \n                                                                                                  \n input_1 (InputLayer)           [(None, None, None,  0           []                               \n                                 3)]                                                              \n                                                                                                  \n spatial_dropout1d (SpatialDrop  (None, None, 50)    0           ['embed[0][0]']                  \n out1D)                                                                                           \n                                                                                                  \n spatial_dropout1d_1 (SpatialDr  (None, None, 50)    0           ['embed[1][0]']                  \n opout1D)                                                                                         \n                                                                                                  \n resnet50 (Functional)          (None, None, None,   23587712    ['input_1[0][0]']                \n                                2048)                                                             \n                                                                                                  \n gru_1 (Bidirectional)          (None, None, 512)    473088      ['spatial_dropout1d[0][0]',      \n                                                                  'spatial_dropout1d_1[0][0]']    \n                                                                                                  \n global_max_pooling2d (GlobalMa  (None, 2048)        0           ['resnet50[0][0]']               \n xPooling2D)                                                                                      \n                                                                                                  \n global_max_pooling1d (GlobalMa  (None, 512)         0           ['gru_1[0][0]']                  \n xPooling1D)                                                                                      \n                                                                                                  \n global_max_pooling1d_1 (Global  (None, 512)         0           ['gru_1[1][0]']                  \n MaxPooling1D)                                                                                    \n                                                                                                  \n dense_image_1 (Dense)          (None, 50)           102450      ['global_max_pooling2d[0][0]']   \n                                                                                                  \n dense_text_1 (Dense)           (None, 50)           25650       ['global_max_pooling1d[0][0]',   \n                                                                  'global_max_pooling1d_1[0][0]'] \n                                                                                                  \n lambda (Lambda)                (None, 50)           0           ['dense_image_1[0][0]',          \n                                                                  'dense_text_1[0][0]',           \n                                                                  'dense_text_1[1][0]']           \n                                                                                                  \n concatenate (Concatenate)      (None, 150)          0           ['lambda[0][0]',                 \n                                                                  'lambda[1][0]',                 \n                                                                  'lambda[2][0]']                 \n                                                                                                  \n\n\n\nI do have a text and a image model that are separate and working. I think the issue comes from just the input. The image/text model i have seperate and all the other tutorials i could find to follow have inputs of (X1,Y1) but I have inputs of ([X1,X2,X3],Y1) and I think that's where the error is coming from. \n\n\n"
        },
        {
          "id": 1613270,
          "postDate": "2021-12-09T19:43:41.970Z",
          "rawMarkdown": "",
          "isDeleted": true
        }
      ]
    },
    {
      "id": 1613121,
      "postDate": "2021-12-09T16:21:17.527Z",
      "content": "<p>When I change the generator to a list and use the following code:</p>\n<p>model.fit(test,use_multiprocessing=True, batch_size = 1,<br>\n                        #validation_data=gen(list_images_val, captions_val, batch_size=BATCH_SIZE), <br>\n                        epochs=10000,<br>\n                        verbose=2, workers=4, steps_per_epoch=300, callbacks=[checkpoint, reduce])<br>\nmodel.save_weights(file_path)</p>\n<p>InternalError: Failed copying input tensor from /job:localhost/replica:0/task:0/device:CPU:0 to /job:localhost/replica:0/task:0/device:GPU:0 in order to run _EagerConst: Dst tensor is not initialized.</p>\n<p>'Dst tensor is not initialized.' error means there was not enough memory <br>\nBecause it ssays GPU:0 i'm assuming it's because it's not detecting my GPU.</p>\n<p>I did try to install cuda to get the gpu working and I do have an RTX 3080 which is cuda compatible.  Any help with this would be greatly appreciated. </p>",
      "rawMarkdown": "When I change the generator to a list and use the following code:\n\nmodel.fit(test,use_multiprocessing=True, batch_size = 1,\n                        #validation_data=gen(list_images_val, captions_val, batch_size=BATCH_SIZE), \n                        epochs=10000,\n                        verbose=2, workers=4, steps_per_epoch=300, callbacks=[checkpoint, reduce])\nmodel.save_weights(file_path)\n\nInternalError: Failed copying input tensor from /job:localhost/replica:0/task:0/device:CPU:0 to /job:localhost/replica:0/task:0/device:GPU:0 in order to run _EagerConst: Dst tensor is not initialized.\n\n'Dst tensor is not initialized.' error means there was not enough memory \nBecause it ssays GPU:0 i'm assuming it's because it's not detecting my GPU.\n\nI did try to install cuda to get the gpu working and I do have an RTX 3080 which is cuda compatible.  Any help with this would be greatly appreciated. "
    },
    {
      "id": 1613113,
      "postDate": "2021-12-09T16:09:24.160Z",
      "content": "<p>When i attempt to fit my tensorflow model with the following code</p>\n<p>model.fit(gen(list_images_train, captions_train, batch_size= 32),<br>\n         use_multiprocessing=True, epochs=10000, verbose=2, workers=4, steps_per_epoch=300, callbacks=[checkpoint, reduce])</p>\n<p>I get a cant pickle a generator error. When I google the error I see people saying when you use a generator in the fitting process you have to turn use_multiprocessing to false. </p>\n<p>But when I do that and try to fit the kernel always dies.</p>\n<p>Does anyone have any idea what I can try to do from here? </p>",
      "rawMarkdown": "When i attempt to fit my tensorflow model with the following code\n\nmodel.fit(gen(list_images_train, captions_train, batch_size= 32),\n         use_multiprocessing=True, epochs=10000, verbose=2, workers=4, steps_per_epoch=300, callbacks=[checkpoint, reduce])\n\nI get a cant pickle a generator error. When I google the error I see people saying when you use a generator in the fitting process you have to turn use_multiprocessing to false. \n\nBut when I do that and try to fit the kernel always dies.\n\nDoes anyone have any idea what I can try to do from here? "
    },
    {
      "id": 1613124,
      "postDate": "2021-12-09T16:23:37.857Z",
      "rawMarkdown": "",
      "votes": 1,
      "isDeleted": true,
      "replies": [
        {
          "id": 1613137,
          "postDate": "2021-12-09T16:44:34.603Z",
          "content": "<p>My captions get embedded in the pipeline for the modeling. I'd be happy to show you.<br>\nAt this point i couldn't care less about the exam I just want to know what I did wrong/get it to work.</p>\n<p>I believe i fixed the GPU issue. </p>\n<p>Thanks for the Cudatoolkit tip. The install guide for tensor flow GPU is seriously not simple. </p>",
          "rawMarkdown": "My captions get embedded in the pipeline for the modeling. I'd be happy to show you.\nAt this point i couldn't care less about the exam I just want to know what I did wrong/get it to work.\n\nI believe i fixed the GPU issue. \n\nThanks for the Cudatoolkit tip. The install guide for tensor flow GPU is seriously not simple. "
        },
        {
          "id": 1613141,
          "postDate": "2021-12-09T16:48:30.167Z",
          "rawMarkdown": "",
          "votes": 1,
          "isDeleted": true
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 1613506,
      "author_name": "Anna462",
      "author_url": "",
      "post_date": "2021-12-10T03:44:06.693000",
      "content": "<p><a href=\"https://www.kaggle.com/danishvirani\" target=\"_blank\">@danishvirani</a> or anyone else in a similar spot - I recommend taking a look at this simple model that's available out of the box from scikit learn: <a href=\"https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html#sklearn.neural_network.MLPRegressor\" target=\"_blank\">https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html#sklearn.neural_network.MLPRegressor</a></p>\n<p>It definitely isn't as built out or robust as torch/tf, but I think you may find it easier to get started with if you're just looking to do something simple. They call out the limitations and expected uses here: <a href=\"https://scikit-learn.org/stable/modules/neural_networks_supervised.html#neural-networks-supervised\" target=\"_blank\">https://scikit-learn.org/stable/modules/neural_networks_supervised.html#neural-networks-supervised</a></p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1613619,
      "author_name": "Caroline Ming",
      "author_url": "",
      "post_date": "2021-12-10T06:39:08.593000",
      "content": "<p>Is this tripletNN? If it is, I also found the same source, and my model did start running with our data.</p>\n<p>However, there is a memory leak to this model, I don't know if it is caused by the structure of the model or it's an issue with Keras, but I did try all the methods available to prevent memory leak on Keras, none of them worked).  It will stop training after 12 epochs, and the result is not very well. The model trained with 12 epochs is able to find the similarities among images pretty well, however, it doesn't build a strong connection between text and images.</p>\n<p>I think the leak is caused by the gen function, but I have no idea on how to fix it. When you make it work, I would recommend you keep track of the memory usage after every epoch, if it keeps increasing, then it indicates the memory is leaking.</p>",
      "votes": 0,
      "replies": [
        {
          "id": 1614070,
          "author_name": "Danish Virani",
          "author_url": "",
          "post_date": "2021-12-10T15:00:56.853000",
          "content": "<p>Good tip about the memory leakage. <br>\nI did not encounter memory leakage in the generator function. <br>\nI am not using a generator function anymore.<br>\nIf you want i'd be happy to share the generator function I was using. </p>",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1613134,
      "author_name": "Danish Virani",
      "author_url": "",
      "post_date": "2021-12-09T16:40:37.007000",
      "content": "<p>Thanks James.</p>\n<p>I did manage to fix the GPU issue, i think. <br>\nI changed the environment settings a bit and i can run my tutorial models and the hand written numbers kaggle challenge. </p>\n<p>Now my issue is:</p>\n<pre><code>ValueError: Layer \"model\" expects 3 input(s), but it received 4 input tensors. Inputs received: [&lt;tf.Tensor 'IteratorGetNext:0' shape=(1, 224, 224, 3) dtype=float32&gt;, &lt;tf.Tensor 'IteratorGetNext:1' shape=(1, 70) dtype=int32&gt;, &lt;tf.Tensor 'IteratorGetNext:2' shape=(1, 70) dtype=int32&gt;, &lt;tf.Tensor 'IteratorGetNext:3' shape=(1, 225) dtype=float32&gt;]\n</code></pre>\n<p>I believe i am formatting the inputs into the model fit incorrectly. </p>\n<p>To answer your question:</p>\n<p>My captions get embedded in the pipeline for the modeling. I'd be happy to show you. <br>\nAt this point i couldn't care less about the exam I just want to know what I did wrong/get it to work. </p>",
      "votes": 0,
      "replies": [
        {
          "id": 1613144,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-12-09T16:54:44.230000",
          "content": "",
          "votes": 1,
          "replies": []
        },
        {
          "id": 1613158,
          "author_name": "Danish Virani",
          "author_url": "",
          "post_date": "2021-12-09T17:15:07.980000",
          "content": "<p>I did manage to fix the batch size issue. </p>\n<p>I'm pretty sure my input itself is what i expect it to be </p>\n<p>The form it's in is:</p>\n<p>[ [X1, X2, X3], Y]</p>\n<p>The model is defined as</p>\n<p>x = Concatenate(axis=-1)([x1, x2, x3])<br>\nmodel = Model([input_1, input_2, input_3], x)</p>\n<p>But the model was made for the generator which was in the form of a tuple. So maybe the model should look like below. Or maybe my input should look like ( [X1, X2, X3], Y )  *a tuple instead of a list.<br>\nmodel = Model( [[input_1, input_2, input_3], x] )</p>\n<p>I feel this shouldn't be causing the issues but I'll try them. </p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1613165,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-12-09T17:28:54.443000",
          "content": "",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1613202,
          "author_name": "Danish Virani",
          "author_url": "",
          "post_date": "2021-12-09T17:57:45.893000",
          "content": "<p>I am attempting to use keras funcitonal api. </p>\n<p>The code looks like below:</p>\n<p>input_1 = Input(shape=(None, None, 3))<br>\ninput_2 = Input(shape=(None,))<br>\ninput_3 = Input(shape=(None,))<br>\n<em>model stuff</em><br>\nx = Concatenate(axis=-1)([x1, x2, x3])<br>\nmodel = Model( [input_1, input_2, input_3], x)<br>\nmodel.compile(loss=LossFunction, optimizer=Adam(lr))</p>\n<p>Current error (changed 70 to 50):</p>\n<p>ValueError: Layer \"model\" expects 3 input(s), but it received 4 input tensors. Inputs received: [, , , ]</p>\n<p>Yes i'm aware they gave us resnet output. I just wanted to try playing around with it myself and trying out some other image encoders and filters. </p>\n<p>Model: \"model\"</p>\n<hr>\n<h1> Layer (type)                   Output Shape         Param #     Connected to                     </h1>\n<p>input_2 (InputLayer)           [(None, None)]       0           []                               </p>\n<p>input_3 (InputLayer)           [(None, None)]       0           []                               </p>\n<p>embed (Embedding)              (None, None, 50)     123600      ['input_2[0][0]',                <br>\n                                                                  'input_3[0][0]']                </p>\n<p>input_1 (InputLayer)           [(None, None, None,  0           []                               <br>\n                                 3)]                                                              </p>\n<p>spatial_dropout1d (SpatialDrop  (None, None, 50)    0           ['embed[0][0]']                  <br>\n out1D)                                                                                           </p>\n<p>spatial_dropout1d_1 (SpatialDr  (None, None, 50)    0           ['embed[1][0]']                  <br>\n opout1D)                                                                                         </p>\n<p>resnet50 (Functional)          (None, None, None,   23587712    ['input_1[0][0]']                <br>\n                                2048)                                                             </p>\n<p>gru_1 (Bidirectional)          (None, None, 512)    473088      ['spatial_dropout1d[0][0]',      <br>\n                                                                  'spatial_dropout1d_1[0][0]']    </p>\n<p>global_max_pooling2d (GlobalMa  (None, 2048)        0           ['resnet50[0][0]']               <br>\n xPooling2D)                                                                                      </p>\n<p>global_max_pooling1d (GlobalMa  (None, 512)         0           ['gru_1[0][0]']                  <br>\n xPooling1D)                                                                                      </p>\n<p>global_max_pooling1d_1 (Global  (None, 512)         0           ['gru_1[1][0]']                  <br>\n MaxPooling1D)                                                                                    </p>\n<p>dense_image_1 (Dense)          (None, 50)           102450      ['global_max_pooling2d[0][0]']   </p>\n<p>dense_text_1 (Dense)           (None, 50)           25650       ['global_max_pooling1d[0][0]',   <br>\n                                                                  'global_max_pooling1d_1[0][0]'] </p>\n<p>lambda (Lambda)                (None, 50)           0           ['dense_image_1[0][0]',          <br>\n                                                                  'dense_text_1[0][0]',           <br>\n                                                                  'dense_text_1[1][0]']           </p>\n<p>concatenate (Concatenate)      (None, 150)          0           ['lambda[0][0]',                 <br>\n                                                                  'lambda[1][0]',                 <br>\n                                                                  'lambda[2][0]']                 </p>\n<p>I do have a text and a image model that are separate and working. I think the issue comes from just the input. The image/text model i have seperate and all the other tutorials i could find to follow have inputs of (X1,Y1) but I have inputs of ([X1,X2,X3],Y1) and I think that's where the error is coming from. </p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1613270,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-12-09T19:43:41.970000",
          "content": "",
          "votes": 0,
          "replies": []
        }
      ]
    },
    {
      "id": 1613121,
      "author_name": "Danish Virani",
      "author_url": "",
      "post_date": "2021-12-09T16:21:17.527000",
      "content": "<p>When I change the generator to a list and use the following code:</p>\n<p>model.fit(test,use_multiprocessing=True, batch_size = 1,<br>\n                        #validation_data=gen(list_images_val, captions_val, batch_size=BATCH_SIZE), <br>\n                        epochs=10000,<br>\n                        verbose=2, workers=4, steps_per_epoch=300, callbacks=[checkpoint, reduce])<br>\nmodel.save_weights(file_path)</p>\n<p>InternalError: Failed copying input tensor from /job:localhost/replica:0/task:0/device:CPU:0 to /job:localhost/replica:0/task:0/device:GPU:0 in order to run _EagerConst: Dst tensor is not initialized.</p>\n<p>'Dst tensor is not initialized.' error means there was not enough memory <br>\nBecause it ssays GPU:0 i'm assuming it's because it's not detecting my GPU.</p>\n<p>I did try to install cuda to get the gpu working and I do have an RTX 3080 which is cuda compatible.  Any help with this would be greatly appreciated. </p>",
      "votes": 0,
      "replies": []
    },
    {
      "id": 1613124,
      "author_name": "",
      "author_url": "",
      "post_date": "2021-12-09T16:23:37.857000",
      "content": "",
      "votes": 1,
      "replies": [
        {
          "id": 1613137,
          "author_name": "Danish Virani",
          "author_url": "",
          "post_date": "2021-12-09T16:44:34.603000",
          "content": "<p>My captions get embedded in the pipeline for the modeling. I'd be happy to show you.<br>\nAt this point i couldn't care less about the exam I just want to know what I did wrong/get it to work.</p>\n<p>I believe i fixed the GPU issue. </p>\n<p>Thanks for the Cudatoolkit tip. The install guide for tensor flow GPU is seriously not simple. </p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1613141,
          "author_name": "",
          "author_url": "",
          "post_date": "2021-12-09T16:48:30.167000",
          "content": "",
          "votes": 1,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1613506": "@danishvirani or anyone else in a similar spot - I recommend taking a look at this simple model that's available out of the box from scikit learn: https://scikit-learn.org/stable/modules/generated/sklearn.neural_network.MLPRegressor.html#sklearn.neural_network.MLPRegressor\n\nIt definitely isn't as built out or robust as torch/tf, but I think you may find it easier to get started with if you're just looking to do something simple. They call out the limitations and expected uses here: https://scikit-learn.org/stable/modules/neural_networks_supervised.html#neural-networks-supervised",
    "1613619": "Is this tripletNN? If it is, I also found the same source, and my model did start running with our data.\n\nHowever, there is a memory leak to this model, I don't know if it is caused by the structure of the model or it's an issue with Keras, but I did try all the methods available to prevent memory leak on Keras, none of them worked).  It will stop training after 12 epochs, and the result is not very well. The model trained with 12 epochs is able to find the similarities among images pretty well, however, it doesn't build a strong connection between text and images.\n\nI think the leak is caused by the gen function, but I have no idea on how to fix it. When you make it work, I would recommend you keep track of the memory usage after every epoch, if it keeps increasing, then it indicates the memory is leaking.",
    "1613134": "Thanks James.\n\nI did manage to fix the GPU issue, i think. \nI changed the environment settings a bit and i can run my tutorial models and the hand written numbers kaggle challenge. \n\nNow my issue is:\n\n    ValueError: Layer \"model\" expects 3 input(s), but it received 4 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(1, 224, 224, 3) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(1, 70) dtype=int32>, <tf.Tensor 'IteratorGetNext:2' shape=(1, 70) dtype=int32>, <tf.Tensor 'IteratorGetNext:3' shape=(1, 225) dtype=float32>]\n\n\nI believe i am formatting the inputs into the model fit incorrectly. \n\n\n\n\nTo answer your question:\n\nMy captions get embedded in the pipeline for the modeling. I'd be happy to show you. \nAt this point i couldn't care less about the exam I just want to know what I did wrong/get it to work. ",
    "1613121": "When I change the generator to a list and use the following code:\n\nmodel.fit(test,use_multiprocessing=True, batch_size = 1,\n                        #validation_data=gen(list_images_val, captions_val, batch_size=BATCH_SIZE), \n                        epochs=10000,\n                        verbose=2, workers=4, steps_per_epoch=300, callbacks=[checkpoint, reduce])\nmodel.save_weights(file_path)\n\nInternalError: Failed copying input tensor from /job:localhost/replica:0/task:0/device:CPU:0 to /job:localhost/replica:0/task:0/device:GPU:0 in order to run _EagerConst: Dst tensor is not initialized.\n\n'Dst tensor is not initialized.' error means there was not enough memory \nBecause it ssays GPU:0 i'm assuming it's because it's not detecting my GPU.\n\nI did try to install cuda to get the gpu working and I do have an RTX 3080 which is cuda compatible.  Any help with this would be greatly appreciated. ",
    "1613113": "When i attempt to fit my tensorflow model with the following code\n\nmodel.fit(gen(list_images_train, captions_train, batch_size= 32),\n         use_multiprocessing=True, epochs=10000, verbose=2, workers=4, steps_per_epoch=300, callbacks=[checkpoint, reduce])\n\nI get a cant pickle a generator error. When I google the error I see people saying when you use a generator in the fitting process you have to turn use_multiprocessing to false. \n\nBut when I do that and try to fit the kernel always dies.\n\nDoes anyone have any idea what I can try to do from here? ",
    "1613124": ""
  }
}