{"cells":[{"metadata":{"_uuid":"402d4f458caf398f1d18ba35503bd267d788b4a6"},"cell_type":"markdown","source":"# Airbus Ship Detection \n\n<div class=\"markdown-converter__text--rendered\"><p><img src=\"https://storage.googleapis.com/kaggle-media/competitions/Airbus/ships.jpg\" alt=\"Shipping\" width=\"300\" style=\"float: right;\"></p>\n<p>Airbus is excited to challenge Kagglers to build a model that detects all ships in satellite images as quickly as possible. Can you find them even in imagery with clouds or haze? </p>\n \n<p>Here’s the backstory: Shipping traffic is growing fast. \nMore ships increase the chances of infractions at sea like environmentally devastating ship accidents, piracy, illegal fishing, drug trafficking, and illegal cargo movement. This has compelled many organizations, from environmental protection agencies to insurance companies and national government authorities, to have a closer watch over the open seas.</p>\n<p>\n</p><p><a href=\"http://www.intelligence-airbusds.com/satellite-data/\" target=\"_blank\" rel=\"nofollow\">Airbus</a> offers comprehensive maritime monitoring services by building a meaningful solution for wide coverage, fine details, intensive monitoring, premium reactivity and interpretation response.\nCombining its proprietary-data with highly-trained analysts, they help to support the maritime industry to increase knowledge, anticipate threats, trigger alerts, and improve efficiency at sea.</p>\n<p>A lot of work has been done over the last 10 years to automatically extract objects from satellite images with significative results but no effective operational effects.  Now Airbus is turning to Kagglers to increase the accuracy <b>and</b>  speed of automatic ship detection.</p> \n\n<p><b>Algorithm Speed Prize: </b>After the Kaggle challenge is complete,  competitors may submit their model via a private Kaggle kernel for a speed evaluation based upon the inference time on over 40.000  images chips (typical size of a full satellite image) to win a special algorithm speed prize.</p>\n<p>&nbsp;</p>\n\nIf you're interested to explore more Airbus data, you are welcomed to check out the <a href=\"https://www.intelligence-airbusds.com/sandbox\" target=\"_blank\" rel=\"nofollow\">OneAtlas Sandbox</a>. And for more insights on our Maritime Surveillance capabilities, have a look at Airbus Intelligence <a href=\"https://www.intelligence-airbusds.com/en/8208-maritime\" target=\"_blank\" rel=\"nofollow\">page</a>.</div>"},{"metadata":{"trusted":true,"_uuid":"7206a9c605ac8ae6e53807869bbab9e01323138f"},"cell_type":"code","source":"import numpy as np\nimport pandas as pd \nfrom skimage.data import imread\nimport matplotlib.pyplot as plt\nimport os\nfrom keras.preprocessing.image import load_img\nfrom tqdm import tqdm_notebook\nprint(os.listdir(\"../input\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"51cf6fc2a8892d206b51f73bbea5e5ddf758e2fb"},"cell_type":"code","source":"Train_Image_folder='../input/train/'\nTest_Image_folder='../input/test/'\nTrain_Image_name=os.listdir(path=Train_Image_folder)\nTest_Image_name=os.listdir(path=Test_Image_folder)\nTrain_Image_path=[]\nTrain_Mask_path=[]\nTrain_id=[]\nfor i in Train_Image_name:\n    path1=Train_Image_folder+i\n    id1=i.split(sep='.')[0]\n    Train_Image_path.append(path1)\n    Train_id.append(id1)\n\ndf_Train_path=pd.DataFrame({'ImageId':Train_id,'Train_Image_path':Train_Image_path})\nprint('Train Shape: ',df_Train_path.shape)\ndf_Train_path.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9a7f8eb95686a96f62b2ae840f0db41c0140e677"},"cell_type":"code","source":"Test_Image_path=[]\nTest_id=[]\nfor i in Test_Image_name:\n    path=Test_Image_folder+i\n    id2=i.split(sep='.')[0]\n    Test_Image_path.append(path)\n    Test_id.append(id2)\ndf_Test_path=pd.DataFrame({'ImageId':Test_id,'Test_Image_path':Test_Image_path})\nprint('Test Shape: ',df_Test_path.shape)\ndf_Test_path.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a4d3cd3eb21ab42111d8e343b425ccf701a3b5d5"},"cell_type":"code","source":"masks = pd.read_csv('../input/train_ship_segmentations.csv')\nprint('Mask Shape: ',masks.shape)\nmasks.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"3d6f37c83a679bbc0ec4c918e3e95463ab152e66"},"cell_type":"code","source":"# ref: https://www.kaggle.com/paulorzp/run-length-encode-and-decode\ndef rle_decode(mask_rle, shape=(768, 768)):\n    '''\n    mask_rle: run-length as string formated (start length)\n    shape: (height,width) of array to return \n    Returns numpy array, 1 - mask, 0 - background\n\n    '''\n    s = mask_rle.split()\n    starts, lengths = [np.asarray(x, dtype=int) for x in (s[0:][::2], s[1:][::2])]\n    starts -= 1\n    ends = starts + lengths\n    img = np.zeros(shape[0]*shape[1], dtype=np.uint8)\n    for lo, hi in zip(starts, ends):\n        img[lo:hi] = 1\n    return img.reshape(shape).T  # Needed to align to RLE direction","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c8c87b926c2384b19a40d8da256b177765f0244d"},"cell_type":"code","source":"masks = pd.read_csv('../input/train_ship_segmentations.csv')\nmasks.head()","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}