{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport os\nimport PIL\nimport PIL.Image\nimport tensorflow as tf\nimport tensorflow_datasets as tfds","metadata":{"execution":{"iopub.status.busy":"2021-08-10T04:39:25.392084Z","iopub.execute_input":"2021-08-10T04:39:25.392704Z","iopub.status.idle":"2021-08-10T04:39:32.880396Z","shell.execute_reply.started":"2021-08-10T04:39:25.392605Z","shell.execute_reply":"2021-08-10T04:39:32.879270Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(tf.__version__)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T04:39:34.508221Z","iopub.execute_input":"2021-08-10T04:39:34.508644Z","iopub.status.idle":"2021-08-10T04:39:34.514641Z","shell.execute_reply.started":"2021-08-10T04:39:34.508607Z","shell.execute_reply":"2021-08-10T04:39:34.513391Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# ****Uploading PNG files****","metadata":{}},{"cell_type":"markdown","source":"Upload png dataset from:\nhttps://www.kaggle.com/jonathanbesomi/rsna-miccai-png\n\nUse the keras.preprocessing module from:\nhttps://www.tensorflow.org/tutorials/load_data/images#load_using_tfkeraspreprocessing\n\nand assigned it to training data:","metadata":{}},{"cell_type":"code","source":"import pathlib\ndr='../input/rsna-miccai-png/train'\ntrain_ds = tf.keras.preprocessing.image_dataset_from_directory(\n  dr,\n  labels='inferred',\n  validation_split=0.2,\n  subset=\"training\",\n  seed=123,\n  # image_size=(img_height, img_width),\n  # batch_size=batch_size,\n)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T04:39:38.046854Z","iopub.execute_input":"2021-08-10T04:39:38.047265Z","iopub.status.idle":"2021-08-10T04:39:58.355146Z","shell.execute_reply.started":"2021-08-10T04:39:38.047230Z","shell.execute_reply":"2021-08-10T04:39:58.354100Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"So, we can see that each class corresponds to patient's id codes. \n\n*If someone knows how could I change the clases to the competition labels (MGMT_value), please leave it on comments...*","metadata":{}},{"cell_type":"code","source":"class_names = train_ds.class_names\nprint(class_names)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T04:40:04.126378Z","iopub.execute_input":"2021-08-10T04:40:04.126823Z","iopub.status.idle":"2021-08-10T04:40:04.133194Z","shell.execute_reply.started":"2021-08-10T04:40:04.126790Z","shell.execute_reply":"2021-08-10T04:40:04.131474Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Patient's ID label","metadata":{}},{"cell_type":"markdown","source":"So, we can visualize the images and the patient id:","metadata":{}},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nplt.figure(figsize=(10, 10))\nfor images, labels in train_ds.take(1):\n  for i in range(9):\n    ax = plt.subplot(3, 3, i + 1)\n    plt.imshow(images[i].numpy().astype(\"uint8\"))\n    plt.title(class_names[labels[i]])\n    plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2021-08-10T04:40:12.742363Z","iopub.execute_input":"2021-08-10T04:40:12.742756Z","iopub.status.idle":"2021-08-10T04:40:16.350675Z","shell.execute_reply.started":"2021-08-10T04:40:12.742719Z","shell.execute_reply":"2021-08-10T04:40:16.348228Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"We can choose another directory to show the images and the type of images as the label if we set a patient's id in the file's path","metadata":{}},{"cell_type":"code","source":"dr2 ='../input/rsna-miccai-png/train/00000'\nimg_type = tf.keras.preprocessing.image_dataset_from_directory(\n  dr2,\n  labels='inferred',\n  validation_split=0.2,\n  subset=\"training\",\n  seed=123,\n  # image_size=(img_height, img_width),\n  # batch_size=batch_size,\n)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T04:44:54.919070Z","iopub.execute_input":"2021-08-10T04:44:54.919465Z","iopub.status.idle":"2021-08-10T04:44:55.055260Z","shell.execute_reply.started":"2021-08-10T04:44:54.919432Z","shell.execute_reply":"2021-08-10T04:44:55.053637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"class_names2 = img_type.class_names\nprint(class_names2)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T04:45:23.607715Z","iopub.execute_input":"2021-08-10T04:45:23.608068Z","iopub.status.idle":"2021-08-10T04:45:23.613224Z","shell.execute_reply.started":"2021-08-10T04:45:23.608035Z","shell.execute_reply":"2021-08-10T04:45:23.612160Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Type of image as label","metadata":{}},{"cell_type":"markdown","source":"So, we can visualize several types of images of the 00000 patient:","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(10, 10))\nfor images, labels in img_type.take(1):\n  for i in range(12):\n    ax = plt.subplot(4, 4, i + 1)\n    plt.imshow(images[i].numpy().astype(\"uint8\"))\n    plt.title(class_names2[labels[i]])\n    plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2021-08-10T04:46:14.692336Z","iopub.execute_input":"2021-08-10T04:46:14.692718Z","iopub.status.idle":"2021-08-10T04:46:16.500098Z","shell.execute_reply.started":"2021-08-10T04:46:14.692687Z","shell.execute_reply":"2021-08-10T04:46:16.499197Z"},"trusted":true},"execution_count":null,"outputs":[]}]}