{"cells":[{"metadata":{},"cell_type":"markdown","source":"## Imports "},{"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)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport json\nimport cv2\n\nimport torch\nimport torch.utils.data as data\nimport torchvision\nimport torchvision.utils as utils\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\n# print(os.listdir(\"../input/train/\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_csv_path = \"../input/train.csv\"\ntrain_path = \"../input/train\"\ntest_path = \"../input/test\"\ntrain_names = os.listdir(train_path)\ntest_names = os.listdir(test_path)\n\nSIZE = (512, 512)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"# trdf = pd.read_csv(train_csv_path)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# trdf.ClassId.value_counts()[trdf.ClassId.value_counts() > 20]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"trdf.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pixels_example = trdf.EncodedPixels.values[0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"fig, ax = plt.subplots(1, 2)\nfig.set_size_inches((12, 4))\nax[0].hist(trdf.Height);\nax[1].hist(trdf.Width);","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img = plt.imread(train_path + train_names[0])\nplt.imshow(img);","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"markdown","source":"## Data loader"},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Utils"},{"metadata":{"trusted":true},"cell_type":"code","source":"def img_generator(img_dir):\n    img_names = os.listdir(img_dir)\n    for name in img_names:\n        img_p = os.path.join(img_dir, name)\n        yield plt.imread(img_p), name\n        \ndef resize_imgs(imgs_dir, target_size, out_dir):\n    os.makedirs(out_dir, exist_ok=True)\n    imgs_gen = img_generator(imgs_dir)\n    for i, (img, name) in enumerate(imgs_gen):\n        if i % 100 == 0:\n            print(i)\n        resized = cv2.resize(img, target_size, cv2.INTER_CUBIC)\n        plt.imsave(os.path.join(out_dir, name), resized)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true},"cell_type":"code","source":"# resize test\n# resize_imgs(test_path, SIZE, \"test_512\")\nresize_imgs(train_path_path, SIZE, \"train_512\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"len(test_names)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"os.makedirs(\"test_resize\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"os.listdir(\".\")\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"rm \"test_resize/\" -r\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"im_p = test_path +\"/\" + test_names[233]\nimg = plt.imread(im_p)\nplt.imsave(\"test.jpg\", img)\n# plt.imshow(img)","execution_count":14,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df = pd.DataFrame([1, 1, 1])\ndf.to_csv(\"test.model\")","execution_count":16,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ls","execution_count":17,"outputs":[{"output_type":"stream","text":"__notebook_source__.ipynb  test.csv  test.jpg  test.model\r\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}