{"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":"# Style Transfer TensorFlow Hub Sample\nThis notebook used TensorFlow Hub Pre-trained model.<br/>\nhttps://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2","metadata":{"papermill":{"duration":0.007149,"end_time":"2021-05-15T03:00:50.357751","exception":false,"start_time":"2021-05-15T03:00:50.350602","status":"completed"},"tags":[]}},{"cell_type":"code","source":"import tensorflow_hub as hub\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport tensorflow as tf","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","papermill":{"duration":6.111346,"end_time":"2021-05-15T03:00:50.34216","exception":false,"start_time":"2021-05-15T03:00:44.230814","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-08-03T11:48:12.58106Z","iopub.execute_input":"2021-08-03T11:48:12.581431Z","iopub.status.idle":"2021-08-03T11:48:12.585814Z","shell.execute_reply.started":"2021-08-03T11:48:12.581398Z","shell.execute_reply":"2021-08-03T11:48:12.584865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2')","metadata":{"papermill":{"duration":4.856858,"end_time":"2021-05-15T03:00:55.223054","exception":false,"start_time":"2021-05-15T03:00:50.366196","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-08-03T11:48:12.602099Z","iopub.execute_input":"2021-08-03T11:48:12.602386Z","iopub.status.idle":"2021-08-03T11:48:14.679469Z","shell.execute_reply.started":"2021-08-03T11:48:12.602357Z","shell.execute_reply":"2021-08-03T11:48:14.678469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"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":{"papermill":{"duration":0.018367,"end_time":"2021-05-15T03:00:55.249086","exception":false,"start_time":"2021-05-15T03:00:55.230719","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-08-03T11:48:14.69377Z","iopub.execute_input":"2021-08-03T11:48:14.6941Z","iopub.status.idle":"2021-08-03T11:48:14.700531Z","shell.execute_reply.started":"2021-08-03T11:48:14.694064Z","shell.execute_reply":"2021-08-03T11:48:14.699265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Content image and Stylized image ","metadata":{}},{"cell_type":"code","source":"content_image = load_image('../input/gan-getting-started/photo_jpg/009ddaed1f.jpg')\nstyle_image = load_image('../input/gan-getting-started/monet_jpg/0e3b3292da.jpg')","metadata":{"papermill":{"duration":0.065152,"end_time":"2021-05-15T03:00:55.322065","exception":false,"start_time":"2021-05-15T03:00:55.256913","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-08-03T11:48:14.703006Z","iopub.execute_input":"2021-08-03T11:48:14.703486Z","iopub.status.idle":"2021-08-03T11:48:14.720636Z","shell.execute_reply.started":"2021-08-03T11:48:14.703449Z","shell.execute_reply":"2021-08-03T11:48:14.71989Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (10,5))\n\nplt.subplot(1,2,1)\nplt.title(\"content_image\")\nplt.imshow(np.squeeze(content_image))\nplt.axis('off')\n\nplt.subplot(1,2,2)\nplt.title(\"style_image\")\nplt.imshow(np.squeeze(style_image))\nplt.axis('off')\nplt.show()","metadata":{"papermill":{"duration":0.308871,"end_time":"2021-05-15T03:00:55.639258","exception":false,"start_time":"2021-05-15T03:00:55.330387","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-08-03T11:48:14.723126Z","iopub.execute_input":"2021-08-03T11:48:14.723398Z","iopub.status.idle":"2021-08-03T11:48:14.94188Z","shell.execute_reply.started":"2021-08-03T11:48:14.723367Z","shell.execute_reply":"2021-08-03T11:48:14.940797Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]","metadata":{"papermill":{"duration":2.974386,"end_time":"2021-05-15T03:00:58.630965","exception":false,"start_time":"2021-05-15T03:00:55.656579","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-08-03T11:48:14.943341Z","iopub.execute_input":"2021-08-03T11:48:14.943721Z","iopub.status.idle":"2021-08-03T11:48:16.495045Z","shell.execute_reply.started":"2021-08-03T11:48:14.943684Z","shell.execute_reply":"2021-08-03T11:48:16.494171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (5,5))\n\n#plt.subplot(1,1,1)\nplt.title(\"stylized_image\")\nplt.imshow(np.squeeze(stylized_image))\nplt.axis('off')\nplt.show()","metadata":{"papermill":{"duration":0.483587,"end_time":"2021-05-15T03:00:59.13158","exception":false,"start_time":"2021-05-15T03:00:58.647993","status":"completed"},"tags":[],"execution":{"iopub.status.busy":"2021-08-03T11:48:16.49821Z","iopub.execute_input":"2021-08-03T11:48:16.498493Z","iopub.status.idle":"2021-08-03T11:48:16.659798Z","shell.execute_reply.started":"2021-08-03T11:48:16.498466Z","shell.execute_reply":"2021-08-03T11:48:16.654406Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Style Transfer TensorFlow Hub Sample<br/>\nhttps://www.kaggle.com/stpeteishii/style-transfer-tensorflow-hub-sample<br/>\nStyle Transfer Tensorflow Sample<br/>\nhttps://www.kaggle.com/stpeteishii/style-transfer-tensorflow-sample<br/>\nStyle Transfer Keras Sample<br/>\nhttps://www.kaggle.com/stpeteishii/style-transfer-keras-sample<br/>\nStyle Transfer Pytorch Sample<br/>\nhttps://www.kaggle.com/stpeteishii/style-transfer-pytorch-sample<br/>","metadata":{}},{"cell_type":"code","source":"","metadata":{"papermill":{"duration":0.031236,"end_time":"2021-05-15T03:00:59.195213","exception":false,"start_time":"2021-05-15T03:00:59.163977","status":"completed"},"tags":[],"trusted":true},"execution_count":null,"outputs":[]}]}