{"cells":[{"metadata":{},"cell_type":"markdown","source":"## Check Train TFRecords\n\nThis notebook checks the training TFRecords provided for the RANZCR CLiP competition. There are 2 points to check:\n1. Items in the TFrecord files: PatientID is not provided.\n2. Number of items in each TFRecord files: the last file '15-1881.tfrec' has 1868 items. Others have 1881 items which are shown by the file name 'xx-1881.tfrec'."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import tensorflow as tf\n\nprint(tf.__version__)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"RANZER_DIR = '../input/ranzcr-clip-catheter-line-classification/'\ntfrec_file_names = tf.io.gfile.glob(RANZER_DIR + 'train_tfrecords/*.tfrec')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### 1. Items in The TFrecord Files"},{"metadata":{"trusted":true},"cell_type":"code","source":"dataset = tf.data.TFRecordDataset(tfrec_file_names)\nraw_record = next(iter(dataset.take(1)))\nexample = tf.train.Example()\nexample.ParseFromString(raw_record.numpy())\nfeature_list = sorted([f for f in example.features.feature])\n\nfor f in feature_list:\n    print(f)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### 2. Number of Items in Each TFRecord Files"},{"metadata":{"trusted":true},"cell_type":"code","source":"import os\n\nfor file_name in sorted(tfrec_file_names):\n    dataset = tf.data.TFRecordDataset(file_name)\n    item_count = 0\n    for item in iter(dataset):\n        item_count += 1\n    base_name = os.path.basename(file_name)\n    print(\"{0}: {1}\".format(base_name, item_count))","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}