{
  "id": 355503,
  "title": "Problem Fitting Data to Model",
  "url": "/competitions/rsna-2022-cervical-spine-fracture-detection/discussion/355503",
  "author_name": "cbarb15",
  "post_date": "2022-09-27T02:53:12.843000",
  "votes": 2,
  "comment_count": 0,
  "views": 0,
  "content": "<p>I am using TensorFlow and I am trying to train a model from the segment data to learn which vertebrae is present in the picture.  I have the dicom image data as an EagorTensor of shape (512, 512, 1) and I used CategoricalEncoding to create a multi-hot encoded labels, which end up being EagorTensors of shape (8,).  However, when I try to call model.fit the code fails.  I tried to write the training loop from scratch using the Tensorflow documentation <a href=\"url\" target=\"_blank\">https://www.tensorflow.org/guide/keras/writing_a_training_loop_from_scratch#using_the_gradienttape_a_first_end-to-end_example</a> and the code fails when I try to pass my data to the model with model(train_ds).  I feel like the shape in my model might be off, but I am not quite sure.  I looked at a couple different tutorials and I copied their code and debugged it to try and get the same shapes as they did with their data.  But I have still had no luck.  I looked at <a href=\"https://towardsdatascience.com/multi-label-image-classification-in-tensorflow-2-0-7d4cf8a4bc72\" target=\"_blank\">https://towardsdatascience.com/multi-label-image-classification-in-tensorflow-2-0-7d4cf8a4bc72</a> and <a href=\"https://medium.com/deep-learning-with-keras/how-to-solve-multi-label-classification-problems-in-deep-learning-with-tensorflow-keras-7fb933243595\" target=\"_blank\">https://medium.com/deep-learning-with-keras/how-to-solve-multi-label-classification-problems-in-deep-learning-with-tensorflow-keras-7fb933243595</a>.   My shapes seem to be the same with the image at, (batch_size, height, width, channels) / (75, 512, 512, 1) and the labels at (batch_size, num_labels)/ (75, 8).  Maybe the problem is in my model and I need my last layer to be of shape (batch_size, num_labels).   Not quite sure.  Any help would be of greatly appreciated.   Here is a link to my notebook on my Github.  <br>\n<a href=\"https://github.com/cbarb15/RSNACervicalSpineFractureDetection\" target=\"_blank\">https://github.com/cbarb15/RSNACervicalSpineFractureDetection</a>  </p>\n<p>**The code in the notebook has a last dense layer with 7, but I have tried it with 8 and get the same results as listed above.  </p>",
  "messages": [
    {
      "id": 1957505,
      "postDate": "2022-09-27T02:53:12.843Z",
      "content": "<p>I am using TensorFlow and I am trying to train a model from the segment data to learn which vertebrae is present in the picture.  I have the dicom image data as an EagorTensor of shape (512, 512, 1) and I used CategoricalEncoding to create a multi-hot encoded labels, which end up being EagorTensors of shape (8,).  However, when I try to call model.fit the code fails.  I tried to write the training loop from scratch using the Tensorflow documentation <a href=\"url\" target=\"_blank\">https://www.tensorflow.org/guide/keras/writing_a_training_loop_from_scratch#using_the_gradienttape_a_first_end-to-end_example</a> and the code fails when I try to pass my data to the model with model(train_ds).  I feel like the shape in my model might be off, but I am not quite sure.  I looked at a couple different tutorials and I copied their code and debugged it to try and get the same shapes as they did with their data.  But I have still had no luck.  I looked at <a href=\"https://towardsdatascience.com/multi-label-image-classification-in-tensorflow-2-0-7d4cf8a4bc72\" target=\"_blank\">https://towardsdatascience.com/multi-label-image-classification-in-tensorflow-2-0-7d4cf8a4bc72</a> and <a href=\"https://medium.com/deep-learning-with-keras/how-to-solve-multi-label-classification-problems-in-deep-learning-with-tensorflow-keras-7fb933243595\" target=\"_blank\">https://medium.com/deep-learning-with-keras/how-to-solve-multi-label-classification-problems-in-deep-learning-with-tensorflow-keras-7fb933243595</a>.   My shapes seem to be the same with the image at, (batch_size, height, width, channels) / (75, 512, 512, 1) and the labels at (batch_size, num_labels)/ (75, 8).  Maybe the problem is in my model and I need my last layer to be of shape (batch_size, num_labels).   Not quite sure.  Any help would be of greatly appreciated.   Here is a link to my notebook on my Github.  <br>\n<a href=\"https://github.com/cbarb15/RSNACervicalSpineFractureDetection\" target=\"_blank\">https://github.com/cbarb15/RSNACervicalSpineFractureDetection</a>  </p>\n<p>**The code in the notebook has a last dense layer with 7, but I have tried it with 8 and get the same results as listed above.  </p>",
      "rawMarkdown": "I am using TensorFlow and I am trying to train a model from the segment data to learn which vertebrae is present in the picture.  I have the dicom image data as an EagorTensor of shape (512, 512, 1) and I used CategoricalEncoding to create a multi-hot encoded labels, which end up being EagorTensors of shape (8,).  However, when I try to call model.fit the code fails.  I tried to write the training loop from scratch using the Tensorflow documentation [https://www.tensorflow.org/guide/keras/writing_a_training_loop_from_scratch#using_the_gradienttape_a_first_end-to-end_example](url) and the code fails when I try to pass my data to the model with model(train_ds).  I feel like the shape in my model might be off, but I am not quite sure.  I looked at a couple different tutorials and I copied their code and debugged it to try and get the same shapes as they did with their data.  But I have still had no luck.  I looked at https://towardsdatascience.com/multi-label-image-classification-in-tensorflow-2-0-7d4cf8a4bc72 and https://medium.com/deep-learning-with-keras/how-to-solve-multi-label-classification-problems-in-deep-learning-with-tensorflow-keras-7fb933243595.   My shapes seem to be the same with the image at, (batch_size, height, width, channels) / (75, 512, 512, 1) and the labels at (batch_size, num_labels)/ (75, 8).  Maybe the problem is in my model and I need my last layer to be of shape (batch_size, num_labels).   Not quite sure.  Any help would be of greatly appreciated.   Here is a link to my notebook on my Github.  \nhttps://github.com/cbarb15/RSNACervicalSpineFractureDetection  \n\n **The code in the notebook has a last dense layer with 7, but I have tried it with 8 and get the same results as listed above.  ",
      "votes": 2
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "1957505": "I am using TensorFlow and I am trying to train a model from the segment data to learn which vertebrae is present in the picture.  I have the dicom image data as an EagorTensor of shape (512, 512, 1) and I used CategoricalEncoding to create a multi-hot encoded labels, which end up being EagorTensors of shape (8,).  However, when I try to call model.fit the code fails.  I tried to write the training loop from scratch using the Tensorflow documentation [https://www.tensorflow.org/guide/keras/writing_a_training_loop_from_scratch#using_the_gradienttape_a_first_end-to-end_example](url) and the code fails when I try to pass my data to the model with model(train_ds).  I feel like the shape in my model might be off, but I am not quite sure.  I looked at a couple different tutorials and I copied their code and debugged it to try and get the same shapes as they did with their data.  But I have still had no luck.  I looked at https://towardsdatascience.com/multi-label-image-classification-in-tensorflow-2-0-7d4cf8a4bc72 and https://medium.com/deep-learning-with-keras/how-to-solve-multi-label-classification-problems-in-deep-learning-with-tensorflow-keras-7fb933243595.   My shapes seem to be the same with the image at, (batch_size, height, width, channels) / (75, 512, 512, 1) and the labels at (batch_size, num_labels)/ (75, 8).  Maybe the problem is in my model and I need my last layer to be of shape (batch_size, num_labels).   Not quite sure.  Any help would be of greatly appreciated.   Here is a link to my notebook on my Github.  \nhttps://github.com/cbarb15/RSNACervicalSpineFractureDetection  \n\n **The code in the notebook has a last dense layer with 7, but I have tried it with 8 and get the same results as listed above.  "
  }
}