{"cells":[{"cell_type":"markdown","metadata":{"_cell_guid":"ebdc6cc5-cd4c-f13f-1b85-985976b3d1a4"},"source":"Nah"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"706ab111-fa19-f5ed-cc09-5603836f2f57"},"outputs":[],"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 cPickle as pk\nimport pandas as pd\nimport numpy as np\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\n\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"0bb7e7b6-b5a4-6e64-1f3c-a5d1fe2f8090"},"outputs":[],"source":"%matplotlib inline\nimport matplotlib.pyplot as plt\nplt.style.use('ggplot')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"5213d1d8-59ae-0d81-6434-d09b3c639193"},"outputs":[],"source":"from subprocess import check_output\nprint(check_output([\"ls\", \"../input/train/Type_1/10.jpg\"]).decode(\"utf8\"))"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"918c4323-30a4-52e3-c951-6f7c0426a071"},"outputs":[],"source":"from glob import glob\n\ndef make_base_df():\n    base_path = '../input/train'\n    image_paths = []\n    for type_base_path in sorted(glob(base_path +'/*')):\n        image_paths = image_paths + glob(type_base_path + '/*')\n    df = pd.DataFrame({'path':image_paths})\n    df['type'] = df.path.map(lambda x: x.split('/')[-2])\n    df['filetype'] = df.path.map(lambda x: x.split('.')[-1])\n    df['num_id'] = df.path.map(lambda x:x.split('/')[-1].split('.')[0])\n    return df\n\ndf = make_base_df(); df.head()"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"e46fe469-4e46-fb0a-ad77-7ef738c712ed"},"outputs":[],"source":"from skimage.io import imread, imshow\ni=0\nimg_path = df.path[i]\nprint(img_path)\nimg = plt.imread(img_path)\n#def show_image_for_path(path):\nprint(img.shape)\nprint(img)\nplt.imshow(img)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"c3e858d7-112d-7efa-c3e0-b911a527e7fb"},"outputs":[],"source":"from skimage.io import imread, imshow\ni=6\nimg_path = df.path[i]\nprint(img_path)\nimg = plt.imread(img_path)\n#def show_image_for_path(path):\nprint(img.shape)\nprint(img)\nplt.imshow(img)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"4a509fa8-c6b4-764d-d23a-289fceb7e730"},"outputs":[],"source":"import cv2\n\ndef get_grayscale_img(path, rescale_dim):\n    img = plt.imread(path)\n    rescaled = cv2.resize(img, (rescale_dim, rescale_dim), cv2.INTER_LINEAR)\n    grey = cv2.cvtColor(rescaled, cv2.COLOR_RGB2GRAY).astype('float')\n    normalized = cv2.normalize(grey,None,0,1,cv2.NORM_MINMAX)\n    vec = normalized.reshape(1,np.prod(normalized.shape))\n    return vec/np.linalg.norm(vec)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"34bb55f7-2640-ca1b-667c-bf96b5f8309d"},"outputs":[],"source":"pwd"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"d857418f-1bd9-c4a4-27e5-55499ceafd8c"},"outputs":[],"source":"df['grayscale_vec'] = df.path.map(lambda path: get_grayscale_img(path, 100))"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"a5742bb6-7171-0df3-7ab8-cb3089a7461d"},"outputs":[],"source":"df['num'] = df.path.map(lambda x:x.split('/')[-1].split('.')[0])"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"15d1dd88-3ab5-fa3a-cc32-49fb4900233c"},"outputs":[],"source":"len(df.num.unique())"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"6062988e-1fd7-280b-9113-faed8794776f"},"outputs":[],"source":"len(df.num)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"446157cb-4cc8-eb73-85db-195f8a500857"},"outputs":[],"source":"file = open('dev_sub.csv','w') \n \nfile.write('image_name, Type_1, Type_2, Type_3, Type') \nfile.write('0.jpg, 0.1, 0.3, 0.6, Type_1') \nfile.write('1.jpg, 1, 0.0, 0.0, Type_1') \nfile.write('2.jpg, 0.5, 0.3, 0.2, Type_3') \nfile.write('3.jpg, 0.0, 0.0, 1, Type_2') \n \nfile.close() "},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"fe16e110-bf06-1aec-ece3-548111749d05"},"outputs":[],"source":"def evaluated_test_submission(sub_path):\n    "}],"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}