{
  "id": 198452,
  "title": "LSTM input shape for spectrograms",
  "url": "/competitions/predict-volcanic-eruptions-ingv-oe/discussion/198452",
  "author_name": "",
  "post_date": "2020-11-21T09:32:40.643735700Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hello, this is my first ever competion and I'm kinda excited :)</p>\n<p>I'm trying to leverage my signal processing skills into this by trying to train an LSTM layer from  signals spectrograms.</p>\n<p>I'm far less skilled than you in deep learning though. In particular I'm finding very hard to determine the input shape for my model.</p>\n<p>My 3D tensor shape: <code>(n, t, f)</code>, where n is the number of spectrograms, t the time sample and f the frequency samples. Below my initial code:</p>\n<pre><code>inputs = Input(shape=(t, f))\n\nmodel = LSTM(f // 2, \n               activation=\"relu\", \n               return_sequences=True)(inputs)\n# .. more stuff\nmodel..fit(train, train_labels, epochs=50, batch_size=32) #random\n</code></pre>\n<p>But I got:</p>\n<blockquote>\n  <p>InvalidArgumentError:  Incompatible shapes: [32,1] vs. [32,399,101]<br>\n  (399 is t and 101 is f).</p>\n</blockquote>\n<p>I cannot really figure this out. Sorry if this is not the right place to ask, it's my first time in dealing with this networks.</p>\n<p>Cheers :)</p>",
  "messages": [
    {
      "id": "1085931",
      "postDate": "11/21/2020 09:32:40",
      "content": "<p>Hello, this is my first ever competion and I'm kinda excited :)</p>\n<p>I'm trying to leverage my signal processing skills into this by trying to train an LSTM layer from  signals spectrograms.</p>\n<p>I'm far less skilled than you in deep learning though. In particular I'm finding very hard to determine the input shape for my model.</p>\n<p>My 3D tensor shape: <code>(n, t, f)</code>, where n is the number of spectrograms, t the time sample and f the frequency samples. Below my initial code:</p>\n<pre><code>inputs = Input(shape=(t, f))\n\nmodel = LSTM(f // 2, \n               activation=\"relu\", \n               return_sequences=True)(inputs)\n# .. more stuff\nmodel..fit(train, train_labels, epochs=50, batch_size=32) #random\n</code></pre>\n<p>But I got:</p>\n<blockquote>\n  <p>InvalidArgumentError:  Incompatible shapes: [32,1] vs. [32,399,101]<br>\n  (399 is t and 101 is f).</p>\n</blockquote>\n<p>I cannot really figure this out. Sorry if this is not the right place to ask, it's my first time in dealing with this networks.</p>\n<p>Cheers :)</p>",
      "rawMarkdown": "Hello, this is my first ever competion and I'm kinda excited :)\n\nI'm trying to leverage my signal processing skills into this by trying to train an LSTM layer from  signals spectrograms.\n\nI'm far less skilled than you in deep learning though. In particular I'm finding very hard to determine the input shape for my model.\n\nMy 3D tensor shape: `(n, t, f)`, where n is the number of spectrograms, t the time sample and f the frequency samples. Below my initial code:\n\n```\ninputs = Input(shape=(t, f))\n\nmodel = LSTM(f // 2, \n               activation=\"relu\", \n               return_sequences=True)(inputs)\n# .. more stuff\nmodel..fit(train, train_labels, epochs=50, batch_size=32) #random\n```\n\nBut I got:\n> InvalidArgumentError:  Incompatible shapes: [32,1] vs. [32,399,101]\n(399 is t and 101 is f).\n\nI cannot really figure this out. Sorry if this is not the right place to ask, it's my first time in dealing with this networks.\n\nCheers :)",
      "votes": null
    },
    {
      "id": "1088776",
      "postDate": "11/23/2020 23:56:26",
      "content": "<p>You need the outout layer, try with Dense(1, activation='linear') </p>",
      "rawMarkdown": "You need the outout layer, try with Dense(1, activation='linear')",
      "votes": null
    },
    {
      "id": "1090716",
      "postDate": "11/25/2020 14:46:36",
      "content": "<p>Thank you, that was the problem!</p>\n<p>Now after the autoencoder I've got this:</p>\n<pre><code>output = Dense(1, activation='linear')(decoded)\n\nautoencoder = Model(inputs, output)\n\nautoencoder.compile(optimizer='adam',\n                                     loss='mse',  \n                                     metrics=[RootMeanSquaredError()])\n\nautoencoder.fit(train, train_labels_sc, epochs=20, batch_size=32)\n</code></pre>\n<p>The training starts so dimensions are correctly set (hopefully) but it yields None as score:</p>\n<blockquote>\n  <p>Epoch 1/20<br>\n  139/139 [==============================] - 284s 2s/step - loss: nan - root_mean_squared_error: nan</p>\n</blockquote>\n<p>For every epoch. I also tried to rescale the labels without mouch success. Might it be the set loss/metrics?</p>",
      "rawMarkdown": "Thank you, that was the problem!\n\nNow after the autoencoder I've got this:\n```\noutput = Dense(1, activation='linear')(decoded)\n\nautoencoder = Model(inputs, output)\n\nautoencoder.compile(optimizer='adam',\n                                     loss='mse',  \n                                     metrics=[RootMeanSquaredError()])\n\nautoencoder.fit(train, train_labels_sc, epochs=20, batch_size=32)\n```\n\nThe training starts so dimensions are correctly set (hopefully) but it yields None as score:\n\n> Epoch 1/20\n> 139/139 [==============================] - 284s 2s/step - loss: nan - root_mean_squared_error: nan\n\nFor every epoch. I also tried to rescale the labels without mouch success. Might it be the set loss/metrics?",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1088776,
      "author_name": "enric1296",
      "author_url": "",
      "post_date": "11/23/2020 23:56:26",
      "content": "<p>You need the outout layer, try with Dense(1, activation='linear') </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1090716,
      "author_name": "frank95",
      "author_url": "",
      "post_date": "11/25/2020 14:46:36",
      "content": "<p>Thank you, that was the problem!</p>\n<p>Now after the autoencoder I've got this:</p>\n<pre><code>output = Dense(1, activation='linear')(decoded)\n\nautoencoder = Model(inputs, output)\n\nautoencoder.compile(optimizer='adam',\n                                     loss='mse',  \n                                     metrics=[RootMeanSquaredError()])\n\nautoencoder.fit(train, train_labels_sc, epochs=20, batch_size=32)\n</code></pre>\n<p>The training starts so dimensions are correctly set (hopefully) but it yields None as score:</p>\n<blockquote>\n  <p>Epoch 1/20<br>\n  139/139 [==============================] - 284s 2s/step - loss: nan - root_mean_squared_error: nan</p>\n</blockquote>\n<p>For every epoch. I also tried to rescale the labels without mouch success. Might it be the set loss/metrics?</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1085931": "Hello, this is my first ever competion and I'm kinda excited :)\n\nI'm trying to leverage my signal processing skills into this by trying to train an LSTM layer from  signals spectrograms.\n\nI'm far less skilled than you in deep learning though. In particular I'm finding very hard to determine the input shape for my model.\n\nMy 3D tensor shape: `(n, t, f)`, where n is the number of spectrograms, t the time sample and f the frequency samples. Below my initial code:\n\n```\ninputs = Input(shape=(t, f))\n\nmodel = LSTM(f // 2, \n               activation=\"relu\", \n               return_sequences=True)(inputs)\n# .. more stuff\nmodel..fit(train, train_labels, epochs=50, batch_size=32) #random\n```\n\nBut I got:\n> InvalidArgumentError:  Incompatible shapes: [32,1] vs. [32,399,101]\n(399 is t and 101 is f).\n\nI cannot really figure this out. Sorry if this is not the right place to ask, it's my first time in dealing with this networks.\n\nCheers :)",
    "1088776": "You need the outout layer, try with Dense(1, activation='linear')",
    "1090716": "Thank you, that was the problem!\n\nNow after the autoencoder I've got this:\n```\noutput = Dense(1, activation='linear')(decoded)\n\nautoencoder = Model(inputs, output)\n\nautoencoder.compile(optimizer='adam',\n                                     loss='mse',  \n                                     metrics=[RootMeanSquaredError()])\n\nautoencoder.fit(train, train_labels_sc, epochs=20, batch_size=32)\n```\n\nThe training starts so dimensions are correctly set (hopefully) but it yields None as score:\n\n> Epoch 1/20\n> 139/139 [==============================] - 284s 2s/step - loss: nan - root_mean_squared_error: nan\n\nFor every epoch. I also tried to rescale the labels without mouch success. Might it be the set loss/metrics?"
  },
  "source": "meta"
}