{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","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":30804,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\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))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:42.597880Z","iopub.execute_input":"2024-12-20T22:26:42.598751Z","iopub.status.idle":"2024-12-20T22:26:46.253142Z","shell.execute_reply.started":"2024-12-20T22:26:42.598698Z","shell.execute_reply":"2024-12-20T22:26:46.251826Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%capture\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport shutil\nimport tensorflow as tf\nimport tensorflow_datasets as tfds\nimport os\nfrom tensorflow import keras\nimport random\nimport time\nfrom IPython.display import clear_output","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:46.255315Z","iopub.execute_input":"2024-12-20T22:26:46.255808Z","iopub.status.idle":"2024-12-20T22:26:49.853101Z","shell.execute_reply.started":"2024-12-20T22:26:46.255769Z","shell.execute_reply":"2024-12-20T22:26:49.851932Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"MONET_FILENAMES = tf.io.gfile.glob('/kaggle/input/gan-getting-started/monet_tfrec/*.tfrec')\nPHOTO_FILENAMES = tf.io.gfile.glob('/kaggle/input/gan-getting-started/photo_tfrec/*.tfrec')\n\nprint(len(MONET_FILENAMES))\nprint(len(PHOTO_FILENAMES))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:49.854314Z","iopub.execute_input":"2024-12-20T22:26:49.854894Z","iopub.status.idle":"2024-12-20T22:26:49.877572Z","shell.execute_reply.started":"2024-12-20T22:26:49.854855Z","shell.execute_reply":"2024-12-20T22:26:49.876442Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"AUTO = tf.data.experimental.AUTOTUNE\n\ndef read_tfrecord(example):\n    tfrecord_format = {\n        \"image_name\": tf.io.FixedLenFeature([], tf.string),\n        \"image\": tf.io.FixedLenFeature([], tf.string),\n        \"target\": tf.io.FixedLenFeature([], tf.string)\n    }\n    example = tf.io.parse_single_example(example, tfrecord_format)\n    image = tf.image.decode_jpeg(example['image'], channels=3)\n    return image\n\ndef load_dataset(filenames):\n    dataset = tf.data.TFRecordDataset(filenames)\n    dataset = dataset.map(read_tfrecord, num_parallel_calls=AUTO)\n    return dataset","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:49.878769Z","iopub.execute_input":"2024-12-20T22:26:49.879144Z","iopub.status.idle":"2024-12-20T22:26:49.886285Z","shell.execute_reply.started":"2024-12-20T22:26:49.879108Z","shell.execute_reply":"2024-12-20T22:26:49.885110Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"monet_train_images = load_dataset(MONET_FILENAMES)\nphoto_train_images = load_dataset(PHOTO_FILENAMES)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:49.889820Z","iopub.execute_input":"2024-12-20T22:26:49.890354Z","iopub.status.idle":"2024-12-20T22:26:50.042253Z","shell.execute_reply.started":"2024-12-20T22:26:49.890302Z","shell.execute_reply":"2024-12-20T22:26:50.041021Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def plot_single_example(monet, photo):\n  fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 7))\n\n  ax1.imshow(monet)\n  ax1.set_title(\"Style image\")\n  ax1.axis('off')\n\n  ax2.imshow(photo)\n  ax2.set_title(\"Content image\")\n  ax2.axis('off')\n  plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:50.043856Z","iopub.execute_input":"2024-12-20T22:26:50.044320Z","iopub.status.idle":"2024-12-20T22:26:50.050855Z","shell.execute_reply.started":"2024-12-20T22:26:50.044272Z","shell.execute_reply":"2024-12-20T22:26:50.049732Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"images_number_monet = 0\nimages_number_photo = 0\n\nfor image in monet_train_images:\n  images_number_monet += 1\n\nfor image in photo_train_images:\n  images_number_photo += 1\n\nprint(f\"Number of monet images: {images_number_monet}\")\nprint(f\"Number of photo images: {images_number_photo}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:50.052404Z","iopub.execute_input":"2024-12-20T22:26:50.052990Z","iopub.status.idle":"2024-12-20T22:26:55.915175Z","shell.execute_reply.started":"2024-12-20T22:26:50.052919Z","shell.execute_reply":"2024-12-20T22:26:55.914062Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"monet_image = monet_train_images.as_numpy_iterator().next()\nphoto_image = photo_train_images.as_numpy_iterator().next()\n\nplot_single_example(monet_image, photo_image)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:55.916510Z","iopub.execute_input":"2024-12-20T22:26:55.916938Z","iopub.status.idle":"2024-12-20T22:26:56.465992Z","shell.execute_reply.started":"2024-12-20T22:26:55.916891Z","shell.execute_reply":"2024-12-20T22:26:56.464792Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"height = 320\nwidth = 320\n\ndef resize_dataset(x, img_height: int=height, img_width: int=width):\n    x = tf.image.resize(x, (img_height, img_width))\n    return x","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:56.467409Z","iopub.execute_input":"2024-12-20T22:26:56.467819Z","iopub.status.idle":"2024-12-20T22:26:56.473484Z","shell.execute_reply.started":"2024-12-20T22:26:56.467779Z","shell.execute_reply":"2024-12-20T22:26:56.472405Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def normalize_dataset(x):\n    x = tf.cast(x, tf.float32)\n    x = x / 255.0\n    return x\n\ndef preprocessing(x):\n  x = resize_dataset(x)\n  x = normalize_dataset(x)\n  return x","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:56.474911Z","iopub.execute_input":"2024-12-20T22:26:56.475346Z","iopub.status.idle":"2024-12-20T22:26:56.491648Z","shell.execute_reply.started":"2024-12-20T22:26:56.475300Z","shell.execute_reply":"2024-12-20T22:26:56.490466Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"batch_size = 1\n\ntrain_monet_after_preprocessing=monet_train_images.map(preprocessing, AUTO).cache().batch(batch_size).prefetch(AUTO)\ntrain_photo_after_preprocessing=photo_train_images.map(preprocessing, AUTO).cache().batch(batch_size).prefetch(AUTO)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:56.493046Z","iopub.execute_input":"2024-12-20T22:26:56.493508Z","iopub.status.idle":"2024-12-20T22:26:56.635424Z","shell.execute_reply.started":"2024-12-20T22:26:56.493398Z","shell.execute_reply":"2024-12-20T22:26:56.634114Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def create_new_model_from_model_relevant_layers(relevant_layers_list, model):\n  outputs = [model.get_layer(layer_name).output for layer_name in relevant_layers_list]\n  new_model = tf.keras.Model([model.input], outputs)\n  return new_model\n\ndef gram_matrix(some_tensor):\n  temp_tensor = some_tensor\n  temp_tensor = tf.squeeze(temp_tensor)\n  result = tf.matmul(temp_tensor, temp_tensor, transpose_b=True)\n  gram = tf.expand_dims(result, axis=0)\n  return gram","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:56.636958Z","iopub.execute_input":"2024-12-20T22:26:56.637381Z","iopub.status.idle":"2024-12-20T22:26:56.644198Z","shell.execute_reply.started":"2024-12-20T22:26:56.637343Z","shell.execute_reply":"2024-12-20T22:26:56.642835Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"class style_model(tf.keras.models.Model):\n  def __init__(self, style_layers, content_layers, model):\n    super(style_model, self).__init__()\n    self.model = model\n    self.vgg =  create_new_model_from_model_relevant_layers(style_and_content_layers, self.model)\n    self.style_layers = style_layers\n    self.content_layers = content_layers\n    self.num_style_layers = len(style_layers)\n    self.vgg.trainable = False\n\n  def call(self, inputs):\n    inputs = inputs * 255.0\n    preprocessed_input = tf.keras.applications.vgg19.preprocess_input(inputs)\n    outputs = self.vgg(preprocessed_input)\n    style_outputs, content_outputs = (outputs[:self.num_style_layers],\n                                      outputs[self.num_style_layers:])\n\n    style_outputs = [gram_matrix(style_output)\n                    for style_output in style_outputs]\n\n    # a layer by layer fashion in dicts\n    content_dict = {content_name:value\n                    for content_name, value\n                    in zip(self.content_layers, content_outputs)}\n\n    style_dict = {style_name:value\n                  for style_name, value\n                  in zip(self.style_layers, style_outputs)}\n\n    return {'content':content_dict, 'style':style_dict}","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:56.646301Z","iopub.execute_input":"2024-12-20T22:26:56.646899Z","iopub.status.idle":"2024-12-20T22:26:56.743532Z","shell.execute_reply.started":"2024-12-20T22:26:56.646831Z","shell.execute_reply":"2024-12-20T22:26:56.742518Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def style_content_and_total_loss(outputs):\n    style_outputs=outputs['style']\n    content_outputs=outputs['content']\n    style_loss=tf.add_n([style_weights[name] * tf.reduce_mean((style_outputs[name]-style_targets[name])**2)\n                        for name in style_outputs.keys()])\n    style_loss*=style_weight/len(style_layers)\n\n    content_loss = tf.add_n([tf.reduce_mean((content_outputs[name]-content_targets[name])**2)\n                             for name in content_outputs.keys()])\n    content_loss*=content_weight/len(content_layers)\n    loss=style_loss+content_loss\n    return loss, style_loss, content_loss","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:56.747470Z","iopub.execute_input":"2024-12-20T22:26:56.748325Z","iopub.status.idle":"2024-12-20T22:26:56.755158Z","shell.execute_reply.started":"2024-12-20T22:26:56.748286Z","shell.execute_reply":"2024-12-20T22:26:56.753938Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"@tf.function()\ndef train_step(image):\n  with tf.GradientTape() as tape:\n    # Extract the features\n    outputs = extractor(image)\n    # Calculate the loss\n    loss, style_loss, content_loss = style_content_and_total_loss(outputs)\n\n  # Determine the gradients of the loss function w.r.t the image pixels\n  grad = tape.gradient(loss, image)\n\n  # Update the pixels\n  opt.apply_gradients([(grad, image)])\n  \n  # Clip the pixel values that fall outside the range of [0,1]\n  image.assign(tf.clip_by_value(image, clip_value_min=0.0, clip_value_max=1.0))\n\n  return loss, style_loss, content_loss","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:56.756511Z","iopub.execute_input":"2024-12-20T22:26:56.756938Z","iopub.status.idle":"2024-12-20T22:26:56.776353Z","shell.execute_reply.started":"2024-12-20T22:26:56.756880Z","shell.execute_reply":"2024-12-20T22:26:56.775191Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def save_image(image_number, image, image_save_location, resize: tuple=()):\n    image_number_str = str(image_number)\n    image_name = f\"{image_number_str}.jpg\"\n    squeeze_image = np.squeeze(image, axis=0)\n    \n    if resize:\n        squeeze_image = resize_dataset(squeeze_image, resize[0], resize[1]).numpy()\n\n    plt.imsave(image_save_location + image_name, squeeze_image)\n\n    print(f\"Image {image_number_str}, with shape of {squeeze_image.shape}, saved in location:\")\n    print(image_save_location + image_name)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:56.777659Z","iopub.execute_input":"2024-12-20T22:26:56.778104Z","iopub.status.idle":"2024-12-20T22:26:56.789754Z","shell.execute_reply.started":"2024-12-20T22:26:56.778054Z","shell.execute_reply":"2024-12-20T22:26:56.788552Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def plot_images_with_generated(iteration: int, content_image, style_image, generated_image) -> None:\n    images_list = [content_image, style_image, generated_image]\n    images_titles = [\"Content Image\",\n                     \"Style Image\",\n                     \"Generated Image - {0} step\".format(iteration)]\n    fig, axs = plt.subplots(1, len(images_list), figsize=(14, 10))\n    i = 0\n\n    for (image, title) in zip(images_list, images_titles):\n        axs[i].imshow(np.squeeze(image, axis=0))\n        axs[i].set_title(title)\n        axs[i].axis('off')\n        i += 1\n\n    plt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:56.791159Z","iopub.execute_input":"2024-12-20T22:26:56.791632Z","iopub.status.idle":"2024-12-20T22:26:56.802620Z","shell.execute_reply.started":"2024-12-20T22:26:56.791571Z","shell.execute_reply":"2024-12-20T22:26:56.801590Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"VGG19_model = tf.keras.applications.VGG19(include_top=False, weights='imagenet')\nVGG19_model.trainable = False","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:56.804198Z","iopub.execute_input":"2024-12-20T22:26:56.804645Z","iopub.status.idle":"2024-12-20T22:26:57.918486Z","shell.execute_reply.started":"2024-12-20T22:26:56.804596Z","shell.execute_reply":"2024-12-20T22:26:57.917277Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for layer in VGG19_model.layers:\n  print(layer.name)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:57.920501Z","iopub.execute_input":"2024-12-20T22:26:57.920843Z","iopub.status.idle":"2024-12-20T22:26:57.926193Z","shell.execute_reply.started":"2024-12-20T22:26:57.920808Z","shell.execute_reply":"2024-12-20T22:26:57.925096Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"style_layers = ['block1_conv1',\n                'block2_conv1',\n                'block3_conv1',\n                'block4_conv1',\n                'block5_conv1']\n\ncontent_layers = ['block4_conv2']\n\nstyle_and_content_layers = style_layers + content_layers\n\nnum_content_layers = len(content_layers)\nnum_style_layers = len(style_layers)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:57.927476Z","iopub.execute_input":"2024-12-20T22:26:57.927853Z","iopub.status.idle":"2024-12-20T22:26:57.940675Z","shell.execute_reply.started":"2024-12-20T22:26:57.927806Z","shell.execute_reply":"2024-12-20T22:26:57.939620Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"style_weight=150\ncontent_weight=10\n\nstyle_weights = {'block1_conv1': 1.,\n                 'block2_conv1': 0.8,\n                 'block3_conv1': 0.6,\n                 'block4_conv1': 0.5,\n                 'block5_conv1': 0.3} ","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:57.942433Z","iopub.execute_input":"2024-12-20T22:26:57.942774Z","iopub.status.idle":"2024-12-20T22:26:57.953329Z","shell.execute_reply.started":"2024-12-20T22:26:57.942743Z","shell.execute_reply":"2024-12-20T22:26:57.952096Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"number_of_images = 1\nepochs = 2000\nlearning_rate=0.001\nbeta_1=0.92\nepsilon=1e-07\n\nearly_stop_threshold = 4343185000000\nearly_stop_patience = 10","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:57.954903Z","iopub.execute_input":"2024-12-20T22:26:57.955348Z","iopub.status.idle":"2024-12-20T22:26:57.966963Z","shell.execute_reply.started":"2024-12-20T22:26:57.955313Z","shell.execute_reply":"2024-12-20T22:26:57.965756Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_save_location = \"../images/\"\n\n!mkdir ../images\n\nloss_all = []\nbest_loss_all = []\nbest_step_loss_all = []\n\nstyle_loss_list_all = []\ncontent_loss_list_all = []\n\nstyle_accuracy_list_all = []\ncontent_accuracy_list_all = []","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:57.968795Z","iopub.execute_input":"2024-12-20T22:26:57.969199Z","iopub.status.idle":"2024-12-20T22:26:59.085123Z","shell.execute_reply.started":"2024-12-20T22:26:57.969166Z","shell.execute_reply":"2024-12-20T22:26:59.083414Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for image_number in range(1, number_of_images + 1):\n    random_style_image = train_monet_after_preprocessing.skip(random.randint(0,images_number_monet - 1)).take(1)\n    random_content_image = train_photo_after_preprocessing.skip(random.randint(0,images_number_photo - 1)).take(1)\n\n    random_style_image = np.squeeze(np.array(list(random_style_image.as_numpy_iterator())), axis=0)\n    random_content_image = np.squeeze(np.array(list(random_content_image.as_numpy_iterator())), axis=0)\n\n    generate_image = tf.Variable(random_content_image)\n\n    losses_current = []\n    style_loss_list_current = []\n    content_loss_list_current = []\n\n    extractor = style_model(style_layers, content_layers, VGG19_model)\n    style_targets = extractor(random_style_image)['style']\n    content_targets = extractor(random_content_image)['content']\n\n    opt = tf.optimizers.Adam(learning_rate=learning_rate, beta_1=beta_1, epsilon=epsilon)\n\n    early_stop_counter = 0\n    best_loss = None\n    best_image = None\n    best_step = None\n\n    start_time = time.time()\n    print(\"[Epoch Number:\",image_number,\"]\")\n\n    # Train image number of epochs\n    for i in range(epochs):\n        loss, style_loss, content_loss = train_step(generate_image)\n\n        if best_loss:\n          if best_loss - loss >= early_stop_threshold:\n            best_loss = loss\n            best_image = generate_image.read_value().numpy()\n            best_step = i\n            early_stop_counter = 0\n          else:\n            early_stop_counter += 1\n        else:\n            best_loss = loss\n            best_image = generate_image.read_value().numpy()\n            best_step = i\n\n        if(i%20==0):\n            generate_image_current = generate_image.read_value().numpy()\n\n            losses_current.append(loss)\n            style_loss_list_current.append(style_loss)\n            content_loss_list_current.append(content_loss)\n\n            generate_targets = extractor(generate_image_current)\n\n            print(f\"Step: {i}\")\n            print(f\"Loss: {loss.numpy()}\")\n            print(f\"Style Loss: {style_loss.numpy()}\")\n            print(f\"Content Loss: {content_loss.numpy()}\")\n\n            if (i%100 == 0):\n              plot_images_with_generated(str(i), random_content_image, random_style_image, generate_image_current)\n\n        if early_stop_counter == early_stop_patience and best_loss:\n          generate_image_current = best_image\n          print(f\"Stopped at iteration {i} after {early_stop_counter} iteration best_loss didnt updated more than {early_stop_threshold} loss\")\n          break\n\n    generate_image_last = generate_image.read_value().numpy()\n\n    clear_output(wait=True)\n\n    print(\"Image generate total time: {:.2f} seconds\".format(time.time() - start_time))\n    plot_images_with_generated(f\"BEST IMAGE {best_step}\", random_content_image, random_style_image, best_image)\n\n    loss_all.append(losses_current)\n    best_loss_all.append(best_loss)\n    best_step_loss_all.append(best_step)\n    style_loss_list_all.append(style_loss_list_current)\n    content_loss_list_all.append(content_loss_list_current)\n\n    save_image(image_number, generate_image_last, image_save_location, (256,256))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T22:26:59.087141Z","iopub.execute_input":"2024-12-20T22:26:59.087564Z","iopub.status.idle":"2024-12-20T23:16:21.863228Z","shell.execute_reply.started":"2024-12-20T22:26:59.087511Z","shell.execute_reply":"2024-12-20T23:16:21.861203Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"shutil.make_archive(\"/kaggle/working/images\", 'zip', \"/kaggle/input/images\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T23:16:21.866214Z","iopub.execute_input":"2024-12-20T23:16:21.866744Z","iopub.status.idle":"2024-12-20T23:16:21.879395Z","shell.execute_reply.started":"2024-12-20T23:16:21.866679Z","shell.execute_reply":"2024-12-20T23:16:21.878265Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"firstTotalLossList = [x.numpy() for x in loss_all[0]]\nlen_of_loss = [i*20 for i in range(len(firstTotalLossList))]\n\n\nplt.figure(figsize=(7, 5))\nplt.plot(len_of_loss, firstTotalLossList)\nplt.title(\"Model loss for first image\")\nplt.xlabel(\"epoch\")\nplt.ylabel(\"loss\")\n\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-20T23:16:21.881125Z","iopub.execute_input":"2024-12-20T23:16:21.881613Z","iopub.status.idle":"2024-12-20T23:16:22.145316Z","shell.execute_reply.started":"2024-12-20T23:16:21.881556Z","shell.execute_reply":"2024-12-20T23:16:22.144095Z"}},"outputs":[],"execution_count":null}]}