{"cells":[{"metadata":{"trusted":true,"_uuid":"7c1f8e67cb9a65729e8124242e6bd7a54569e3cf"},"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nfrom matplotlib import patches\nimport matplotlib.image as mpimg\nimport zipfile\nimport cv2\nimport numpy as np\n\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f5f0774bb2e510a490f9c7c17c484215550f0ff7"},"cell_type":"code","source":"!ls ../input","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d5284ff77c200405c129f1d3bf8bb0fc227f4a4a"},"cell_type":"code","source":"df_bounding_boxes = pd.read_csv('../input/train_bounding_boxes.csv', nrows=100, index_col=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cf75dfe515189eafd971749c4b75c16c6efa9a57"},"cell_type":"code","source":"df_bounding_boxes.head(16)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6cb961ef6628fd7fb999aec01b1b7c839b8ea43b"},"cell_type":"code","source":"for img, bounding_boxes in df_bounding_boxes.groupby('ImageID'):\n    fig,ax = plt.subplots(1)\n\n    ax.set_title(img)\n    \n    ax.set_xlim([-0.1,1.1])\n    ax.set_ylim([-0.1,1.1])\n    \n    # Display the image\n    #ax.imshow(im)\n\n    def add_rect (row):\n        # Create a Rectangle patch\n        w = row.XMax - row.XMin\n        h = row.YMax - row.YMin\n        rect = patches.Rectangle((row.XMin, row.YMin), w, h, linewidth=1, edgecolor='r', facecolor='none')\n\n        # Add the patch to the Axes\n        ax.add_patch(rect)        \n    \n    for _, data in bounding_boxes.iterrows():\n        add_rect(data)\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0c77556c7380e0073a8d047213e70c8b048eee1a"},"cell_type":"code","source":"df_human_labels = pd.read_csv('../input/train_human_labels.csv', nrows=200, index_col=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"de2f6ad4f689122ac83b46ad68ea6e6520de9ab3"},"cell_type":"code","source":"df_human_labels.head(140)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c50195d38ca660e512b41ae90949d04608c4bd0f"},"cell_type":"code","source":"df_machine_labels = pd.read_csv('../input/train_machine_labels.csv', nrows=100, index_col=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d177e733b3cb14634b88ed7de3a2f43aed1db3b9"},"cell_type":"code","source":"df_machine_labels.head(16)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4c9f0359f5a827d8b8fa741c3504cf46fb75ccf5"},"cell_type":"code","source":"df_human_labels.groupby('ImageID')['LabelName'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"35b849f4ad361f05e1f6c2e848a413988f0a8ac6"},"cell_type":"code","source":"df_tuning_labels = pd.read_csv('../input/tuning_labels.csv', nrows=100, index_col=0, header=None, names=['image_id', 'labels'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1834a035a79a08e1090ed17bb4a245d6ac806f3f"},"cell_type":"code","source":"df_tuning_labels.head(20)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"cc6351e93aad2c819037a795f5089bb9a12142ea"},"cell_type":"code","source":"df_classes_descriptions = pd.read_csv('../input/class-descriptions.csv', index_col=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2e2669dc6819b3dbb7287fb43db24b4a0fefeb41"},"cell_type":"code","source":"df_classes_descriptions.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ef0bb65de533478625309c8c7c404b3d7041bb77"},"cell_type":"code","source":"df_classes_descriptions.nunique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0b853c1ab07feb00f4445df049f445bcd8068fa8"},"cell_type":"code","source":"df_classes_trainable = pd.read_csv('../input/classes-trainable.csv', index_col=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"085b2480150457fc49d793ee5ea68d1b9e455683"},"cell_type":"code","source":"df_classes_trainable.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"879fa73398759bf99da8eccbe375274c9259cd99"},"cell_type":"code","source":"df_classes_descriptions.loc[df_classes_trainable.index, :].head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"09005b79f365ca7212cb0f8dd71e6028e750022f"},"cell_type":"code","source":"df_classes_descriptions.loc[df_classes_trainable.index, :].nunique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ae2fe76dd2fd0c55dcffe35202f1894cba978be3"},"cell_type":"code","source":"# display an image from the stage_1_test collection\ndef display_image(image_id):\n    #archive = zipfile.ZipFile('../input/stage_1_test_images.zip', 'r')\n    #imgdata = archive.read('{}.jpg'.format(image_id))\n\n    with open('../input/stage_1_test_images/{}.jpg'.format(image_id), 'rb') as f:\n        imgdata = f.read()\n    \n    imgdata = np.asarray(\n            bytearray(imgdata)\n            , dtype=np.uint8)\n\n    img = cv2.imdecode(imgdata, 1)\n    #img = cv2.imread(imgdata, 1)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) \n\n    plt.imshow(img)\n    plt.axis('off')\n    plt.show()\n    \ndisplay_image('395076764176457a63324d3d')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4fd3175fc9cc337631943a9e19fe4d87a0a0e9e9"},"cell_type":"code","source":"df_tuning_labels = pd.read_csv('../input/tuning_labels.csv', index_col=0, header=None, names=['image_id', 'labels'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"271df74047a469489dbe4981df1ff74c4a85d63b"},"cell_type":"code","source":"df_tuning_labels.head(3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b56380b1d6892f0f26687d025611e5ded4d2edfc"},"cell_type":"code","source":"for row, data in df_tuning_labels.head(3).iterrows():\n    display_image(row)\n    print(df_classes_descriptions.loc[data['labels'].split(), :])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fdcac54df68c8af5a478ec7778b9a882c028cd81"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.6.6"}},"nbformat":4,"nbformat_minor":1}