{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":21755,"databundleVersionId":1475600,"sourceType":"competition"}],"dockerImageVersionId":30684,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport seaborn as sns\nimport tensorflow as tf\nimport cv2\n\nfrom colorama import Fore, Back, Style\nfrom tensorflow import keras\nfrom tensorflow.keras import layers\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"execution":{"iopub.status.busy":"2024-04-15T10:54:35.809412Z","iopub.execute_input":"2024-04-15T10:54:35.810202Z","iopub.status.idle":"2024-04-15T10:54:35.962231Z","shell.execute_reply.started":"2024-04-15T10:54:35.810160Z","shell.execute_reply":"2024-04-15T10:54:35.961063Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_ = Fore.YELLOW\nr_ = Fore.RED\ng_ = Fore.GREEN\nb_ = Fore.BLUE\nm_ = Fore.MAGENTA\n\ntry:\n    tpu = tf.distribute.cluster_resolver.TPUClusterResolver()\n    print('Device:', tpu.master())\n    tf.config.experimental_connect_to_cluster(tpu)\n    tf.tpu.experimental.initialize_tpu_system(tpu)\n    strategy = tf.distribute.experimental.TPUStrategy(tpu)\nexcept:\n    strategy = tf.distribute.get_strategy()\nprint('Number of replicas:', strategy.num_replicas_in_sync)\n\nAUTOTUNE = tf.data.experimental.AUTOTUNE\n    \nprint(tf.__version__)","metadata":{"execution":{"iopub.status.busy":"2024-04-15T10:57:15.832993Z","iopub.execute_input":"2024-04-15T10:57:15.833470Z","iopub.status.idle":"2024-04-15T10:57:15.845493Z","shell.execute_reply.started":"2024-04-15T10:57:15.833434Z","shell.execute_reply":"2024-04-15T10:57:15.844242Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"monet_jpg_directory = '../input/gan-getting-started/monet_jpg/'\nphoto_jpg_directory = '../input/gan-getting-started/photo_jpg/'","metadata":{"execution":{"iopub.status.busy":"2024-04-15T10:57:28.833508Z","iopub.execute_input":"2024-04-15T10:57:28.834759Z","iopub.status.idle":"2024-04-15T10:57:28.840145Z","shell.execute_reply.started":"2024-04-15T10:57:28.834719Z","shell.execute_reply":"2024-04-15T10:57:28.838747Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def getImagePaths(path):\n    image_names = []\n    for dirname, _, filenames in os.walk(path):\n        for filename in filenames:\n            fullpath = os.path.join(dirname, filename)\n            image_names.append(fullpath)\n    return image_names","metadata":{"execution":{"iopub.status.busy":"2024-04-15T10:57:38.253828Z","iopub.execute_input":"2024-04-15T10:57:38.254580Z","iopub.status.idle":"2024-04-15T10:57:38.261172Z","shell.execute_reply.started":"2024-04-15T10:57:38.254545Z","shell.execute_reply":"2024-04-15T10:57:38.259633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"monet_images_path = getImagePaths(monet_jpg_directory)\nphoto_images_path = getImagePaths(photo_jpg_directory)","metadata":{"execution":{"iopub.status.busy":"2024-04-15T10:57:48.212751Z","iopub.execute_input":"2024-04-15T10:57:48.213831Z","iopub.status.idle":"2024-04-15T10:57:50.317742Z","shell.execute_reply.started":"2024-04-15T10:57:48.213797Z","shell.execute_reply":"2024-04-15T10:57:50.316587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"{y_}Number of Monet images: {g_} {len(monet_images_path)}\\n\")\nprint(f\"{y_}Number of Photo images: {g_} {len(photo_images_path)}\\n\")","metadata":{"execution":{"iopub.status.busy":"2024-04-15T10:57:56.953413Z","iopub.execute_input":"2024-04-15T10:57:56.953923Z","iopub.status.idle":"2024-04-15T10:57:56.960679Z","shell.execute_reply.started":"2024-04-15T10:57:56.953884Z","shell.execute_reply":"2024-04-15T10:57:56.959470Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def getShape(images_paths):\n    shape = cv2.imread(images_paths[0]).shape\n    for image_path in images_paths:\n        image_shape=cv2.imread(image_path).shape\n        if (image_shape!=shape):\n            return \"Different image shape\"\n        else:\n            return \"Same image shape \" + str(shape)","metadata":{"execution":{"iopub.status.busy":"2024-04-15T10:59:13.487048Z","iopub.execute_input":"2024-04-15T10:59:13.488343Z","iopub.status.idle":"2024-04-15T10:59:13.494900Z","shell.execute_reply.started":"2024-04-15T10:59:13.488294Z","shell.execute_reply":"2024-04-15T10:59:13.494057Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"getShape(monet_images_path)\ngetShape(photo_images_path)","metadata":{"execution":{"iopub.status.busy":"2024-04-15T10:59:32.721779Z","iopub.execute_input":"2024-04-15T10:59:32.722200Z","iopub.status.idle":"2024-04-15T10:59:32.774809Z","shell.execute_reply.started":"2024-04-15T10:59:32.722168Z","shell.execute_reply":"2024-04-15T10:59:32.773069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_multiple_img(images_paths, rows, cols):\n    figure, ax = plt.subplots(nrows=rows,ncols=cols,figsize=(16,8) )\n    for ind,image_path in enumerate(images_paths):\n        image=cv2.imread(image_path)\n        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) \n        try:\n            ax.ravel()[ind].imshow(image)\n            ax.ravel()[ind].set_axis_off()\n        except:\n            continue;\n    plt.tight_layout()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-15T10:59:42.104154Z","iopub.execute_input":"2024-04-15T10:59:42.104581Z","iopub.status.idle":"2024-04-15T10:59:42.112145Z","shell.execute_reply.started":"2024-04-15T10:59:42.104541Z","shell.execute_reply":"2024-04-15T10:59:42.111142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_multiple_img(monet_images_path, 4, 4)","metadata":{"execution":{"iopub.status.busy":"2024-04-15T10:59:49.989862Z","iopub.execute_input":"2024-04-15T10:59:49.990686Z","iopub.status.idle":"2024-04-15T10:59:53.802074Z","shell.execute_reply.started":"2024-04-15T10:59:49.990640Z","shell.execute_reply":"2024-04-15T10:59:53.800646Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_multiple_img(photo_images_path, 4, 4)","metadata":{"execution":{"iopub.status.busy":"2024-04-15T11:00:02.462175Z","iopub.execute_input":"2024-04-15T11:00:02.462673Z","iopub.status.idle":"2024-04-15T11:01:08.042277Z","shell.execute_reply.started":"2024-04-15T11:00:02.462634Z","shell.execute_reply":"2024-04-15T11:01:08.040176Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def styling():\n    for spine in plt.gca().spines.values():\n        spine.set_visible(False)\n        plt.xticks([])\n        plt.yticks([])","metadata":{"execution":{"iopub.status.busy":"2024-04-15T11:01:17.246767Z","iopub.execute_input":"2024-04-15T11:01:17.247205Z","iopub.status.idle":"2024-04-15T11:01:17.254139Z","shell.execute_reply.started":"2024-04-15T11:01:17.247171Z","shell.execute_reply":"2024-04-15T11:01:17.252733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def hist(image_path):\n    plt.figure(figsize=(16, 3))\n    \n    img = cv2.imread(image_path)\n    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) \n    \n    plt.subplot(1, 5, 1)\n    plt.imshow(img)\n    styling()\n    \n    custom_colors = [\"#ef233c\", \"#76da71\", \"#2667ff\",\"#aea3b0\"]\n    labels = ['Red Channel', 'Green Channel', 'Blue Channel','Total']\n    \n    for i in range(1,4):\n        plt.subplot(1, 5, i+1)\n        plt.hist(img[:, :, i-1].reshape(-1),bins=64,color=custom_colors[i-1],alpha = 0.6)\n        plt.xlabel(labels[i-1],fontsize=10)\n        styling()\n        \n    plt.subplot(1, 5, 5)\n    plt.hist(img.reshape(-1),bins=128,color=custom_colors[3],alpha = 0.6)\n    plt.xlabel(labels[3],fontsize=10)\n    styling()\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2024-04-15T11:01:55.737291Z","iopub.execute_input":"2024-04-15T11:01:55.737713Z","iopub.status.idle":"2024-04-15T11:01:55.747632Z","shell.execute_reply.started":"2024-04-15T11:01:55.737680Z","shell.execute_reply":"2024-04-15T11:01:55.746545Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def display_hist(images_paths):\n        for ind,image_path in enumerate(images_paths):\n            if (ind<6):\n                hist(image_path)","metadata":{"execution":{"iopub.status.busy":"2024-04-15T11:02:04.244661Z","iopub.execute_input":"2024-04-15T11:02:04.245314Z","iopub.status.idle":"2024-04-15T11:02:04.250253Z","shell.execute_reply.started":"2024-04-15T11:02:04.245281Z","shell.execute_reply":"2024-04-15T11:02:04.249356Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_hist(monet_images_path)","metadata":{"execution":{"iopub.status.busy":"2024-04-15T11:02:11.719133Z","iopub.execute_input":"2024-04-15T11:02:11.720444Z","iopub.status.idle":"2024-04-15T11:02:17.515343Z","shell.execute_reply.started":"2024-04-15T11:02:11.720398Z","shell.execute_reply":"2024-04-15T11:02:17.513771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display_hist(photo_images_path)","metadata":{"execution":{"iopub.status.busy":"2024-04-15T11:02:21.670315Z","iopub.execute_input":"2024-04-15T11:02:21.670750Z","iopub.status.idle":"2024-04-15T11:02:27.184561Z","shell.execute_reply.started":"2024-04-15T11:02:21.670716Z","shell.execute_reply":"2024-04-15T11:02:27.183252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}