{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"os.listdir(\"../input\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"b8d38842555711f66efd11aa2cef0ab55cd1358d"},"cell_type":"markdown","source":"### classes-trainable.csv"},{"metadata":{"trusted":true,"_uuid":"742c2a78ec2694a553bc8c52f0c1beadfe31175c"},"cell_type":"code","source":"df_classes_trainable = pd.read_csv(\"../input/classes-trainable.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"379cc7b6083ff9e631ff47f87dae1b2475213fd8"},"cell_type":"code","source":"df_classes_trainable.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"72ec88d235c957baf0abfb24f68e41f51a068704"},"cell_type":"code","source":"df_classes_trainable.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2160fb5cc085dc04a1ac7d13e5d17c850e79950c"},"cell_type":"code","source":"df_classes_trainable.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"366c512d94207e0e35ae2b831f67828c23be48c5"},"cell_type":"markdown","source":"### train_human_labels.csv"},{"metadata":{"trusted":true,"_uuid":"d1a5b39596a95b5ef67160befe2612b1223e2c94"},"cell_type":"code","source":"df_train_human_labels = pd.read_csv(\"../input/train_human_labels.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0af43e64d4aee7681afb70919e84b2724552a096"},"cell_type":"code","source":"df_train_human_labels.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"62d61d1ab3119632d297cac89f26f75ab1d63334"},"cell_type":"code","source":"df_train_human_labels.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fb6cd19a0919c40138db11daf0d3ebd9246c7d68"},"cell_type":"code","source":"df_train_human_labels.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"23a185caa2f69850d55c0481ba639a68a626d539"},"cell_type":"markdown","source":"### stage_1_sample_submission.csv"},{"metadata":{"trusted":true,"_uuid":"46cb680554eff0c888f823fffc718d7ac9f8a46b"},"cell_type":"code","source":"df_stage_1_sample_submission = pd.read_csv(\"../input/stage_1_sample_submission.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8c69237efe4efdcebf3b9367c6426c9bbcef48c2"},"cell_type":"code","source":"df_stage_1_sample_submission.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3fa0ea29faf0337e1b2706d743e405b8902d5e3a"},"cell_type":"code","source":"df_stage_1_sample_submission.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4e4ce91f04eb5e6f98910c1302f1a09a6388c184"},"cell_type":"code","source":"df_stage_1_sample_submission.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"68f09fcdfc9a4fa3525e2dd45365de3c48d853e5"},"cell_type":"markdown","source":"### tuning_labels.csv"},{"metadata":{"trusted":true,"_uuid":"960e5c8be7987179c3ce8b546ecfa2d3806ac461"},"cell_type":"code","source":"df_tuning_labels = pd.read_csv(\"../input/tuning_labels.csv\", header=None, names=['id', 'labels'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fef44ab2d6ad5d7d8bb46c426e003f1b5b80814d"},"cell_type":"code","source":"df_tuning_labels.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4ed1cd93775bc949e56ce0f4fc743aaaaf1505b7"},"cell_type":"code","source":"df_tuning_labels.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"dad15ab0af5ca219a81c6674eed818516399b6e7"},"cell_type":"code","source":"df_tuning_labels.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"76788a0de8811ab5e75902815c045b8e4878d75c"},"cell_type":"markdown","source":"### stage_1_attributions.csv"},{"metadata":{"trusted":true,"_uuid":"a36608315dbaae4183afc767f381893fb319abf3"},"cell_type":"code","source":"df_stage_1_attributions = pd.read_csv(\"../input/stage_1_attributions.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8a50b52ac781772e14b5008f45804b98f4fe577d"},"cell_type":"code","source":"df_stage_1_attributions.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a94fdc332e79ce4e85e51195b424c78172bb01bf"},"cell_type":"code","source":"df_stage_1_attributions.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4503346c156634a2b13fc3a1517bd0c2cd1f1f5d"},"cell_type":"code","source":"df_stage_1_attributions.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"bbeb31457a73117ad43649d46033b942a1217ba2"},"cell_type":"markdown","source":"### train_bounding_boxes.csv"},{"metadata":{"trusted":true,"_uuid":"2802e1a25a7fc6feb9c6172362975980f3415b47"},"cell_type":"code","source":"df_train_bounding_boxes = pd.read_csv(\"../input/train_bounding_boxes.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7110fbcdc25b0caeae618d3de00fedd2e6a45cb9"},"cell_type":"code","source":"df_train_bounding_boxes.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"353c363094dc45111e938411bfdc662ee4b62f40"},"cell_type":"code","source":"df_train_bounding_boxes.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"3dfdb1f0b117a44869506e01e24ca85786ae05b8"},"cell_type":"code","source":"df_train_bounding_boxes.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"2d424c3f0597e6cac6de4240f58c9888a1363e2b"},"cell_type":"markdown","source":"### class-descriptions.csv"},{"metadata":{"trusted":true,"_uuid":"f81d75a5d9d5051066e4fbd3e83509ba8f6c50a9"},"cell_type":"code","source":"df_class_descriptions = pd.read_csv(\"../input/class-descriptions.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4bc9d9305092c7a23bf9861a7759ac7ba69f2287"},"cell_type":"code","source":"df_class_descriptions.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"91bed1c753e97f34471d7c6c14a1a685162e81af"},"cell_type":"code","source":"df_class_descriptions.description","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0703b02a2d4bfd05c165b9a10958cfbaf159d8e3"},"cell_type":"code","source":"df_class_descriptions.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f9cad71d52f87a9f9aca53a0eaae787da6fcea91"},"cell_type":"code","source":"df_class_descriptions.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"23de261f58855ac4a179abc30871383e2a9ae09b"},"cell_type":"markdown","source":"### train_machine_labels.csv"},{"metadata":{"trusted":true,"_uuid":"00217f723fd7a6587ea29fb734240069dd75ef6d"},"cell_type":"code","source":"df_train_machine_labels = pd.read_csv(\"../input/train_machine_labels.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"357a26cf19102a907ed6f04d97138a51bbfcb168"},"cell_type":"code","source":"df_train_machine_labels.describe()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c4d1a9cc293d0ad3b34570fa30382f6aa6d5ab6d"},"cell_type":"code","source":"df_train_machine_labels.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7c815853d1ee05757c03515c1a972597777e5109"},"cell_type":"code","source":"df_train_machine_labels.shape","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c29c3304097d4b5b6d6f684eca14161d42964687"},"cell_type":"markdown","source":"###  Display some Test Images"},{"metadata":{"trusted":true,"_uuid":"bc97706ad1c0384cd7ebe97b8ef3c160b0a011a3"},"cell_type":"code","source":"import cv2\nfrom matplotlib import pyplot as plt\n%matplotlib inline\n\nm_labels = df_tuning_labels.labels.str.split().tolist()\n#print(m_labels)\n# get the descriptions and translate\nmap_label_to_des = dict(zip(df_class_descriptions.label_code.values, df_class_descriptions.description.values))\nnum_of_imgs = 16\ndes_labels = []\nfor i in np.arange(num_of_imgs):\n    j = [map_label_to_des.get(item, item) for item in m_labels[i]]\n    des_labels.append(j)\n    \n# pull images and plot\nimg_list = ['../input/stage_1_test_images/{}.jpg'.format(id_) for id_ in df_tuning_labels.id.values]\nfig, ax = plt.subplots()\nfig.set_size_inches(25, 25)\nax.set_axis_off()\nfor n, (image, label) in enumerate(zip(img_list, des_labels)):\n    a = fig.add_subplot(num_of_imgs//4, num_of_imgs//4, n+1)\n    img = cv2.imread(image, 1)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n    plt.axis('off')\n    plt.title(label, fontsize=15)\n    plt.imshow(img)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"adb0c48d912655676fa4ace3a1ad8df50b470d98"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"45225859a8e40d7db7b5d9f824b09f3b0e02af72"},"cell_type":"code","source":"count = pd.DataFrame(df_tuning_labels['labels'].str.split().apply(lambda x: len(x)))\nprint(count)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bf609a4dd727ea4d8dc1c68f958ba2a3e984d367"},"cell_type":"code","source":"import seaborn as sns\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\nsns.countplot(data=count, x='labels')\nplt.title(\"number of labels\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ed40e7fc8026b92aea91c2fac7a5ff49ffb8e079"},"cell_type":"code","source":"# tmp = df_tuning_labels[count['labels'] > 7]\n# tmp['labels'].apply(lambda x: x.split()).values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a7622635259fa3ba95352c8ecb7408de2e231248"},"cell_type":"markdown","source":"## Images with more than 7 labels"},{"metadata":{"trusted":true,"_uuid":"4e4fca40b07c158910c16be0ca1f791833ecc013"},"cell_type":"code","source":"## make a dictionary file\nd={}\nfor i,j in zip(df_class_descriptions.label_code.values, df_class_descriptions.description.values):\n    d[i]=j","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"56ec253aef5e8480556e7669434dfb5624c6aa98"},"cell_type":"code","source":"d","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"694a67bfb697c6efd964418a541920fb76cace3d"},"cell_type":"code","source":"tmp = df_tuning_labels[count['labels'] > 6]\nmy_list = ['../input/stage_1_test_images/{}.jpg'.format(img_id) for img_id in tmp.id.values]\n\nax = plt.figure(figsize=(12, 12))\nfor num, i in enumerate(tmp['labels'].apply(lambda x: x.split()).values):\n    plt.subplot(3,2, 2*num + 1)\n    plt.axis('off')\n    #print(num)\n    file_name = my_list[num]\n    img = cv2.imread(file_name)\n    plt.imshow(img)\n    \n    names = [d[j] for j in i]\n    print(names)\n    \n    for n, i in enumerate(names):\n        plt.text(1500,10+n*100, i, fontsize = 14, horizontalalignment='right')\n        ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"552013b30895f78214ab057eba012cb3feda6630"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}