{"cells":[{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"scans = !ls /kaggle/input/rsna-str-pulmonary-embolism-detection/train/*/* -d\nlen(scans)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","collapsed":true,"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":false},"cell_type":"markdown","source":"# We're given *7279* scans\n"},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"from tqdm import tqdm\ncount_min = 10e6\ncount_max = 0\nfor s in tqdm(scans):\n    cnt, = !ls {s}/* | wc -l # this is super-slow.. probably avoiding \"!\" would be a good idea\n    count_min = min(count_min, int(cnt))\n    count_max = max(count_max, int(cnt))\ncount_min, count_max","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Each scan consists of number of slices, between *63* and *1083*"},{"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"cell_type":"code","source":"import numpy as np\n\nimport matplotlib\nimport matplotlib.pyplot as plt\n\nimport matplotlib.animation as animation\n\nfrom matplotlib import animation, rc\nfrom pydicom import dcmread\n\n\nrc('animation', html='jshtml')\n\n\ndef read_scan(path):\n    fs = !ls -d {path}/*\n    \n    slices = []\n    for f in fs:\n        ds = dcmread(f)\n        data = ds.pixel_array\n        num = int(ds.InstanceNumber)\n        slices.append((num, data))\n    \n    slices.sort()\n    slices = [s[1] for s in slices]\n    return slices\n\ndef create_animation(ims):\n    ims = ims\n    fps = 30\n    nSeconds = 5\n\n    fig = plt.figure( figsize=(9,9) )\n\n    a = ims[0]\n    im = plt.imshow(a)\n\n    def animate_func(i):\n        im.set_array(ims[i])\n        return [im]\n\n    anim = animation.FuncAnimation(fig, animate_func, frames = len(ims), interval = 1000//24)\n    \n    return anim\n\ns1 = scans[1]\nims = read_scan(s1)\nanim = create_animation(ims)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"anim\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Also each slice contains bunch of metadata"},{"metadata":{"trusted":true},"cell_type":"code","source":"f,*_ = !ls -d {scans[1]}/*\nmeta = dcmread(f)\nmeta","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# This is part multi-class and part multi-label competition, since some labels are mutually exclusive"},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"import pandas as pd\ndf = pd.read_csv('/kaggle/input/rsna-str-pulmonary-embolism-detection/train.csv')\n\ncols = \"pe_present_on_image\tnegative_exam_for_pe\tqa_motion\tqa_contrast\tflow_artifact\trv_lv_ratio_gte_1\trv_lv_ratio_lt_1\tleftsided_pe\tchronic_pe\ttrue_filling_defect_not_pe\trightsided_pe\tacute_and_chronic_pe\tcentral_pe\tindeterminate\".split()\n\n\n\nfig = plt.figure( figsize=(12,12) )\npie = df[cols].sum()\nplt.pie(pie, labels=pie.index)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# So, large number of examples appears to be negative"},{"metadata":{},"cell_type":"markdown","source":"### *wip*"}],"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}