{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"from matplotlib.pyplot import imshow\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom PIL import Image\nimport pandas as pd\nimport numpy as np\nimport cv2\nimport os\n\nprint(os.listdir('../input/'))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train = pd.read_csv('../input/understanding_cloud_organization/train.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.dtypes","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Image_Label = train.pop('Image_Label')\n\ntrain['label'] = Image_Label.apply(lambda x: x.split('_')[1])\ntrain['image'] = Image_Label.apply(lambda x: x.split('_')[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.isnull().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.countplot(train['label'])\nplt.plot()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"path = '../input/understanding_cloud_organization/train_images/'\n\nlabels = train['label'].values\n\n\nfor i, img in enumerate(train['image'][:4]):\n    image = plt.imread(path + img)\n    plt.imshow(image)\n    plt.title(labels[i])\n    plt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def decode(mask, shape=(1400, 2100)):\n    \n    m = mask.split()\n    a = list()\n    \n    for x in (m[0:][::2], m[1:][::2]):\n        a.append(np.asarray(x, dtype=int))\n    \n    starts, lengths = a\n    starts -= 1\n    stop = starts + lengths\n    \n    image = np.zeros(shape[0]*shape[1], dtype=np.uint8)\n    for i, j in zip(starts, stop):\n        image[i:j] = 1\n        \n    image = image.reshape(shape, order='F') \n    return image","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=[60, 30])\n\nfor i, row in train[:16].iterrows():\n    img = cv2.imread(path +  row['image'])\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    enc_pix = row['EncodedPixels']\n    try:\n        mask = decode(enc_pix)\n    except:\n        mask = np.zeros((1400, 2100))\n        \n    plt.subplot(4, 4, i+1)\n    plt.imshow(img)\n    plt.imshow(mask, alpha=0.6, cmap='gray')\n    plt.title(\"Label %s\" % row['label'], fontsize=32)\n    plt.axis('off')    \n    \nplt.show()","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":1}