{"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":"## Import Necessary Libraries","metadata":{}},{"cell_type":"code","source":"import tensorflow_hub as hub\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport tensorflow as tf","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-06-22T01:36:07.786679Z","iopub.execute_input":"2021-06-22T01:36:07.787189Z","iopub.status.idle":"2021-06-22T01:36:14.381098Z","shell.execute_reply.started":"2021-06-22T01:36:07.787084Z","shell.execute_reply":"2021-06-22T01:36:14.380079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Load pre-trained model","metadata":{}},{"cell_type":"code","source":"model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:36:14.382938Z","iopub.execute_input":"2021-06-22T01:36:14.383366Z","iopub.status.idle":"2021-06-22T01:36:18.757801Z","shell.execute_reply.started":"2021-06-22T01:36:14.383319Z","shell.execute_reply":"2021-06-22T01:36:18.756765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### function to load image and display","metadata":{}},{"cell_type":"code","source":"def load_image(img_path):\n    img = tf.io.read_file(img_path)\n    img = tf.image.decode_image(img, channels = 3)\n    img = tf.image.convert_image_dtype(img, tf.float32)\n    img = img[tf.newaxis , :]\n    return img","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:48:47.456132Z","iopub.execute_input":"2021-06-22T01:48:47.456653Z","iopub.status.idle":"2021-06-22T01:48:47.462802Z","shell.execute_reply.started":"2021-06-22T01:48:47.456610Z","shell.execute_reply":"2021-06-22T01:48:47.461416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot(content_image, style_image):\n    plt.figure(figsize = (10,10))\n    plt.subplot(1,2,1)\n    plt.title(\"content_image\",size = 16)\n    plt.imshow(np.squeeze(content_image))\n    plt.axis('off')\n    plt.subplot(1,2,2)\n    plt.title(\"style_image\",size = 16)\n    plt.imshow(np.squeeze(style_image))\n    plt.axis('off')\n    plt.show()\n \ndef plot_pair(content_image, style_image, stylized_image):\n    plt.figure(figsize = (17,10))\n    plt.subplot(1,3,1)\n    plt.title(\"content_image\",size = 16)\n    plt.imshow(np.squeeze(content_image))\n    plt.axis('off')\n    plt.subplot(1,3,2)\n    plt.title(\"style_image\",size = 16)\n    plt.imshow(np.squeeze(style_image))\n    plt.axis('off')\n\n    plt.subplot(1,3,3)\n    plt.title(\"stylized_image\",size = 16)\n    plt.imshow(np.squeeze(stylized_image))\n    plt.axis('off')\n    plt.show()\n    \n","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:48:47.678014Z","iopub.execute_input":"2021-06-22T01:48:47.678410Z","iopub.status.idle":"2021-06-22T01:48:47.689463Z","shell.execute_reply.started":"2021-06-22T01:48:47.678380Z","shell.execute_reply":"2021-06-22T01:48:47.687881Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Plotting  images","metadata":{}},{"cell_type":"code","source":"content_image = load_image('../input/gan-getting-started/photo_jpg/00e1798585.jpg')\nstyle_image = load_image('../input/gan-getting-started/monet_jpg/184d6c66cd.jpg')\nplot(content_image,style_image)\nprint(\"====\"*38)\nstylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]\nplot_pair(content_image,style_image,stylized_image)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:48:49.932910Z","iopub.execute_input":"2021-06-22T01:48:49.933336Z","iopub.status.idle":"2021-06-22T01:48:51.730783Z","shell.execute_reply.started":"2021-06-22T01:48:49.933297Z","shell.execute_reply":"2021-06-22T01:48:51.729903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"content_image = load_image('../input/gan-getting-started/photo_jpg/00dcf0f1e3.jpg')\nstyle_image = load_image('../input/gan-getting-started/monet_jpg/118da0690c.jpg')\nplot(content_image,style_image)\nstylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]\nplot_pair(content_image,style_image,stylized_image)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:49:05.889935Z","iopub.execute_input":"2021-06-22T01:49:05.890321Z","iopub.status.idle":"2021-06-22T01:49:07.319506Z","shell.execute_reply.started":"2021-06-22T01:49:05.890286Z","shell.execute_reply":"2021-06-22T01:49:07.318855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"content_image = load_image('../input/gan-getting-started/photo_jpg/003aab6fdd.jpg')\nstyle_image = load_image('../input/gan-getting-started/monet_jpg/17557a29cb.jpg')\nplot(content_image,style_image)\nstylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]\nplot_pair(content_image,style_image,stylized_image)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:49:36.471036Z","iopub.execute_input":"2021-06-22T01:49:36.471531Z","iopub.status.idle":"2021-06-22T01:49:37.956427Z","shell.execute_reply.started":"2021-06-22T01:49:36.471500Z","shell.execute_reply":"2021-06-22T01:49:37.952998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"content_image = load_image('../input/gan-getting-started/photo_jpg/023eed0385.jpg')\nstyle_image = load_image('../input/gan-getting-started/monet_jpg/3417ace946.jpg')\nplot(content_image,style_image)\nstylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]\nplot_pair(content_image,style_image,stylized_image)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:50:56.628506Z","iopub.execute_input":"2021-06-22T01:50:56.628968Z","iopub.status.idle":"2021-06-22T01:50:58.138794Z","shell.execute_reply.started":"2021-06-22T01:50:56.628926Z","shell.execute_reply":"2021-06-22T01:50:58.137795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"content_image = load_image('../input/gan-getting-started/photo_jpg/02001e59af.jpg')\nstyle_image = load_image('../input/gan-getting-started/monet_jpg/4260d1c556.jpg')\nplot(content_image,style_image)\nstylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]\nplot_pair(content_image,style_image,stylized_image)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:52:26.288719Z","iopub.execute_input":"2021-06-22T01:52:26.289188Z","iopub.status.idle":"2021-06-22T01:52:27.796860Z","shell.execute_reply.started":"2021-06-22T01:52:26.289150Z","shell.execute_reply":"2021-06-22T01:52:27.795929Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"content_image = load_image('../input/gan-getting-started/photo_jpg/03fe5d2263.jpg')\nstyle_image = load_image('../input/gan-getting-started/monet_jpg/599098859e.jpg')\nplot(content_image,style_image)\nstylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]\nplot_pair(content_image,style_image,stylized_image)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:53:32.000542Z","iopub.execute_input":"2021-06-22T01:53:32.000971Z","iopub.status.idle":"2021-06-22T01:53:33.738345Z","shell.execute_reply.started":"2021-06-22T01:53:32.000936Z","shell.execute_reply":"2021-06-22T01:53:33.737287Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"content_image = load_image('../input/gan-getting-started/photo_jpg/05557b0148.jpg')\nstyle_image = load_image('../input/gan-getting-started/monet_jpg/676a5a4c2e.jpg')\nplot(content_image,style_image)\nstylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]\nplot_pair(content_image,style_image,stylized_image)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:54:16.441221Z","iopub.execute_input":"2021-06-22T01:54:16.441600Z","iopub.status.idle":"2021-06-22T01:54:17.883166Z","shell.execute_reply.started":"2021-06-22T01:54:16.441548Z","shell.execute_reply":"2021-06-22T01:54:17.882182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"content_image = load_image('../input/gan-getting-started/photo_jpg/05e37a8900.jpg')\nstyle_image = load_image('../input/gan-getting-started/monet_jpg/608ee0d370.jpg')\nplot(content_image,style_image)\nstylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]\nplot_pair(content_image,style_image,stylized_image)","metadata":{"execution":{"iopub.status.busy":"2021-06-22T01:55:20.932207Z","iopub.execute_input":"2021-06-22T01:55:20.932627Z","iopub.status.idle":"2021-06-22T01:55:22.443312Z","shell.execute_reply.started":"2021-06-22T01:55:20.932590Z","shell.execute_reply":"2021-06-22T01:55:22.442374Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Thank You !!","metadata":{}}]}