{"cells":[{"metadata":{"_uuid":"0d7a3ae12d0b3f3caddf607ce1ae7f5b719d1034"},"cell_type":"markdown","source":"Run locally because we don't have enough disk space on Kernel :("},{"metadata":{"trusted":true,"_uuid":"bca6a42b943effc2cbeb6c14b1f2c8e873407398"},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom scipy.misc import imread\nfrom tqdm import tqdm\nimport cv2\nfrom skimage.transform import resize\nimport os\nfrom sklearn.model_selection import train_test_split\nfrom matplotlib import pyplot as plt\nimport gc","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"01b25e6e6a23deebc88bd47be907a9714d1e6130"},"cell_type":"code","source":"gc.enable()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"05203db5071c5d07ad5c17642bdd69bffe9d55c6"},"cell_type":"code","source":"INPUT_PATH = '../input/'\nTRAIN_PATH = INPUT_PATH + 'train/'\nTEST_PATH = INPUT_PATH + 'test/'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8967146a8b1c8ddc5619e93b53b61fafd16b0aef"},"cell_type":"code","source":"data = pd.read_csv(INPUT_PATH+\"train.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0a2c3a9bc2e41e72d286739a934253c1fdbf12f4"},"cell_type":"code","source":"# https://www.kaggle.com/iafoss/pretrained-resnet34-with-rgby-0-460-public-lb#\ndef open_rgby(path, id_): #a function that reads RGBY image\n    colors = ['red','green','blue','yellow']\n    flags = cv2.IMREAD_GRAYSCALE\n    img = [cv2.imread(os.path.join(path, id_ + '_' + color + '.png'), flags).astype(np.float32) / 255\n           for color in colors]\n    return np.stack(img, axis=-1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6734338fc85a2ef86ac511d076c9a5144ab5e47f"},"cell_type":"code","source":"!mkdir train_4channel","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7c296ba1ed6f33209954fe500013fdfe33373d25"},"cell_type":"code","source":"for idx in tqdm(data.Id.values):\n    data = open_rgby(TRAIN_PATH, idx)\n    with open(\"./train_4channel/\"+idx+\".npz\", 'wb') as f:\n        #np.save(f, data)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6225e7b6811018e818c0fe82abadfad9998e9190"},"cell_type":"code","source":"import glob\ntest_files = glob.glob(TEST_PATH + \"*.png\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"36ff3433b7d833c1db2be8de6af8496d8967943a"},"cell_type":"code","source":"test_ids = list(set([x[13:].split(\"_\")[0] for x in test_files]))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"6f98fae6a96208e376e3c0ac520391ae3c954a93"},"cell_type":"code","source":"!mkdir test_4channel","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"25d8d82871f778932c3f66485576136b16160ff5"},"cell_type":"code","source":"for idx in tqdm(test_ids):\n    data = open_rgby(TEST_PATH, idx)\n    with open(\"./test_4channel/\"+idx+\".npz\", 'wb') as f:\n        #np.save(f, data)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}