{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Main task: \n> to create dataset with colored images (there are many single channeled black and white images in this dataset)\n\n> @init27 thanks for idea\n\n## ImportingLibraries ","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"markdown","source":"# before after results actual whale\n# Discussion link:https://www.kaggle.com/c/happy-whale-and-dolphin/discussion/306742\n<!-- ![image.png](attachment:c3a0cf21-d669-41cf-aa82-6cd3738af639.png)\n![image.png](attachment:d4aad330-0592-4cbc-836e-f763b8506d1f.png) -->","metadata":{}},{"cell_type":"code","source":"import pandas as pd \nimport numpy as np \nimport matplotlib.pyplot as plt \nimport seaborn as sns\nimport os \nimport sys \n","metadata":{"execution":{"iopub.status.busy":"2022-02-13T18:34:50.550971Z","iopub.execute_input":"2022-02-13T18:34:50.551344Z","iopub.status.idle":"2022-02-13T18:34:51.537209Z","shell.execute_reply.started":"2022-02-13T18:34:50.551235Z","shell.execute_reply":"2022-02-13T18:34:51.536381Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## setting up DeOldify \ngithub repo: https://github.com/jantic/DeOldify","metadata":{}},{"cell_type":"code","source":"!git clone https://github.com/jantic/DeOldify.git \nsys.path.append(\"./DeOldify\")","metadata":{"execution":{"iopub.status.busy":"2022-02-13T18:34:52.997958Z","iopub.execute_input":"2022-02-13T18:34:52.998772Z","iopub.status.idle":"2022-02-13T18:34:57.074374Z","shell.execute_reply.started":"2022-02-13T18:34:52.998711Z","shell.execute_reply":"2022-02-13T18:34:57.073651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from deoldify import device\nfrom deoldify.device_id import DeviceId\ndevice.set(device=DeviceId.GPU0)","metadata":{"execution":{"iopub.status.busy":"2022-02-13T18:35:47.935323Z","iopub.execute_input":"2022-02-13T18:35:47.93567Z","iopub.status.idle":"2022-02-13T18:35:47.943915Z","shell.execute_reply.started":"2022-02-13T18:35:47.935636Z","shell.execute_reply":"2022-02-13T18:35:47.943317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install -r ./DeOldify/colab_requirements.txt\nimport fastai\nfrom deoldify.visualize import *\nimport warnings\nwarnings.filterwarnings(\"ignore\", category=UserWarning, message=\".*?Your .*? set is empty.*?\")","metadata":{"execution":{"iopub.status.busy":"2022-02-13T18:35:52.160966Z","iopub.execute_input":"2022-02-13T18:35:52.161277Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir 'models'\n!wget https://data.deepai.org/deoldify/ColorizeArtistic_gen.pth -O ./models/ColorizeArtistic_gen.pth","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"colorizer = get_image_colorizer(artistic=True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir train_imgs\ntrain_imgs = os.listdir(\"../input/happy-whale-and-dolphin/train_images\")\ntrain_imgs = np.array(train_imgs)\nbw_img = np.array([])\nfrom tqdm.notebook import tqdm \nfor i in tqdm(train_imgs):\n    img = plt.imread(f\"../input/happy-whale-and-dolphin/train_images/{i}\")\n    if len(img.shape)!=3 :\n        image= colorizer.get_transformed_image(path = f\"../input/happy-whale-and-dolphin/train_images/{i}\", render_factor = 40 , watermarked = False)\n        image.save(\"./train_imgs/\"+i)\n        bw_img = np.append(bw_img,f\"../input/happy-whale-and-dolphin/train_images/{i}\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.save('train_bw', bw_img)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir test_imgs\ntest_imgs = np.array(os.listdir(\"../input/happy-whale-and-dolphin/test_images\"))\n\nbw_img_test = np.array([])\nfrom tqdm.notebook import tqdm \nfor i in tqdm(test_imgs):\n    img = plt.imread(f\"../input/happy-whale-and-dolphin/test_images/{i}\")\n    if len(img.shape)!=3 :\n        image= colorizer.get_transformed_image(path = f\"../input/happy-whale-and-dolphin/test_images/{i}\", render_factor = 40 , watermarked = False)\n        image.save(\"./test_imgs/\"+i)\n        bw_img_test= np.append(bw_img_test,f\"../input/happy-whale-and-dolphin/test_images/{i}\")","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.save('test_bw', bw_img_test)","metadata":{},"execution_count":null,"outputs":[]}]}