{
  "id": 217613,
  "title": "Format of Tfrec files ",
  "url": "/competitions/ranzcr-clip-catheter-line-classification/discussion/217613",
  "author_name": "",
  "post_date": "2021-02-07T14:58:11.354744100Z",
  "votes": 2,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hi,</p>\n<p>I want to use tfrec files but I searched a lot and cant find format of tfrec files anywhere for this competition. Where can I find it?</p>\n<p>Thank you.</p>",
  "messages": [
    {
      "id": "1190210",
      "postDate": "02/07/2021 14:58:11",
      "content": "<p>Hi,</p>\n<p>I want to use tfrec files but I searched a lot and cant find format of tfrec files anywhere for this competition. Where can I find it?</p>\n<p>Thank you.</p>",
      "rawMarkdown": "Hi,\n\nI want to use tfrec files but I searched a lot and cant find format of tfrec files anywhere for this competition. Where can I find it?\n\nThank you.",
      "votes": null
    },
    {
      "id": "1190675",
      "postDate": "02/07/2021 22:25:29",
      "content": "<pre><code>def read_labeled_tfrecord(example):\n    LABELED_TFREC_FORMAT = {\n        \"image\": tf.io.FixedLenFeature([], tf.string),\n        \"StudyInstanceUID\": tf.io.FixedLenFeature([], tf.string),\n        \"ETT - Abnormal\": tf.io.FixedLenFeature([], tf.int64),\n        \"ETT - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"ETT - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Abnormal\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Incompletely Imaged\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"CVC - Abnormal\": tf.io.FixedLenFeature([], tf.int64), \n        \"CVC - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"CVC - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"Swan Ganz Catheter Present\": tf.io.FixedLenFeature([], tf.int64),\n    }\n    example = tf.io.parse_single_example(example, LABELED_TFREC_FORMAT)\n    image = decode_image(example['image'])\n    label = [tf.cast(example[\"ETT - Abnormal\"], tf.int32),\n             tf.cast(example[\"ETT - Borderline\"], tf.int32),\n             tf.cast(example[\"ETT - Normal\"], tf.int32),\n             tf.cast(example[\"NGT - Abnormal\"], tf.int32),\n             tf.cast(example[\"NGT - Borderline\"], tf.int32),\n             tf.cast(example[\"NGT - Incompletely Imaged\"], tf.int32),\n             tf.cast(example[\"NGT - Normal\"], tf.int32),\n             tf.cast(example[\"CVC - Abnormal\"], tf.int32),\n             tf.cast(example[\"CVC - Borderline\"], tf.int32),\n             tf.cast(example[\"CVC - Normal\"], tf.int32),\n             tf.cast(example[\"Swan Ganz Catheter Present\"], tf.int32)]\n    return image, label\n</code></pre>",
      "rawMarkdown": "```\ndef read_labeled_tfrecord(example):\n    LABELED_TFREC_FORMAT = {\n        \"image\": tf.io.FixedLenFeature([], tf.string),\n        \"StudyInstanceUID\": tf.io.FixedLenFeature([], tf.string),\n        \"ETT - Abnormal\": tf.io.FixedLenFeature([], tf.int64),\n        \"ETT - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"ETT - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Abnormal\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Incompletely Imaged\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"CVC - Abnormal\": tf.io.FixedLenFeature([], tf.int64), \n        \"CVC - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"CVC - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"Swan Ganz Catheter Present\": tf.io.FixedLenFeature([], tf.int64),\n    }\n    example = tf.io.parse_single_example(example, LABELED_TFREC_FORMAT)\n    image = decode_image(example['image'])\n    label = [tf.cast(example[\"ETT - Abnormal\"], tf.int32),\n             tf.cast(example[\"ETT - Borderline\"], tf.int32),\n             tf.cast(example[\"ETT - Normal\"], tf.int32),\n             tf.cast(example[\"NGT - Abnormal\"], tf.int32),\n             tf.cast(example[\"NGT - Borderline\"], tf.int32),\n             tf.cast(example[\"NGT - Incompletely Imaged\"], tf.int32),\n             tf.cast(example[\"NGT - Normal\"], tf.int32),\n             tf.cast(example[\"CVC - Abnormal\"], tf.int32),\n             tf.cast(example[\"CVC - Borderline\"], tf.int32),\n             tf.cast(example[\"CVC - Normal\"], tf.int32),\n             tf.cast(example[\"Swan Ganz Catheter Present\"], tf.int32)]\n    return image, label\n```",
      "votes": null
    },
    {
      "id": "1194087",
      "postDate": "02/10/2021 03:45:15",
      "content": "<p>next time you can run something like this </p>\n<pre><code>import tensorflow as tf\nraw_dataset = tf.data.TFRecordDataset(GCS_DS_PATH + '/train_tfrecords/05-1881.tfrec')\nfor raw_record in raw_dataset.take(1):\n  example = tf.train.Example()\n  example.ParseFromString(raw_record.numpy())\n  print(example)\n</code></pre>\n<p>to dump out all the features </p>",
      "rawMarkdown": "next time you can run something like this \n```\nimport tensorflow as tf\nraw_dataset = tf.data.TFRecordDataset(GCS_DS_PATH + '/train_tfrecords/05-1881.tfrec')\nfor raw_record in raw_dataset.take(1):\n  example = tf.train.Example()\n  example.ParseFromString(raw_record.numpy())\n  print(example)\n```\n\nto dump out all the features",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1190675,
      "author_name": "raddar",
      "author_url": "",
      "post_date": "02/07/2021 22:25:29",
      "content": "<pre><code>def read_labeled_tfrecord(example):\n    LABELED_TFREC_FORMAT = {\n        \"image\": tf.io.FixedLenFeature([], tf.string),\n        \"StudyInstanceUID\": tf.io.FixedLenFeature([], tf.string),\n        \"ETT - Abnormal\": tf.io.FixedLenFeature([], tf.int64),\n        \"ETT - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"ETT - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Abnormal\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Incompletely Imaged\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"CVC - Abnormal\": tf.io.FixedLenFeature([], tf.int64), \n        \"CVC - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"CVC - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"Swan Ganz Catheter Present\": tf.io.FixedLenFeature([], tf.int64),\n    }\n    example = tf.io.parse_single_example(example, LABELED_TFREC_FORMAT)\n    image = decode_image(example['image'])\n    label = [tf.cast(example[\"ETT - Abnormal\"], tf.int32),\n             tf.cast(example[\"ETT - Borderline\"], tf.int32),\n             tf.cast(example[\"ETT - Normal\"], tf.int32),\n             tf.cast(example[\"NGT - Abnormal\"], tf.int32),\n             tf.cast(example[\"NGT - Borderline\"], tf.int32),\n             tf.cast(example[\"NGT - Incompletely Imaged\"], tf.int32),\n             tf.cast(example[\"NGT - Normal\"], tf.int32),\n             tf.cast(example[\"CVC - Abnormal\"], tf.int32),\n             tf.cast(example[\"CVC - Borderline\"], tf.int32),\n             tf.cast(example[\"CVC - Normal\"], tf.int32),\n             tf.cast(example[\"Swan Ganz Catheter Present\"], tf.int32)]\n    return image, label\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1194087,
      "author_name": "venkat555",
      "author_url": "",
      "post_date": "02/10/2021 03:45:15",
      "content": "<p>next time you can run something like this </p>\n<pre><code>import tensorflow as tf\nraw_dataset = tf.data.TFRecordDataset(GCS_DS_PATH + '/train_tfrecords/05-1881.tfrec')\nfor raw_record in raw_dataset.take(1):\n  example = tf.train.Example()\n  example.ParseFromString(raw_record.numpy())\n  print(example)\n</code></pre>\n<p>to dump out all the features </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1190210": "Hi,\n\nI want to use tfrec files but I searched a lot and cant find format of tfrec files anywhere for this competition. Where can I find it?\n\nThank you.",
    "1190675": "```\ndef read_labeled_tfrecord(example):\n    LABELED_TFREC_FORMAT = {\n        \"image\": tf.io.FixedLenFeature([], tf.string),\n        \"StudyInstanceUID\": tf.io.FixedLenFeature([], tf.string),\n        \"ETT - Abnormal\": tf.io.FixedLenFeature([], tf.int64),\n        \"ETT - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"ETT - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Abnormal\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Incompletely Imaged\": tf.io.FixedLenFeature([], tf.int64),\n        \"NGT - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"CVC - Abnormal\": tf.io.FixedLenFeature([], tf.int64), \n        \"CVC - Borderline\": tf.io.FixedLenFeature([], tf.int64),\n        \"CVC - Normal\": tf.io.FixedLenFeature([], tf.int64),\n        \"Swan Ganz Catheter Present\": tf.io.FixedLenFeature([], tf.int64),\n    }\n    example = tf.io.parse_single_example(example, LABELED_TFREC_FORMAT)\n    image = decode_image(example['image'])\n    label = [tf.cast(example[\"ETT - Abnormal\"], tf.int32),\n             tf.cast(example[\"ETT - Borderline\"], tf.int32),\n             tf.cast(example[\"ETT - Normal\"], tf.int32),\n             tf.cast(example[\"NGT - Abnormal\"], tf.int32),\n             tf.cast(example[\"NGT - Borderline\"], tf.int32),\n             tf.cast(example[\"NGT - Incompletely Imaged\"], tf.int32),\n             tf.cast(example[\"NGT - Normal\"], tf.int32),\n             tf.cast(example[\"CVC - Abnormal\"], tf.int32),\n             tf.cast(example[\"CVC - Borderline\"], tf.int32),\n             tf.cast(example[\"CVC - Normal\"], tf.int32),\n             tf.cast(example[\"Swan Ganz Catheter Present\"], tf.int32)]\n    return image, label\n```",
    "1194087": "next time you can run something like this \n```\nimport tensorflow as tf\nraw_dataset = tf.data.TFRecordDataset(GCS_DS_PATH + '/train_tfrecords/05-1881.tfrec')\nfor raw_record in raw_dataset.take(1):\n  example = tf.train.Example()\n  example.ParseFromString(raw_record.numpy())\n  print(example)\n```\n\nto dump out all the features"
  },
  "source": "meta"
}