{"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":"code","source":"import numpy as np\nimport os\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nimport tensorflow_hub as hub","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"https://colab.research.google.com/github/tensorflow/hub/blob/master/examples/colab/tf2_arbitrary_image_stylization.ipynb","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":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"content_image = load_image('../input/gan-getting-started/photo_jpg/01135e4771.jpg')\nstyle_image = load_image('../input/the-metropolitan-museum-of-art-ukiyoe-dataset/images/Katsushika_Hokusai/MET-39799.jpg')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"stylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize = (18,6))\n\nplt.subplot(1,3,1)\nplt.title(\"content_image\")\nplt.imshow(np.squeeze(content_image))\nplt.axis('off')\n\nplt.subplot(1,3,2)\nplt.title(\"style_image\")\nplt.imshow(np.squeeze(style_image))\nplt.axis('off')\n\nplt.subplot(1,3,3)\nplt.title(\"stylized_image\")\nplt.imshow(np.squeeze(stylized_image))\nplt.axis('off')\nplt.show()\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_dir='../input/gan-getting-started/photo_jpg/'\npaths=[]\nfor im in os.listdir(data_dir):\n        paths+=[os.path.join(data_dir,im)]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(10):\n    content_image = load_image(paths[i])\n    stylized_image = model(tf.constant(content_image), tf.constant(style_image))[0]\n    plt.figure(figsize = (12,6))\n    plt.subplot(1,2,1)\n    plt.title(\"content_image \"+str(i+1))\n    plt.imshow(np.squeeze(content_image))\n    plt.axis('off')\n    plt.subplot(1,2,2)\n    plt.title(\"stylized_image \"+str(i+1))\n    plt.imshow(np.squeeze(stylized_image))\n    plt.axis('off')\n    plt.show()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}