{"cells":[{"metadata":{"trusted":true,"_uuid":"027a11aaf6634ae5bc7100b913644f993dc500a7"},"cell_type":"code","source":"import numpy as np\nimport pandas as pd \nimport cv2\nimport seaborn as sns\n\nfrom matplotlib import pyplot as plt\n%matplotlib inline\n\n## load two csv files\ndf = pd.read_csv('../input/tuning_labels.csv', header=None, \n                 names=['img_id', 'labels'])\ndescription = pd.read_csv('../input/class-descriptions.csv')\n\n## make a dictionary file\nd={}\nfor i,j in zip(description.label_code.values, description.description.values):\n    d[i]=j","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"946b57b5e5adb668afaec9d9238a2f2331ee10c6"},"cell_type":"code","source":"count = pd.DataFrame(df['labels'].str.split().apply(lambda x:len(x)))\nsns.countplot(data=count,x='labels')\nplt.title('number of labels')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"daaff083d62a56f3eef986e262e40e7ed2bf9cc3"},"cell_type":"markdown","source":"> ## Images with more than 6 labels"},{"metadata":{"trusted":true,"_uuid":"e319e309059fe58d15fe1c3f0acd5f4060f4bbaa"},"cell_type":"code","source":"temp = df[count['labels']>6]\nlist = ['../input/stage_1_test_images/{}.jpg'.format(img_id) for img_id in temp.img_id.values]\nax=plt.figure(figsize=(12,12))\nfor num,i in enumerate(temp['labels'].apply(lambda x: x.split()).values):\n    plt.subplot(3,2,2*num+1)\n    plt.axis('off')\n    filename = list[num]\n    img = cv2.imread(filename)\n    plt.imshow(img)\n    names = [d[j] for j in i]\n    for n,i in enumerate(names):\n        plt.text(1500,10+n*100,i,fontsize=14,horizontalalignment='right')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0af83654efa420024ab3fb9f4063cff51919ad26","collapsed":true},"cell_type":"code","source":"## create a function called \"plot_images\"\ndef plot_images(num_label,max=60):\n    temp = df[count['labels']==num_label]\n    print(len(temp))\n    if len(temp) > 60:\n        temp = temp[:60]\n    list = ['../input/stage_1_test_images/{}.jpg'.format(img_id) for img_id in temp.img_id.values]\n    ax=plt.figure(figsize=(12,60))\n    for num,i in enumerate(temp['labels'].apply(lambda x: x.split()).values):\n        filename = list[num]\n        img = cv2.imread(filename)\n        img = cv2.resize(img, dsize=(1024, 600), interpolation=cv2.INTER_CUBIC)\n        plt.subplot(30,4,2*num+1)\n        plt.axis('off')\n        plt.imshow(img)\n        names = [d[j] for j in i]\n        for n,i in enumerate(names):\n            plt.text(1500,10+n*100,i,fontsize=10,horizontalalignment='left')","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"4929c3feb8d29086444809d54327776d723cbc2d"},"cell_type":"markdown","source":"## Images with 6 labels"},{"metadata":{"trusted":true,"_uuid":"246c04ca5f65c83b47d55d2e59237fe6dfbda65b"},"cell_type":"code","source":"plot_images(6)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c2ad7c2d4d15202f9b49306ebdbd124f3857d524"},"cell_type":"markdown","source":"## Images with 5 labels"},{"metadata":{"trusted":true,"_uuid":"865bcabc798a3ef5ae1a01d7378cf0b8e461085a"},"cell_type":"code","source":"plot_images(5)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c24fdb6e9047a47b1954dac4dfd978effd47970e"},"cell_type":"markdown","source":"## Images with 4 labels"},{"metadata":{"trusted":true,"_uuid":"49e5b2603d22fb7cf16f2fc687897eef7903e576"},"cell_type":"code","source":"plot_images(4)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"34effe33fd7016a03ce2f2ad4d2092c46ff03709"},"cell_type":"markdown","source":"## Images with 3 labels"},{"metadata":{"trusted":true,"_uuid":"6036357c515b288c58b626b9fc785461b23edcd7"},"cell_type":"code","source":"plot_images(3)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"5fac21276e79aa50fe7ebfaf544fa6465c769df7"},"cell_type":"markdown","source":"## Images with 2 labels"},{"metadata":{"trusted":true,"_uuid":"a70863a902f6490f28fa70e2f754332ece8f1ef6"},"cell_type":"code","source":"plot_images(2)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"f51ed0d44b9b93f42753de02db74eaf5627405a0"},"cell_type":"markdown","source":"## Images with only one label!"},{"metadata":{"trusted":true,"_uuid":"13fd888e15087f852d2793fe059ad5b7c93088b6"},"cell_type":"code","source":"plot_images(1)","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}