{"cells":[{"metadata":{},"cell_type":"markdown","source":"<center><div style=\"background:url(https://www.teahub.io/photos/full/19-197024_backgrounds-medical-hd-best-free-medicine-wallpapers-medicine.jpg); border-radius:8px;padding:20px; color:gray\"><h1 style=\"font-size: 40px;\">DATA EXPLANATION VIDEO</h1></div></center><br><br>\n            <div style=\"margin-left:50px;margin-right:50px;\">\n    <p style=\"font-size:20px\">Did I actually sit down to discuss this competetion with myself? You bet I did.<br><br><a hreaf=\"https://www.linkedin.com/posts/vyom-bhatia-40ba79181_computervision-activity-6747848578720419840-wMNc\">Check it out here on LinkedIn.</a></p></div>\n   "},{"metadata":{},"cell_type":"markdown","source":"\n\n<center><div style=\"background:url(https://www.teahub.io/photos/full/19-197024_backgrounds-medical-hd-best-free-medicine-wallpapers-medicine.jpg); border-radius:8px;padding:20px; color:gray\"><h1 style=\"font-size: 40px;\">INTUBATION</h1></div></center><br><br>\n            <div style=\"margin-left:50px;margin-right:50px;\">\n    <p style=\"font-size:20px\">Nasogastric intubation is a medical process involving the insertion of a plastic tube through the nose, past the throat, and down into the stomach. <br>Orogastric intubation is a similar process involving the insertion of a plastic tube (orogastric tube) through the mouth.</p>\n\n\n<img src=\"https://cdn.sanity.io/images/0vv8moc6/contagion/932718a7efb2e107df436416a1d72fcda8250b89-3984x2656.jpg?auto=format\" style=\"width:30%;border-radius:10px;float:right;\"><br><br>\n    <center><div style=\"background:url(https://www.teahub.io/photos/full/19-197024_backgrounds-medical-hd-best-free-medicine-wallpapers-medicine.jpg); border-radius:8px;padding:20px; color:gray\"><h1 style=\"font-size: 40px;\">NCOVID-19 AND INTUBATION</h1></div></center><br>\n<p style=\"font-size:20px\">The “early intubation” makes sense for two reasons:<br> <br>(1) patients with COVID-19 can deteriorate rapidly (e.g. from minimal oxygen requirements to life-threatening hypoxaemia and respiratory distress in hours) and <br><br>(2) it takes time to deal with the logistical complexity of preparing for, and performing, intubation of patients with COVID-19.<br><br> This logistical complexity arises from needing to transfer the patient to an appropriate location for intubation while maintaining infection control measures and the need for for the intubation team to assemble, don appropriate personal protective equipment (PPE), and prepare for this potentially life-or-death intervention.<br><br>Point being that patients with covid have a lot of complications. As the covid cases rise, we are seeing a rise in need of intubations.<br>Even though, Intubation has its own complications and require a technician or a physician to go through x-rays to ensure the tube is not erratically placed, which is prone to human errors.</p>\n<br><br>\n\n<img src=\"https://healthjade.net/wp-content/uploads/2019/05/nasogastric-tube.jpg\" style=\"width:30%;border-radius:10px;float:left;\"><br><br>\n    <center><div style=\"background:url(https://www.teahub.io/photos/full/19-197024_backgrounds-medical-hd-best-free-medicine-wallpapers-medicine.jpg); border-radius:8px;padding:60px; color:gray;\"><h1 style=\"font-size: 40px;\">COMPLICATIONS</h1></div></center><br><br>\n    <p style=\"font-size:20px;margin-left:50px;margin-right:50px;\">If your NG tube isn’t inserted properly, it can potentially injure the tissue inside your nose, sinuses, throat, esophagus, or stomach.\n<br><br>\nThis is why placement of the NG tube is checked and confirmed to be in the correct location before any other action is performed.</p></div><br><br>"},{"metadata":{},"cell_type":"markdown","source":"<div style=\"margin-left:50px;margin-right:50px;\">\n<img src=\"https://scontent.fdel27-2.fna.fbcdn.net/v/t31.0-8/704596_398230280272514_875501421_o.jpg?_nc_cat=100&ccb=2&_nc_sid=6e5ad9&_nc_ohc=elhSWP5xLp4AX8Ho6pF&_nc_oc=AQl_SLeozTq2hi4ktY5qBxr-a4u4jlFUKSr16K5AJcL_PAwFfffvt70edZmnrzs-VVA&_nc_ht=scontent.fdel27-2.fna&oh=ae907de942569e6dec4dce714c95eff7&oe=600C13B4\" style=\"width:50%;border-radius:10px;float:left;\"><br><br>\n    <center><div style=\"background:url(https://www.teahub.io/photos/full/19-197024_backgrounds-medical-hd-best-free-medicine-wallpapers-medicine.jpg); border-radius:8px;padding:60px; color:gray;\"><h1 style=\"font-size: 40px;\">NEED FOR AI</h1></div></center><br><br>\n    <p style=\"font-size:20px;margin-left:50px;margin-right:50px;\">We need the physicians to do the jobs of spending time and looking through every single x-ray to see any abnormalitites. \n<br><br>\nWell if we can get AI to do the work, we free up human capital and save time. <br><br>That's why we fricking need AI.</p></div>\n   "},{"metadata":{},"cell_type":"markdown","source":"<div style=\"margin-left:50px;margin-right:50px;\">\n<center><div style=\"background:url(https://www.teahub.io/photos/full/19-197024_backgrounds-medical-hd-best-free-medicine-wallpapers-medicine.jpg); border-radius:8px;padding:20px; color:white;\"><h1 style=\"font-size: 40px;\">TIME TO CODE</h1></div><br>\n<p style=\"font-size:20px;margin-left:50px;margin-right:50px;\">The point is simple, we need a model to solve the problem, let's build one. <br><br>Also,<br><br> My mom said that I would be married off if I don't get 5 upvotes on this notebook. <br>That's how it works in India. Deal with it. </p></center></div>"},{"metadata":{},"cell_type":"markdown","source":"# Importing Libraries + Data"},{"metadata":{"trusted":true},"cell_type":"code","source":"!pip install -q efficientnet_pytorch","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from efficientnet_pytorch import EfficientNet\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"from fastai.vision.all import *\nimport torch\n\nimport pandas as pd","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Reading the CSV with annotations."},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"data = pd.read_csv(\"../input/ranzcr-clip-catheter-line-classification/train_annotations.csv\")\ndata.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Forming the Dataloader"},{"metadata":{},"cell_type":"markdown","source":"### Defining the functions to grab those files."},{"metadata":{"trusted":true},"cell_type":"code","source":"path = \"../input/ranzcr-clip-catheter-line-classification\"\n\ndef get_x(r):\n    return path + \"/\" + 'train' + \"/\" + r['StudyInstanceUID'] + \".jpg\"\n\ndef get_y(r):\n    return r['label']","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Finally setting up the Dataloader for FastAI.\n#### Well below you can see we got a lot of hyperparmeter tuning. Hit me up on [LinkedIn](https://www.linkedin.com/in/vyom-bhatia-40ba79181/) on [Instagram](https://instagram.com/vyombhatia) if you got any questions."},{"metadata":{"trusted":true},"cell_type":"code","source":"def getblock(size=400,batch=32, data_df=data):\n    block = DataBlock(blocks=(ImageBlock, CategoryBlock),\n                      splitter=RandomSplitter(seed=42),\n                      get_x=get_x, # Using the function above.\n                      get_y=get_y, # Using the function above.\n                      item_tfms = RandomResizedCrop(400), # Resizing images to 400 pixels.\n                      \n                      # Data Augmentation time:\n                      batch_tfms = [*aug_transforms(mult=1.0, do_flip=False,\n                                                   flip_vert=False, max_rotate=5,\n                                                   min_zoom=1.0, max_zoom=1,\n                                                   pad_mode=\"zeros\",\n                                                   xtra_tfms=[Contrast(max_lighting=0.15,p=1)],\n                                                   max_lighting=0.1, max_warp=0.2,\n                                                   p_affine=0.75, p_lighting=0.75),\n                                    Normalize.from_stats(*imagenet_stats)])\n    \n    return block.dataloaders(data_df, bs=batch)\n                      \n    ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"dataloader = getblock()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Visualizing"},{"metadata":{},"cell_type":"markdown","source":"### Lets see how the data augmentations is doing:"},{"metadata":{"trusted":true},"cell_type":"code","source":"dataloader.show_batch()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Building the model"},{"metadata":{},"cell_type":"markdown","source":"### Easy Peasy grab a resnet50 and train the model using transfer learning:"},{"metadata":{"trusted":true},"cell_type":"code","source":"model = EfficientNet.from_pretrained('efficientnet-b2')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"learn = Learner(dataloader, model, metrics = accuracy)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Learning Rate Finder"},{"metadata":{},"cell_type":"markdown","source":"### I absolutely love this function from the FastAI library. \n### Why? It finds you the best Learning Rate."},{"metadata":{"trusted":true},"cell_type":"code","source":"learn.lr_find()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"learn.fine_tune(2, 0.001737800776027143)\n# The above LR was suggested by the lr_find.","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Yes Josh, I know that the accuracy sucks with EfficientNet-B2 and my current hyperparameters for data augmentation. I will keep updating this notebook every few hours.\n### A little background about me?\n### I am an 18-year-old business major, Fresher at Delhi University and my mom will marry me off if you don't upvote this notebook. That's how it works here. Thank you. Love from India."}],"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}