{"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 # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport gc\nimport time","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2023-06-10T16:47:27.699171Z","iopub.execute_input":"2023-06-10T16:47:27.699511Z","iopub.status.idle":"2023-06-10T16:47:28.424487Z","shell.execute_reply.started":"2023-06-10T16:47:27.699482Z","shell.execute_reply":"2023-06-10T16:47:28.423613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from IPython import display","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:28.719090Z","iopub.execute_input":"2023-06-10T16:47:28.719506Z","iopub.status.idle":"2023-06-10T16:47:28.726622Z","shell.execute_reply.started":"2023-06-10T16:47:28.719461Z","shell.execute_reply":"2023-06-10T16:47:28.725613Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nimport tensorflow.keras.backend as K\n","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:28.992372Z","iopub.execute_input":"2023-06-10T16:47:28.992984Z","iopub.status.idle":"2023-06-10T16:47:36.582546Z","shell.execute_reply.started":"2023-06-10T16:47:28.992938Z","shell.execute_reply":"2023-06-10T16:47:36.581615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras import layers\nfrom tensorflow.keras import Model\nfrom tensorflow.keras.models import Sequential","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:36.584491Z","iopub.execute_input":"2023-06-10T16:47:36.585249Z","iopub.status.idle":"2023-06-10T16:47:36.590669Z","shell.execute_reply.started":"2023-06-10T16:47:36.585215Z","shell.execute_reply":"2023-06-10T16:47:36.589631Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path = \"/kaggle/input/happy-whale-and-dolphin/train.csv\"\ntrain_df = pd.read_csv(path)","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:36.592290Z","iopub.execute_input":"2023-06-10T16:47:36.592642Z","iopub.status.idle":"2023-06-10T16:47:36.694951Z","shell.execute_reply.started":"2023-06-10T16:47:36.592612Z","shell.execute_reply":"2023-06-10T16:47:36.694029Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.groupby(\"species\").count().sort_values(\"image\", ascending = False).head()","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:36.697468Z","iopub.execute_input":"2023-06-10T16:47:36.698186Z","iopub.status.idle":"2023-06-10T16:47:36.751611Z","shell.execute_reply.started":"2023-06-10T16:47:36.698153Z","shell.execute_reply":"2023-06-10T16:47:36.750626Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dolphin = \"bottlenose_dolphin\"\n\nfilter1 = train_df[\"species\"] == dolphin\n\ntrain_indx =  np.where(filter1)[0]","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:36.753087Z","iopub.execute_input":"2023-06-10T16:47:36.753487Z","iopub.status.idle":"2023-06-10T16:47:36.765472Z","shell.execute_reply.started":"2023-06-10T16:47:36.753454Z","shell.execute_reply":"2023-06-10T16:47:36.764583Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.random.seed(1)\nnp.random.shuffle(train_indx)","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:36.767127Z","iopub.execute_input":"2023-06-10T16:47:36.767799Z","iopub.status.idle":"2023-06-10T16:47:36.774363Z","shell.execute_reply.started":"2023-06-10T16:47:36.767768Z","shell.execute_reply":"2023-06-10T16:47:36.773451Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#n_train = 50000\n#np.random.seed(1)\n#train_indx = np.random.choice(n_train, 17000)","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:36.775773Z","iopub.execute_input":"2023-06-10T16:47:36.776251Z","iopub.status.idle":"2023-06-10T16:47:36.782451Z","shell.execute_reply.started":"2023-06-10T16:47:36.776222Z","shell.execute_reply":"2023-06-10T16:47:36.781523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = np.load(\"/kaggle/input/happywhale-images/Img_train_96x128.npy\")[train_indx,16:-16,:,:]","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:36.784137Z","iopub.execute_input":"2023-06-10T16:47:36.784454Z","iopub.status.idle":"2023-06-10T16:47:57.963990Z","shell.execute_reply.started":"2023-06-10T16:47:36.784426Z","shell.execute_reply":"2023-06-10T16:47:57.962937Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:57.965143Z","iopub.execute_input":"2023-06-10T16:47:57.965497Z","iopub.status.idle":"2023-06-10T16:47:57.977135Z","shell.execute_reply.started":"2023-06-10T16:47:57.965465Z","shell.execute_reply":"2023-06-10T16:47:57.974630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(4,4, figsize = (10, 8))\n\nfor k in range(16):\n    i = int(k//4)\n    j = k % 4\n    ax[i,j].imshow(X_train[k])\n    ax[i,j].tick_params(left = False, right = False , labelleft = False ,\n                labelbottom = False, bottom = False)\n","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:47:57.981472Z","iopub.execute_input":"2023-06-10T16:47:57.982152Z","iopub.status.idle":"2023-06-10T16:48:00.361982Z","shell.execute_reply.started":"2023-06-10T16:47:57.982120Z","shell.execute_reply":"2023-06-10T16:48:00.361156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(4,4, figsize = (10, 8))\n\nfor k in range(16):\n    i = int(k//4)\n    j = k % 4\n    ax[i,j].imshow(X_train[k+100])\n    ax[i,j].tick_params(left = False, right = False , labelleft = False ,\n                labelbottom = False, bottom = False)\n","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:00.362896Z","iopub.execute_input":"2023-06-10T16:48:00.363199Z","iopub.status.idle":"2023-06-10T16:48:02.730161Z","shell.execute_reply.started":"2023-06-10T16:48:00.363172Z","shell.execute_reply":"2023-06-10T16:48:02.729171Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train = X_train.astype(np.float32) / (255/2) - 1","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:02.731785Z","iopub.execute_input":"2023-06-10T16:48:02.732114Z","iopub.status.idle":"2023-06-10T16:48:03.138250Z","shell.execute_reply.started":"2023-06-10T16:48:02.732085Z","shell.execute_reply":"2023-06-10T16:48:03.137301Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 64\ndataset = tf.data.Dataset.from_tensor_slices(X_train).shuffle(1000)\ndataset = dataset.batch(batch_size, drop_remainder=True).prefetch(1)","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:03.139866Z","iopub.execute_input":"2023-06-10T16:48:03.140191Z","iopub.status.idle":"2023-06-10T16:48:07.590892Z","shell.execute_reply.started":"2023-06-10T16:48:03.140159Z","shell.execute_reply":"2023-06-10T16:48:07.589939Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gc.collect()","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:07.592308Z","iopub.execute_input":"2023-06-10T16:48:07.592663Z","iopub.status.idle":"2023-06-10T16:48:07.839250Z","shell.execute_reply.started":"2023-06-10T16:48:07.592631Z","shell.execute_reply":"2023-06-10T16:48:07.838252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_results(images):\n    #display.clear_output(wait=True)  \n    \n    N = 16\n    \n    NC = 4\n    NR = int(N//NC)\n    \n    img2 = convert_img(images)\n    \n    fig, ax = plt.subplots(NR,NC, figsize = (12,8))\n    \n    for k in range(N):\n        i = int(k//NC)\n        j = k % NC\n        \n        ax[i,j].imshow(img2[k])\n        ax[i,j].tick_params(left = False, right = False , labelleft = False ,\n                labelbottom = False, bottom = False)\n        \n        \ndef convert_img(images):\n    \n    img2 = ((np.array(images).copy() + 1)*127.5)\n    \n    img2[img2>255] = 255\n    img2[img2<0] = 0\n    img2 = img2.astype(np.uint8)\n    \n    return img2","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:07.840815Z","iopub.execute_input":"2023-06-10T16:48:07.841446Z","iopub.status.idle":"2023-06-10T16:48:07.850178Z","shell.execute_reply.started":"2023-06-10T16:48:07.841404Z","shell.execute_reply":"2023-06-10T16:48:07.849134Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Generator","metadata":{}},{"cell_type":"code","source":"def create_generator6():\n    \n    Input =  layers.Input(shape=(random_normal_dim))\n    \n    #x = layers.Dropout(0.25)(Input)\n    \n    FS = 256*2\n    x = layers.Dense(random_normal_dim*FS)(Input)\n    \n    \n    x = layers.Reshape((4,8,FS))(x)\n    \n    x = layers.Dropout(0.4)(x)\n    \n    FS = int(FS//2)\n    x = layers.Conv2DTranspose(FS, kernel_size=5, strides=2, padding=\"SAME\", activation=\"selu\")(x)\n    x = layers.BatchNormalization()(x)\n    \n    \n    FS = int(FS//2)\n    x = layers.Conv2DTranspose(FS, kernel_size=7, strides=2, padding=\"SAME\", activation=\"selu\")(x)\n    x = layers.BatchNormalization()(x)\n    \n    FS = int(FS//2)\n    x = layers.Conv2DTranspose(FS, kernel_size=7, strides=2, padding=\"SAME\", activation=\"selu\")(x)\n    x = layers.BatchNormalization()(x)\n    \n    output = layers.Conv2DTranspose(3, kernel_size=7, strides=2, padding=\"SAME\", activation=\"tanh\")(x)\n    \n    \n    \n    model = Model(inputs = Input, outputs = output, name = \"generator\")\n    \n    return model","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:07.851696Z","iopub.execute_input":"2023-06-10T16:48:07.852082Z","iopub.status.idle":"2023-06-10T16:48:07.863652Z","shell.execute_reply.started":"2023-06-10T16:48:07.852050Z","shell.execute_reply":"2023-06-10T16:48:07.862714Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"random_normal_dim = 32\n\n","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:07.866928Z","iopub.execute_input":"2023-06-10T16:48:07.867193Z","iopub.status.idle":"2023-06-10T16:48:07.873371Z","shell.execute_reply.started":"2023-06-10T16:48:07.867171Z","shell.execute_reply":"2023-06-10T16:48:07.872292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Critic","metadata":{}},{"cell_type":"code","source":"def create_critic():\n    \n    Input = layers.Input(shape = (64, 128, 3))\n    \n    FS = 32*2\n    x = layers.Conv2D(FS, kernel_size =7, strides = 2, padding = \"same\")(Input)\n    x = layers.BatchNormalization()(x)\n    x = layers.LeakyReLU(0.2)(x)\n    \n\n    \n    FS = FS*2\n    x = layers.Conv2D(FS, kernel_size =7, strides = 2, padding = \"same\")(x)\n    x = layers.BatchNormalization()(x)\n    x = layers.LeakyReLU(0.2)(x)\n        \n\n    \n    FS = FS*2\n    x = layers.Conv2D(FS, kernel_size =7, strides = 2, padding = \"same\")(x)\n    x = layers.BatchNormalization()(x)\n    x = layers.LeakyReLU(0.2)(x)\n    \n    \n    FS = FS*2\n    x = layers.Conv2D(FS, kernel_size =5, strides = 2, padding = \"same\", activation = layers.LeakyReLU(0.2))(x)\n    \n    \n    x = layers.Flatten()(x)\n    \n    x = layers.Dropout(0.2)(x)\n    \n    output = layers.Dense(1)(x)\n    \n    model =  Model(inputs = Input, outputs = output, name = \"critic\")\n    \n    return model\n    ","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:07.876820Z","iopub.execute_input":"2023-06-10T16:48:07.877097Z","iopub.status.idle":"2023-06-10T16:48:07.888389Z","shell.execute_reply.started":"2023-06-10T16:48:07.877075Z","shell.execute_reply":"2023-06-10T16:48:07.887478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"critic = create_critic()\ncritic.summary()","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:07.890271Z","iopub.execute_input":"2023-06-10T16:48:07.891103Z","iopub.status.idle":"2023-06-10T16:48:08.115760Z","shell.execute_reply.started":"2023-06-10T16:48:07.891069Z","shell.execute_reply":"2023-06-10T16:48:08.114928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Wassertain loss","metadata":{}},{"cell_type":"code","source":"def gradient_cal(real_images, fake_images):\n    \n    epsilon = tf.random.uniform(\n    shape = (batch_size, 1,1,1), minval=0, maxval=1)\n    \n    mixed = epsilon*real_images + (1-epsilon)*fake_images\n    \n    with tf.GradientTape() as tape:\n        tape.watch(mixed)\n        mixed_pred  = critic(mixed)\n        \n    \n    gradients = tape.gradient(mixed_pred, mixed)\n    \n    \n    return gradients\n\n\ndef gp_cal(gradient):\n    \n    grad_flat =  tf.reshape(gradient, shape = (64,-1))\n    \n    norms = tf.norm(grad_flat, axis = 1)\n    \n    \n    gp = K.mean(K.square(norms - 1))\n    \n    return gp\n    ","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:08.851049Z","iopub.execute_input":"2023-06-10T16:48:08.851829Z","iopub.status.idle":"2023-06-10T16:48:08.859231Z","shell.execute_reply.started":"2023-06-10T16:48:08.851796Z","shell.execute_reply":"2023-06-10T16:48:08.858001Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def gen_loss_cal(critic_fake_pred):\n    \n    \n    loss = - K.mean(critic_fake_pred)\n    \n    return loss","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:19.258671Z","iopub.execute_input":"2023-06-10T16:48:19.259025Z","iopub.status.idle":"2023-06-10T16:48:19.267052Z","shell.execute_reply.started":"2023-06-10T16:48:19.258998Z","shell.execute_reply":"2023-06-10T16:48:19.265981Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def critic_loss_cal(crit_real_pred, crit_fake_pred, gp, c_lambda):\n    \n    \n    loss = -K.mean(crit_real_pred) + K.mean(crit_fake_pred)  + c_lambda*gp\n    \n    return loss\n    ","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:48:19.499293Z","iopub.execute_input":"2023-06-10T16:48:19.499903Z","iopub.status.idle":"2023-06-10T16:48:19.504758Z","shell.execute_reply.started":"2023-06-10T16:48:19.499874Z","shell.execute_reply":"2023-06-10T16:48:19.503766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train WGAN","metadata":{}},{"cell_type":"markdown","source":"## Create Model","metadata":{}},{"cell_type":"code","source":"generator = create_generator6()\ncritic = create_critic()","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:50:36.947261Z","iopub.execute_input":"2023-06-10T16:50:36.947642Z","iopub.status.idle":"2023-06-10T16:50:37.154035Z","shell.execute_reply.started":"2023-06-10T16:50:36.947611Z","shell.execute_reply":"2023-06-10T16:50:37.153130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"wgan = Sequential([generator, critic])","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:50:37.168498Z","iopub.execute_input":"2023-06-10T16:50:37.168811Z","iopub.status.idle":"2023-06-10T16:50:37.274430Z","shell.execute_reply.started":"2023-06-10T16:50:37.168784Z","shell.execute_reply":"2023-06-10T16:50:37.273552Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"optimizer_critic = tf.keras.optimizers.experimental.RMSprop()\noptimizer_wgan = tf.keras.optimizers.experimental.RMSprop()","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:50:37.372304Z","iopub.execute_input":"2023-06-10T16:50:37.372616Z","iopub.status.idle":"2023-06-10T16:50:37.394482Z","shell.execute_reply.started":"2023-06-10T16:50:37.372587Z","shell.execute_reply":"2023-06-10T16:50:37.393679Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Train Loop function","metadata":{}},{"cell_type":"code","source":"def train_wgan(EPOCH):\n    \n    disc_labels = tf.constant([[0.]]*batch_size + [[1.]]*batch_size)\n    gan_labels = tf.constant([[1.]]*batch_size)\n\n\n    for ITR in range(EPOCH):\n        time1 = time.time()\n        \n        print(\"EPOCH\", ITR)\n        count = 0\n        for real_images in dataset:\n            count += 1\n            \n            #generate images\n\n            \n            #print(\"train critic\")\n            #train critic ######################################\n            critic.trainable = True\n            \n            c_lambda = 1\n            \n            random_noise = tf.random.normal(shape = (batch_size, random_normal_dim))\n            fake_images = generator(random_noise)\n\n\n            \n            with tf.GradientTape() as tape:\n                \n                \n                crit_real_pred = critic(real_images)\n                crit_fake_pred = critic(fake_images)\n                \n                gp = gp_cal(gradient_cal(real_images, fake_images))\n\n    \n                critic_loss = critic_loss_cal(crit_real_pred, crit_fake_pred, gp, c_lambda)\n                #print(\"gp = \",  gp, \" loss = \", critic_loss)\n            \n            gradients = tape.gradient(critic_loss, critic.trainable_weights)\n            \n            optimizer_critic.apply_gradients(zip(gradients, critic.trainable_weights))\n            \n\n            #train generator############################\n            #print(\"train gen\")\n            critic.trainable = False\n            \n            random_noise = tf.random.normal(shape = (batch_size, random_normal_dim))\n            \n            with tf.GradientTape() as tape:\n                crit_fake_pred = wgan(random_noise)\n                gen_loss = gen_loss_cal(crit_fake_pred)\n                \n            gradients = tape.gradient(gen_loss, wgan.trainable_weights)\n            \n            \n            optimizer_wgan.apply_gradients(zip(gradients, wgan.trainable_weights))\n            \n            \n            #if count > 100:\n            #    break\n            \n            #if count % 100 == 0:\n            #    print(count)\n            \n    \n        time2 = time.time()\n        time3 = np.round(time2 - time1)\n        print(time3, \"sec\")\n    \n    ","metadata":{"execution":{"iopub.status.busy":"2023-06-10T16:52:23.738125Z","iopub.execute_input":"2023-06-10T16:52:23.738476Z","iopub.status.idle":"2023-06-10T16:52:23.751302Z","shell.execute_reply.started":"2023-06-10T16:52:23.738450Z","shell.execute_reply":"2023-06-10T16:52:23.750314Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fake_images_list = []","metadata":{"execution":{"iopub.status.busy":"2023-06-10T17:06:38.160151Z","iopub.execute_input":"2023-06-10T17:06:38.160516Z","iopub.status.idle":"2023-06-10T17:06:38.164862Z","shell.execute_reply.started":"2023-06-10T17:06:38.160486Z","shell.execute_reply":"2023-06-10T17:06:38.163916Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"EPOCH = 3","metadata":{"execution":{"iopub.status.busy":"2023-06-10T17:06:38.365589Z","iopub.execute_input":"2023-06-10T17:06:38.366291Z","iopub.status.idle":"2023-06-10T17:06:38.371762Z","shell.execute_reply.started":"2023-06-10T17:06:38.366257Z","shell.execute_reply":"2023-06-10T17:06:38.370827Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{"execution":{"iopub.status.busy":"2023-06-10T17:06:38.875380Z","iopub.execute_input":"2023-06-10T17:06:38.875747Z","iopub.status.idle":"2023-06-10T17:08:30.614017Z","shell.execute_reply.started":"2023-06-10T17:06:38.875715Z","shell.execute_reply":"2023-06-10T17:08:30.612591Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{"execution":{"iopub.status.busy":"2023-06-10T17:08:30.615905Z","iopub.execute_input":"2023-06-10T17:08:30.616529Z","iopub.status.idle":"2023-06-10T17:10:27.218615Z","shell.execute_reply.started":"2023-06-10T17:08:30.616495Z","shell.execute_reply":"2023-06-10T17:10:27.217366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{"execution":{"iopub.status.busy":"2023-06-10T17:10:27.220081Z","iopub.execute_input":"2023-06-10T17:10:27.220519Z","iopub.status.idle":"2023-06-10T17:12:18.787821Z","shell.execute_reply.started":"2023-06-10T17:10:27.220486Z","shell.execute_reply":"2023-06-10T17:12:18.786787Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_wgan(EPOCH)\nrandom_noise = tf.random.normal(shape = (200, random_normal_dim))\nfake_images = generator(random_noise)\nfake_images_np = convert_img(fake_images)\nfake_images_list.append(fake_images_np)\nplot_results(fake_images)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Write Numpy","metadata":{}},{"cell_type":"code","source":"for i in range(len(fake_images_list)):\n    fname = \"fake_images_\" + str(i)\n    print(fname)\n    \n    np.save(fname, fake_images_list[i])","metadata":{"execution":{"iopub.status.busy":"2023-06-10T17:12:18.789810Z","iopub.execute_input":"2023-06-10T17:12:18.790217Z","iopub.status.idle":"2023-06-10T17:12:18.816282Z","shell.execute_reply.started":"2023-06-10T17:12:18.790188Z","shell.execute_reply":"2023-06-10T17:12:18.815477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-06-10T17:06:26.909966Z","iopub.execute_input":"2023-06-10T17:06:26.910322Z","iopub.status.idle":"2023-06-10T17:06:27.420709Z","shell.execute_reply.started":"2023-06-10T17:06:26.910294Z","shell.execute_reply":"2023-06-10T17:06:27.419749Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}