{"cells":[{"metadata":{},"cell_type":"markdown","source":"## tl;dr\n\nWithin training set we have `CVC - Abnormal` category. This category has a very broad possible cases what can go wrong with CVC placement in your body.\n\nI manually inspected training data and split `CVC - Abnormal` category into two main ones:\n\n- `CVC - Abnormal - Right Atrium` - most common abnormality, when CVC is inserted too deep into the heart\n- `CVC - Abnormal - Other` - all other abnormalities, which include bad CVC line trajectory, CVC kinkings and other abnormalities.\n\nThe dataset is provided in https://www.kaggle.com/raddar/ranzcr-clip-abnormal-cvc-categories which maps to competition training data annotations by `index` column.\n\nThis information is potentially useful if you are going to train detectors."},{"metadata":{},"cell_type":"markdown","source":"## CVC positioning - how is it determined?\n\nTo show how normal/borderline/abnormal CVC position is decided, one can look at this illustration:\n\n![](https://cdn.shopify.com/s/files/1/0667/1365/articles/What_is_a_picc_line_image-529932_600x.jpg?v=1587788405)\n\n\n- Image above shows normal CVC tip placement.\n\n- If CVC tip is little lower (but not too low) compared to reference image, the position is considered as borderline - neither normal nor abnormal.\n\n- If CVC is much lower, the position is considered abnormal (malpositioned). This is also known as CVC tip placement in Right Atrium. However, this is only one type of possible abnormalities (although most common one).\n\n- If the tip of CVC is above compared to reference image, this another kind of abnormality, caused due to many reasons of CVC insertion failures - line going in wrong venaes, CVC kinking, etc.\n"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":false},"cell_type":"code","source":"import ast\nimport numpy as np\nimport pandas as pd\nimport cv2\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\npd.options.display.max_colwidth = 1000\n\n# my dataset\ncvc_malpositions = pd.read_csv('../input/ranzcr-clip-abnormal-cvc-categories/cvc_malposition_categories.csv')\n\n# competition data\ntrain_ann = pd.read_csv('../input/ranzcr-clip-catheter-line-classification/train_annotations.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"I've spent some time to look through all `CVC - Abnormal` cases in order to split abnormalities into 2 distinct categories:\n\n- `CVC - Abnormal - Right Atrium` - most common abnormality, when CVC is inserted too deep into the heart\n- `CVC - Abnormal - Other` - all other abnormalities, which include bad CVC line trajectory, CVC kinkings and other abnormalities."},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true,"_kg_hide-input":false},"cell_type":"code","source":"# the table below can be joined with competition annotations by the `index` column\ncvc_malpositions","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":false,"trusted":true},"cell_type":"code","source":"cvc_malpositions.groupby('label')['label'].count()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Visualizations\n\n### Normal cases"},{"metadata":{"trusted":true},"cell_type":"code","source":"def plot_xray(index):\n    studyuid = train_ann.loc[index,'StudyInstanceUID']\n    img = cv2.imread('../input/ranzcr-clip-catheter-line-classification/train/'+studyuid+'.jpg')\n    cvc = ast.literal_eval(train_ann.loc[index,'data'])\n    for c in cvc:\n        img = cv2.circle(img, tuple(c), 5, (255,0,0), 5)\n    plt.figure(figsize=(8,8))\n    plt.imshow(img)","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"plot_xray(16)","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"plot_xray(7)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Both cases show CVC in correct position, with the tip of CVC being close to the heart."},{"metadata":{},"cell_type":"markdown","source":"### Borderline"},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"plot_xray(13)","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"plot_xray(40)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The tip of CVC is within heart shadow, however radiologists did not consider the tip of CVC to be too deep into the heart. This is very subjective as radiologists could disagree if its borderline or not quite often."},{"metadata":{},"cell_type":"markdown","source":"### Abnormal - Right Atrium\n\nNow we are going to inspect different types of abnormalities based on my manual annotations. Let's take a look at the most common one - the tip of CVC in heart's right atrium."},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"plot_xray(25)","execution_count":null,"outputs":[]},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"plot_xray(42)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"The tip of CVC is clearly way too deep into the heart. This is troublesome as this can have direct impact to the patient's health."},{"metadata":{},"cell_type":"markdown","source":"### Abnormal - Other"},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"plot_xray(34)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"This a common abnormality, when the CVC trajectory goes into other venae - in this case to the neck. The CVC must be reinserted for this patient!"},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"plot_xray(43)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"This is a typical case of CVC kinking - when the tip of CVC is kinked during insertion procedure."},{"metadata":{},"cell_type":"markdown","source":"## Different CVC - Abnormal categories - what's next?\n\nI have shown that `CVC - Abnormal` category should not be treated as a homogenous feature of CVC - it clearly has many different forms of possible abnormalities.\n\nThis might be useful when validating classifiers. However, the biggest benefit might come if one builds detection/segmentation models.\n\nAfter all, CVC classification task is the hardest problem of the competition - even small gains can lead to huge AUC differences on the LB."}],"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}