{"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":70,"outputs":[{"output_type":"stream","text":"['gtsrb_challenge']\n","name":"stdout"}]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train_data = glob.glob('../input/gtsrb_challenge/GTSRB_Challenge/train/*/*.ppm')\ntest_data = glob.glob('../input/gtsrb_challenge/GTSRB_Challenge/test/*.ppm')\nprint(\"Total number of training images: \", len(train_data))\nprint(\"Total number of test images: \", len(test_data))\n","execution_count":71,"outputs":[{"output_type":"stream","text":"Total number of training images:  39209\nTotal number of test images:  12630\n","name":"stdout"}]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data = pd.Series(train_data)\ntest_data = pd.Series(test_data)\n","execution_count":72,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# train_df: a dataframe with 2 field: Filename, ClassId\ntrain_df = pd.DataFrame()\n# generate Filename field\ntrain_df['Filename'] = train_data.map(lambda img_name: img_name.split(\"/\")[-1])\n# generate ClassId field\ntrain_df['ClassId'] = train_data.map(lambda img_name: int(img_name.split(\"/\")[-2]))\ntrain_df.head()","execution_count":73,"outputs":[{"output_type":"execute_result","execution_count":73,"data":{"text/plain":"          Filename  ClassId\n0  00020_00006.ppm       15\n1  00010_00002.ppm       15\n2  00008_00025.ppm       15\n3  00011_00021.ppm       15\n4  00004_00018.ppm       15","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Filename</th>\n      <th>ClassId</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>00020_00006.ppm</td>\n      <td>15</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>00010_00002.ppm</td>\n      <td>15</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>00008_00025.ppm</td>\n      <td>15</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>00011_00021.ppm</td>\n      <td>15</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>00004_00018.ppm</td>\n      <td>15</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"# train_df: a dataframe with 2 field: Filename, ClassId\ntest_df = pd.DataFrame()\n\n# generate Filename field\ntest_df['Filename'] = test_data.map(lambda img_name: img_name.split(\"/\")[-1])\n\n\n\n# print(test_df)\n\ntest_df.head()","execution_count":74,"outputs":[{"output_type":"execute_result","execution_count":74,"data":{"text/plain":"                 Filename\n0   1558973073.859722.ppm\n1  1558973073.8829477.ppm\n2   1558973073.892149.ppm\n3   1558973073.871112.ppm\n4     1558973073.8769.ppm","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Filename</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1558973073.859722.ppm</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1558973073.8829477.ppm</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1558973073.892149.ppm</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1558973073.871112.ppm</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1558973073.8769.ppm</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{"trusted":true},"cell_type":"code","source":"X_train, y_train = train_df['Filename'], train_df['ClassId']\nX_test = test_df['Filename'] ","execution_count":75,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Number of training examples\nn_train = len(X_train)\nprint(n_train)\n\n#  Number of testing examples.\nn_test = len(X_test)\nprint(n_test)","execution_count":76,"outputs":[{"output_type":"stream","text":"39209\n12630\n","name":"stdout"}]},{"metadata":{"trusted":true},"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.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}