{"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":"\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    print(dirname)\n\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport tensorflow as tf\nimport tensorflow_hub as hub\nimport cv2","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tf.__version__","metadata":{"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":"code","source":"model","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"image_1=\"../input/gan-getting-started/monet_jpg/000c1e3bff.jpg\"\nimage_2=\"../input/gan-getting-started/photo_jpg/00068bc07f.jpg\"#","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def l(img):\n    img=tf.io.read_file(img)\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":"im1=l(image_1)\nplt.imshow(np.squeeze(im1))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"im2=l(image_2)\nplt.imshow(np.squeeze(im2))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tfm=model(tf.constant(im1),tf.constant(im2))[0]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(np.squeeze(tfm))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"photo_dir=\"../input/gan-getting-started/photo_jpg/\"\nmonet_dir=\"../input/gan-getting-started/monet_jpg/\"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"photo_path=[]\nmonet_path=[]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for a,i in enumerate(os.listdir(photo_dir)):\n    if a==10:\n        break\n    photo_path.append(os.path.join(photo_dir,i))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"photo_path","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for a,i in enumerate(os.listdir(monet_dir)):\n    if a==10:\n        break\n    monet_path.append(os.path.join(monet_dir,i))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"monet_path","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"im2=l(monet_path[0])\nplt.imshow(np.squeeze(im2))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"im2=l(photo_path[0])\nplt.imshow(np.squeeze(im2))","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sq=zip(photo_path,monet_path)\nfor (i,j) in sq:\n    print(i,j)\n    i=l(i)\n    j=l(j)\n    style=model(tf.constant(i),tf.constant(j))[0]\n    plt.subplot(1,3,1)\n    plt.title(\"content_image\")\n    plt.imshow(np.squeeze(i))\n    plt.axis('off')\n\n    plt.subplot(1,3,2)\n    plt.title(\"style_image\")\n    plt.imshow(np.squeeze(j))\n    plt.axis('off')\n\n    plt.subplot(1,3,3)\n    plt.title(\"stylized_image\")\n    plt.imshow(np.squeeze(style))\n    plt.axis('off')\n    plt.show()\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}