{"cells":[{"cell_type":"markdown","metadata":{"_cell_guid":"a24e0671-8d6e-4f13-9e2e-29716da3cd01"},"source":"## Data exploration of CCS Kaggle competition\n- User PIL\n- User cv2\n- User Keras, with caution on type conversion (back to uint8)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"f20adca8-0f99-f284-f358-df62665c34a0"},"outputs":[],"source":"import cv2"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"2c7ea6f8-a5be-23f5-f441-0ac1d1ce41ae"},"outputs":[],"source":"img = cv2.imread('../input/test/0.jpg')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"3b212c65-2196-a058-be8e-5d020fd25750"},"outputs":[],"source":"img.shape"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"a5095f98-a0e9-649e-5ff7-a50b040553e3"},"outputs":[],"source":"from keras.preprocessing import image"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"98f2bd82-0e52-ed83-6b90-2c9cb9f8c70e"},"outputs":[],"source":"img=image.load_img('../input/additional/Type_1/5893.jpg')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"628d41e2-1279-14bb-5aa3-4175211eea61"},"outputs":[],"source":"img = image.img_to_array(img)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"dd578272-d7f6-1ac5-c919-5f5b3c47fe78"},"outputs":[],"source":"import numpy as np\nnp.histogram(img)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"247dc21d-3897-30b4-11ff-acda31b5ee36"},"outputs":[],"source":"import matplotlib.pyplot as plt"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"dcf4221b-55a4-d635-a379-9527040c0d9a"},"outputs":[],"source":"plt.imshow(img)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"f2730d97-9b03-27ba-8827-27d40a66e829"},"outputs":[],"source":"cv2.imshow('../input/additional/Type_1/5893.jpg')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"6a84767e-7eeb-047b-9bf1-cc03ca6fb34b"},"outputs":[],"source":"img = cv2.imread('../input/additional/Type_1/5893.jpg')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"42408a57-f471-65b6-77c4-eddb2dcef158"},"outputs":[],"source":"type(img)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b40bbeea-1441-43fa-e802-36857ef3a292"},"outputs":[],"source":"cv2.imshow('../input/additional/Type_2/2845.jpg')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"628b3627-401a-3632-fa57-35ae1cff874c"},"outputs":[],"source":"img = cv2.imread('../input/additional/Type_2/2845.jpg')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"2a556df7-c46a-814d-7d53-cb07f79b80ab"},"outputs":[],"source":"type(img)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"84fe806e-fee4-862e-f895-3cae31be4de4"},"outputs":[],"source":"cv2.imshow('../input/additional/Type_2/5892.jpg')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"e28c53bc-c167-68f3-b8dd-54e9a78c14a0"},"outputs":[],"source":"img = cv2.imread('../input/additional/Type_2/5892.jpg')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ba86bb9e-d156-ac8d-7768-835c2b0d5366"},"outputs":[],"source":"type(img)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"3635a7cc-cec8-0223-eceb-548b38d9c2e2"},"outputs":[],"source":"img = image.img_to_array(img).astype('uint8')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"5d64f894-c93c-e9b5-b51e-11c57cd4a2b0"},"outputs":[],"source":"type(img)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"c5367678-529c-ee0b-b81f-604852538005"},"outputs":[],"source":"img.shape"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"e85081e7-6c1d-b70e-2cbb-ed81c0b2e78b"},"outputs":[],"source":"plt.imshow(img)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"e9203a81-f9fb-78bb-d200-4497fb258fc6"},"outputs":[],"source":"img.min(),img.max(),img.dtype"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"aee91520-d3e2-8e13-0ee6-27b640814422"},"outputs":[],"source":"plt.imshow(img.astype('uint8'))"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"0f2bfbac-7079-ed26-4ca9-469843be0c98"},"outputs":[],"source":"## Previous version"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"757c23ec-cec3-b435-d42a-2ad735441750"},"outputs":[],"source":"import os"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"eeec7424-f5b0-1837-7a4f-8787ae0ca36b"},"outputs":[],"source":"test_files = os.listdir('../input/test/')\nlen(test_files)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"3d3ed5fd-b10b-3105-4ad2-8aefe9d3c5b4"},"outputs":[],"source":"import PIL\nimport numpy as np"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"7cc6ca17-9c87-0f77-25e1-ba9a981b6477"},"outputs":[],"source":"#plt.imshow('../input/test/0.jpg') # Doesn't work directly"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"f69841b9-a807-0a65-b142-b45025cfd175"},"outputs":[],"source":"def read_jpg(path):\n    return np.asarray(PIL.Image.open(path),dtype=np.uint8)    "},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"650b45aa-1741-5679-86f2-ab58e7d377e9"},"outputs":[],"source":"img = read_jpg('../input/test/0.jpg')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"6ef8a19c-519d-825e-c9b8-85cd7b148054"},"outputs":[],"source":"plt.imshow(img)"},{"cell_type":"markdown","metadata":{"_cell_guid":"ad9ba934-5ed7-24ef-d9b6-0ef65f362a77"},"source":"### Noticeable difference in resolution"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"bfc1c318-f680-9289-898b-0876439aa2b8"},"outputs":[],"source":"img.shape"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"c82d730b-20a7-4af8-c9a0-7eb0b61abd32"},"outputs":[],"source":"img = read_jpg('../input/test/19.jpg')\nimg.shape"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ec73af86-3831-d16f-4b0c-572c7d5a8188"},"outputs":[],"source":"img.dtype"},{"cell_type":"markdown","metadata":{"_cell_guid":"b06196cc-918c-93fd-6898-45075e97261a"},"source":"Note the exceptional resolution in test files\n<pre>\n11 107.jpg (640, 480, 3)\n</pr"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"b3297cc1-59dc-6ae3-2c3c-fa48fda0beb0"},"outputs":[],"source":"for j,f in enumerate(test_files):\n    if 'jpg' in f:\n        img = read_jpg('../input/test/'+f)\n        print(j,f,img.shape)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"191fff8e-6155-cfaa-4aef-d5ec63446219"},"outputs":[],"source":"plt.imshow(read_jpg('../input/test/1.jpg'))"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ad2172dd-6be2-6ae2-9360-47a83a478d0e"},"outputs":[],"source":"plt.imshow(read_jpg('../input/test/2.jpg'))"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"7335051f-b600-c7bb-bb4c-00a8936960a6"},"outputs":[],"source":"plt.imshow(read_jpg('../input/test/3.jpg'))"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"557b16d8-2881-0ca9-14e1-58e85ef061e7"},"outputs":[],"source":"os.listdir('../input/additional')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ec6eff36-0a6d-483d-7a5b-4fe13bfb46b7"},"outputs":[],"source":"os.listdir('../input/train/')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"49c3f788-f155-d019-3864-6d59a0942cd0"},"outputs":[],"source":"import pandas as pd\nsubm = pd.read_csv('../input/sample_submission.csv')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"0e05b300-3d04-fafe-1bb9-657232294242"},"outputs":[],"source":"subm.columns"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"32e8c916-61fd-2b22-ce02-7bc6ed67c2c4"},"outputs":[],"source":"subm.head()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"6246d480-73ba-d914-6910-dbf3bcecf1da"},"outputs":[],"source":"0.168805\t+ 0.527346\t+ 0.303849"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"c54f5f1a-ac60-46c0-5894-a82c89505884"},"outputs":[],"source":"subm.shape"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"d72b66e2-5330-b4a8-cac6-32d924daea2e"},"outputs":[],"source":"os.listdir('./')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"e4b77a5a-281d-f733-6ec8-2ed24e7ae384"},"outputs":[],"source":"os.listdir('..')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"f7d61d91-286a-01e6-e094-a47b2f526ed5"},"outputs":[],"source":"os.getcwd()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"57e30744-f9ee-b3a6-675b-704ce2dc155e"},"outputs":[],"source":"os.listdir('../config')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"ba77a3fb-82c9-8737-3f68-efae6902516e"},"outputs":[],"source":"os.listdir('../lib')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"10126a9d-48bf-e365-ce33-dc7f3647999f"},"outputs":[],"source":"[x for x in test_files if 'jpg' not in x]"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"896436a4-6a73-76c4-16c1-697c48437dbb"},"outputs":[],"source":""}],"metadata":{"_change_revision":0,"_is_fork":false,"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.0"}},"nbformat":4,"nbformat_minor":0}