{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":7327,"databundleVersionId":861871,"sourceType":"competition"}],"dockerImageVersionId":30588,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\n\nfrom IPython.display import Image\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import LabelEncoder\nfrom tensorflow.keras.utils import to_categorical\nfrom tensorflow.keras.applications import EfficientNetB4, Xception, ResNet50\nfrom tensorflow.keras.layers import GlobalAveragePooling2D, concatenate\nfrom tensorflow.keras.models import Model\nfrom tensorflow.keras.callbacks import EarlyStopping, ModelCheckpoint\nfrom tensorflow.keras.models import load_model\nfrom tensorflow.keras.layers import Input\nfrom keras.layers import Dense, Conv2D, Flatten,Input,Dropout,MaxPooling2D\nfrom tensorflow.keras import datasets, layers, models\nfrom tensorflow.math import confusion_matrix\nfrom matplotlib.pyplot import imread\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom keras.preprocessing.image import ImageDataGenerator\nimport os\nimport cv2\nimport warnings\nwarnings.filterwarnings(\"ignore\")\nwarnings.warn(\"this will not show\")\nimport tensorflow as tf\n\nfrom tensorflow import keras\nfrom tensorflow.keras.models import Sequential\nimport tensorflow_hub as hub\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:04.379053Z","iopub.execute_input":"2023-12-02T16:56:04.379536Z","iopub.status.idle":"2023-12-02T16:56:04.392175Z","shell.execute_reply.started":"2023-12-02T16:56:04.379495Z","shell.execute_reply":"2023-12-02T16:56:04.390759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gpus = tf.config.experimental.list_physical_devices('GPU')\nfor gpu in gpus:\n    print(\"Name:\", gpu.name, \"  Type:\", gpu.device_type)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:04.394614Z","iopub.execute_input":"2023-12-02T16:56:04.395036Z","iopub.status.idle":"2023-12-02T16:56:04.406343Z","shell.execute_reply.started":"2023-12-02T16:56:04.395002Z","shell.execute_reply":"2023-12-02T16:56:04.405227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\nif tf.test.is_gpu_available():\n    print(\"GPU is available.\")\nelse:\n    print(\"GPU is not available.\")\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:04.408299Z","iopub.execute_input":"2023-12-02T16:56:04.409235Z","iopub.status.idle":"2023-12-02T16:56:04.424541Z","shell.execute_reply.started":"2023-12-02T16:56:04.409200Z","shell.execute_reply":"2023-12-02T16:56:04.423455Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = pd.read_csv(\"../input/dog-breed-identification/labels.csv\")\nlabels\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:04.427028Z","iopub.execute_input":"2023-12-02T16:56:04.427851Z","iopub.status.idle":"2023-12-02T16:56:04.486203Z","shell.execute_reply.started":"2023-12-02T16:56:04.427799Z","shell.execute_reply":"2023-12-02T16:56:04.484826Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_submission_csv=pd.read_csv(\"/kaggle/input/dog-breed-identification/sample_submission.csv\")\nsample_submission_csv","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:04.487689Z","iopub.execute_input":"2023-12-02T16:56:04.488116Z","iopub.status.idle":"2023-12-02T16:56:05.337823Z","shell.execute_reply.started":"2023-12-02T16:56:04.488081Z","shell.execute_reply":"2023-12-02T16:56:05.336915Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labelnames=pd.read_csv(\"/kaggle/input/dog-breed-identification/sample_submission.csv\").keys()[1:]\nlabelnames\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T22:53:17.108151Z","iopub.execute_input":"2023-12-02T22:53:17.108638Z","iopub.status.idle":"2023-12-02T22:53:17.617510Z","shell.execute_reply.started":"2023-12-02T22:53:17.108600Z","shell.execute_reply":"2023-12-02T22:53:17.616387Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# datamın olduğu klasörün yolunu bir değişkene atıyorum.\nmy_data_dir = \"/kaggle/input/dog-breed-identification\"","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:05.739458Z","iopub.execute_input":"2023-12-02T16:56:05.739917Z","iopub.status.idle":"2023-12-02T16:56:05.744907Z","shell.execute_reply.started":"2023-12-02T16:56:05.739883Z","shell.execute_reply":"2023-12-02T16:56:05.743710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nos.listdir(my_data_dir)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:05.746412Z","iopub.execute_input":"2023-12-02T16:56:05.746912Z","iopub.status.idle":"2023-12-02T16:56:05.760967Z","shell.execute_reply.started":"2023-12-02T16:56:05.746869Z","shell.execute_reply":"2023-12-02T16:56:05.759690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\ntest_path = os.path.join(my_data_dir, 'test')     \ntrain_path = os.path.join(my_data_dir, 'train')  \n\n# os.path.join bizim işletim sistemize göre dosya yollarını belirliyor.","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:13.161500Z","iopub.execute_input":"2023-12-02T16:56:13.162741Z","iopub.status.idle":"2023-12-02T16:56:13.167789Z","shell.execute_reply.started":"2023-12-02T16:56:13.162697Z","shell.execute_reply":"2023-12-02T16:56:13.166515Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test=os.listdir(test_path)\n","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:14:52.299742Z","iopub.execute_input":"2023-12-01T18:14:52.300106Z","iopub.status.idle":"2023-12-01T18:14:53.246446Z","shell.execute_reply.started":"2023-12-01T18:14:52.300075Z","shell.execute_reply":"2023-12-01T18:14:53.245312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntest[0]","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:14:53.248611Z","iopub.execute_input":"2023-12-01T18:14:53.249164Z","iopub.status.idle":"2023-12-01T18:14:53.258149Z","shell.execute_reply.started":"2023-12-01T18:14:53.249118Z","shell.execute_reply":"2023-12-01T18:14:53.256984Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(test) ","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:14:53.259240Z","iopub.execute_input":"2023-12-01T18:14:53.259588Z","iopub.status.idle":"2023-12-01T18:14:53.268547Z","shell.execute_reply.started":"2023-12-01T18:14:53.259556Z","shell.execute_reply":"2023-12-01T18:14:53.267604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = np.array(sorted(test))\ntest","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:14:53.270275Z","iopub.execute_input":"2023-12-01T18:14:53.270925Z","iopub.status.idle":"2023-12-01T18:14:53.290549Z","shell.execute_reply.started":"2023-12-01T18:14:53.270878Z","shell.execute_reply":"2023-12-01T18:14:53.288971Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=os.listdir(train_path)\n","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:14:53.292376Z","iopub.execute_input":"2023-12-01T18:14:53.292834Z","iopub.status.idle":"2023-12-01T18:14:54.203751Z","shell.execute_reply.started":"2023-12-01T18:14:53.292798Z","shell.execute_reply":"2023-12-01T18:14:54.202323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(train) ","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:14:54.205231Z","iopub.execute_input":"2023-12-01T18:14:54.206209Z","iopub.status.idle":"2023-12-01T18:14:54.213035Z","shell.execute_reply.started":"2023-12-01T18:14:54.206167Z","shell.execute_reply":"2023-12-01T18:14:54.211760Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=np.array(sorted(train))\ntrain","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:14:54.214679Z","iopub.execute_input":"2023-12-01T18:14:54.215076Z","iopub.status.idle":"2023-12-01T18:14:54.236731Z","shell.execute_reply.started":"2023-12-01T18:14:54.215040Z","shell.execute_reply":"2023-12-01T18:14:54.235284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"'U', Unicode tipini temsil eder.Unicode, dunya genelindeki bilgisayar\n sistemlerinde metin karakterlerini temsil etmek için kullanılan bir standarttır.  \n36, her bir karakter dizisinin en fazla 36 karakter uzunluğunda olduğunu belirtir.\n         ","metadata":{}},{"cell_type":"code","source":"# Create pathnames from image ID's\nfilenames = [train_path + fname + \".jpg\" for fname in labels[\"id\"]]\n\n# Check the first 10 filenames\nfilenames[:10]","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:18.515100Z","iopub.execute_input":"2023-12-02T16:56:18.515511Z","iopub.status.idle":"2023-12-02T16:56:18.530292Z","shell.execute_reply.started":"2023-12-02T16:56:18.515479Z","shell.execute_reply":"2023-12-02T16:56:18.528817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nif len(os.listdir(train_path)) == len(filenames):\n  print(\"Filenames match actual amount of files!\")\nelse:\n  print(\"Filenames do not match actual amount of files, check the target directory.\")","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:14:54.253762Z","iopub.execute_input":"2023-12-01T18:14:54.254236Z","iopub.status.idle":"2023-12-01T18:14:54.270216Z","shell.execute_reply.started":"2023-12-01T18:14:54.254160Z","shell.execute_reply":"2023-12-01T18:14:54.268673Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#dog-breed-identification dizininde gezinin ve dosya sayısını listeleyin:klasorlerin yapısını gormek için \nfor dirpath, dirnames, filenames in os.walk(my_data_dir):\n    print(\n        f\"There are {len(dirnames)} directories and {len(filenames)} images in '{dirpath}'.\")","metadata":{"execution":{"iopub.status.busy":"2023-12-02T12:39:20.118388Z","iopub.execute_input":"2023-12-02T12:39:20.118806Z","iopub.status.idle":"2023-12-02T12:39:51.780557Z","shell.execute_reply.started":"2023-12-02T12:39:20.118772Z","shell.execute_reply":"2023-12-02T12:39:51.779340Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels[\"filenames\"] = filenames\nlabels","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:15:27.986280Z","iopub.execute_input":"2023-12-01T18:15:27.986648Z","iopub.status.idle":"2023-12-01T18:15:28.005050Z","shell.execute_reply.started":"2023-12-01T18:15:27.986614Z","shell.execute_reply":"2023-12-01T18:15:28.003729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels[\"breed\"].value_counts()#.plot.bar(figsize=(20, 10));","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:26.342997Z","iopub.execute_input":"2023-12-02T16:56:26.343465Z","iopub.status.idle":"2023-12-02T16:56:26.359476Z","shell.execute_reply.started":"2023-12-02T16:56:26.343393Z","shell.execute_reply":"2023-12-02T16:56:26.358126Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path1 = os.path.join(train_path,train[0])\npath2 = os.path.join(test_path,test[0])\ntrain_img = imread(path1)\ntest_img = imread(path2)\n# elimizdeki resimler png formatında biz bunları imread ile array'e çeviriyoruz.\n#çunku imshow metodu  array alabildiği için imread bu işlevi görüyor  \n#imread'i matplotlib içerisinden import ettik\ntrain_img","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\"train_img\" adlı bir array verisidir. Bu array, bir resmin piksel değerlerini içerir. Her bir piksel, üç değerden oluşan bir RGB (Kırmızı, Yeşil, Mavi) renk değeri içerir.\n\nArray'in şekli (boyutu) 3 boyutludur. İlk boyut, resmin yüksekliğini temsil eder. İkinci boyut, resmin genişliğini temsil eder. Üçüncü boyut ise RGB renk kanallarını temsil eder.\n\nÖrneğin, \"train_img\" array'inin şekli (yükseklik, genişlik, 3) olabilir. Bu durumda, resim 3 renk kanalına (RGB) sahip olur. Her bir piksel, bu üç renk kanalının değerlerini içeren bir vektör olarak temsil edilir.\n\nÖrneğin, \"train_img\" array'inin ilk pikseli şu şekilde temsil edilebilir: [108, 46, 0]. Bu pikselin kırmızı bileşeni 108, yeşil bileşeni 46 ve mavi bileşeni 0'dır.\n\nBu şekilde, tüm resmin piksel değerleri array içinde temsil edilir.\n\n","metadata":{}},{"cell_type":"code","source":"train_img.shape","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:15:28.079358Z","iopub.execute_input":"2023-12-01T18:15:28.080072Z","iopub.status.idle":"2023-12-01T18:15:28.087641Z","shell.execute_reply.started":"2023-12-01T18:15:28.080031Z","shell.execute_reply":"2023-12-01T18:15:28.086363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# imshow ile array formatındaki resmi artık okutabiliriz.\nplt.imshow(train_img)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:15:28.089395Z","iopub.execute_input":"2023-12-01T18:15:28.089801Z","iopub.status.idle":"2023-12-01T18:15:28.463599Z","shell.execute_reply.started":"2023-12-01T18:15:28.089766Z","shell.execute_reply":"2023-12-01T18:15:28.462489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# View an image\nimport random\n\n\ndef view_random_image(target_dir, target_class):\n    \"\"\"Display and return an image given the target_dir and target_class.\n    Args:\n        target_dir (str): The full or relative path of the directory of the target.\n        target_class (str): The name of the target_class you want to display and return.\n    Returns:\n        img: (np.ndarray): Image as numpy array.\n    \"\"\"\n    # Setup target directory (we'll view images from here)\n    target_folder = os.path.join(target_dir, target_class)\n\n    # Get a random image path\n    random_image = random.sample(os.listdir(target_folder), 1)\n\n    # Read in the image and plot it using matplotlib\n    img = imread(os.path.join(target_folder, random_image[0]))\n    plt.imshow(img)\n    plt.title(target_class)\n    plt.axis(\"off\")\n\n    print(f\"Image shape: {img.shape}\")  # show the shape of the image\n\n    return img\n\n\nimg = view_random_image(target_dir=my_data_dir, target_class=\"train\")","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:15:28.464994Z","iopub.execute_input":"2023-12-01T18:15:28.465596Z","iopub.status.idle":"2023-12-01T18:15:28.767928Z","shell.execute_reply.started":"2023-12-01T18:15:28.465550Z","shell.execute_reply":"2023-12-01T18:15:28.766933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = [\n    imread(os.path.join(my_data_dir, \"train\", image)).shape[0]\n    for image in os.listdir(os.path.join(my_data_dir, \"train\"))\n]\nz = [\n    imread(os.path.join(my_data_dir, \"train\", image)).shape[1]\n    for image in os.listdir(os.path.join(my_data_dir, \"train\"))\n]","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:15:28.769190Z","iopub.execute_input":"2023-12-01T18:15:28.770198Z","iopub.status.idle":"2023-12-01T18:17:33.967735Z","shell.execute_reply.started":"2023-12-01T18:15:28.770160Z","shell.execute_reply":"2023-12-01T18:17:33.966893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.mean(x), np.median(x)","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:17:33.969146Z","iopub.execute_input":"2023-12-01T18:17:33.970176Z","iopub.status.idle":"2023-12-01T18:17:33.982350Z","shell.execute_reply.started":"2023-12-01T18:17:33.970133Z","shell.execute_reply":"2023-12-01T18:17:33.981269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.mean(z), np.median(z)","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:17:33.990301Z","iopub.execute_input":"2023-12-01T18:17:33.990944Z","iopub.status.idle":"2023-12-01T18:17:34.001226Z","shell.execute_reply.started":"2023-12-01T18:17:33.990908Z","shell.execute_reply":"2023-12-01T18:17:34.000012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.scatterplot(x=x, y=z)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:17:34.003007Z","iopub.execute_input":"2023-12-01T18:17:34.003470Z","iopub.status.idle":"2023-12-01T18:17:34.274676Z","shell.execute_reply.started":"2023-12-01T18:17:34.003435Z","shell.execute_reply":"2023-12-01T18:17:34.273480Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels[\"breed\"].value_counts()#.plot.bar(figsize=(20, 10));","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:17:34.276512Z","iopub.execute_input":"2023-12-01T18:17:34.276969Z","iopub.status.idle":"2023-12-01T18:17:34.288919Z","shell.execute_reply.started":"2023-12-01T18:17:34.276928Z","shell.execute_reply":"2023-12-01T18:17:34.287809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"codes = range(len(labelnames))\nbreed_to_code = dict(zip(labelnames, codes))\ncode_to_breed = dict(zip(codes, labelnames))\nlabels['target'] =  [breed_to_code[x] for x in labels[\"breed\"]]\nlabels","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:56:52.749612Z","iopub.execute_input":"2023-12-02T16:56:52.750069Z","iopub.status.idle":"2023-12-02T16:56:52.774906Z","shell.execute_reply.started":"2023-12-02T16:56:52.750023Z","shell.execute_reply":"2023-12-02T16:56:52.773821Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path = '/kaggle/input/dog-breed-identification/train'\ntest_path =  \"/kaggle/input/dog-breed-identification/test\"","metadata":{"execution":{"iopub.status.busy":"2023-12-02T17:02:39.549010Z","iopub.execute_input":"2023-12-02T17:02:39.549461Z","iopub.status.idle":"2023-12-02T17:02:39.555365Z","shell.execute_reply.started":"2023-12-02T17:02:39.549425Z","shell.execute_reply":"2023-12-02T17:02:39.554055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport os\nimport numpy as np\n\n# Dosya yollarını içeren dataframe'i oluşturun (df)\n# Burada df, verilerinizi içeren bir dataframe olmalıdır.\ndef read_and_resize_image_rgb(file_path):\n    img = cv2.imread(file_path)\n    img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) \n    img_rgb_resized = cv2.resize(img_rgb, (224, 224))\n    return img_rgb_resized\n\n# Dosya yollarını içeren sütunu kullanarak resimleri okuyun ve boyutlandırın\nprocessed_images = []\nfor idx, filename in enumerate(labels['id']):\n    img_path = os.path.join(train_path, filename + '.jpg')\n    resized_img = read_and_resize_image_rgb(img_path)\n    processed_images.append(resized_img)\n\n\n# Liste içindeki resimleri NumPy array'e dönüştürün\nprocessed_images_array = np.array(processed_images)\n\n\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T16:59:03.673688Z","iopub.execute_input":"2023-12-02T16:59:03.674121Z","iopub.status.idle":"2023-12-02T17:01:29.415640Z","shell.execute_reply.started":"2023-12-02T16:59:03.674086Z","shell.execute_reply":"2023-12-02T17:01:29.413988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"processed_images shape:\", processed_images_array.shape)\nprint(\"processed_images dtype:\", processed_images_array.dtype)\nprint(\"labels shape:\",labels['target'].shape)  # Bu sadece numpy dizileri için geçerlidir\nprint(\"labels dtype:\",labels['target'].dtype)\n\n# processed_images'in ilk resmi görselleştirme\nimport matplotlib.pyplot as plt\nplt.imshow(processed_images_array[0])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-02T17:01:29.418028Z","iopub.execute_input":"2023-12-02T17:01:29.418514Z","iopub.status.idle":"2023-12-02T17:01:29.825751Z","shell.execute_reply.started":"2023-12-02T17:01:29.418479Z","shell.execute_reply":"2023-12-02T17:01:29.824517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def read_and_resize_image_rgb(file_path):\n    img = cv2.imread(file_path)\n    img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) \n    img_rgb_resized = cv2.resize(img_rgb, (224, 224))\n    return img_rgb_resized\n\n# Dosya yollarını içeren sütunu kullanarak resimleri okuyun ve boyutlandırın\nprocessed2_images = []\nfor idx, filename in enumerate(sample_submission_csv['id']):\n    img_path = os.path.join(test_path, filename + '.jpg')\n    resized_img = read_and_resize_image_rgb(img_path)\n    processed2_images.append(resized_img)\n\n\n# Liste içindeki resimleri NumPy array'e dönüştürün\nprocessed2_images_array = np.array(processed2_images)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T17:15:29.548488Z","iopub.execute_input":"2023-12-02T17:15:29.549049Z","iopub.status.idle":"2023-12-02T17:18:16.057966Z","shell.execute_reply.started":"2023-12-02T17:15:29.549005Z","shell.execute_reply":"2023-12-02T17:18:16.056697Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(\"processed_images shape:\", processed2_images_array.shape)\nprint(\"processed_images dtype:\", processed2_images_array.dtype)\nprint(\"labels shape:\",sample_submission_csv['id'].shape)  # Bu sadece numpy dizileri için geçerlidir\nprint(\"labels dtype:\",sample_submission_csv['id'].dtype)\n\n# processed_images'in ilk resmi görselleştirme\nimport matplotlib.pyplot as plt\nplt.imshow(processed2_images_array[0])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-12-02T17:18:48.718198Z","iopub.execute_input":"2023-12-02T17:18:48.718639Z","iopub.status.idle":"2023-12-02T17:18:49.103284Z","shell.execute_reply.started":"2023-12-02T17:18:48.718601Z","shell.execute_reply":"2023-12-02T17:18:49.102264Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train Test Split","metadata":{}},{"cell_type":"code","source":"X=processed_images_array\ny=labels[\"target\"]\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, stratify=y, random_state=42)\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T17:19:08.628747Z","iopub.execute_input":"2023-12-02T17:19:08.629198Z","iopub.status.idle":"2023-12-02T17:19:09.369364Z","shell.execute_reply.started":"2023-12-02T17:19:08.629159Z","shell.execute_reply":"2023-12-02T17:19:09.368086Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train.shape)\nprint(X_test.shape)\nprint(y_train.shape)\nprint(y_test.shape)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T17:19:12.889536Z","iopub.execute_input":"2023-12-02T17:19:12.890285Z","iopub.status.idle":"2023-12-02T17:19:12.896857Z","shell.execute_reply.started":"2023-12-02T17:19:12.890248Z","shell.execute_reply":"2023-12-02T17:19:12.895518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Scaling\n\nLet's check the images if they are needed to be scaled or not","metadata":{}},{"cell_type":"code","source":"train_img.max(),train_img.min()","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:18:25.034287Z","iopub.execute_input":"2023-12-01T18:18:25.035164Z","iopub.status.idle":"2023-12-01T18:18:25.050174Z","shell.execute_reply.started":"2023-12-01T18:18:25.035107Z","shell.execute_reply":"2023-12-01T18:18:25.048830Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_img.max(),test_img.min()","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:18:25.051902Z","iopub.execute_input":"2023-12-01T18:18:25.052412Z","iopub.status.idle":"2023-12-01T18:18:25.063946Z","shell.execute_reply.started":"2023-12-01T18:18:25.052363Z","shell.execute_reply":"2023-12-01T18:18:25.061603Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"As we see above, images need to be scaled","metadata":{}},{"cell_type":"markdown","source":"# Image Data Generator","metadata":{}},{"cell_type":"markdown","source":"Image Manipulation\n\nWe can use the ImageDataGenerator to manipulate the images with rotation, resizing, and scaling so the model becomes more robust to different images that our data set doesn't have. ImageDataGenerator does the followings.\n\nAccepts a batch of images used for training.\nApplies a series of random transformations to each image in the batch.\nReplaces the original batch with randomly transformed batch.\nTraining the CNN on this randomly transformed batch.\nThe goal of applying data augmentation is to have a more generalized model.\n\nData augmentation is a way to try and prevent a model overfitting. If your model is overfiting (e.g. the validation loss keeps increasing), you may want to try using data augmentation.","metadata":{}},{"cell_type":"code","source":"train_datagen = ImageDataGenerator(\n    rotation_range=30,\n    width_shift_range=0.2,\n    height_shift_range=0.2,\n    rescale=1./255,\n    shear_range=0.2,\n    zoom_range=0.2,\n    horizontal_flip=True,\n    fill_mode='nearest')\n\ntest_datagen=ImageDataGenerator(rescale=1./255)          ","metadata":{"execution":{"iopub.status.busy":"2023-12-02T17:19:17.531248Z","iopub.execute_input":"2023-12-02T17:19:17.532114Z","iopub.status.idle":"2023-12-02T17:19:17.538544Z","shell.execute_reply.started":"2023-12-02T17:19:17.532073Z","shell.execute_reply":"2023-12-02T17:19:17.537103Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"training_set=train_datagen.flow(X_train,y=y_train,batch_size=128)\ntesting_set=test_datagen.flow(X_test,y=y_test,batch_size=128)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T17:19:20.551211Z","iopub.execute_input":"2023-12-02T17:19:20.551660Z","iopub.status.idle":"2023-12-02T17:19:22.850968Z","shell.execute_reply.started":"2023-12-02T17:19:20.551609Z","shell.execute_reply":"2023-12-02T17:19:22.849727Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential([\n    Input(shape=(224, 224, 3)),\n    Conv2D(16, (3, 3), activation='relu', padding='same'),\n    MaxPooling2D((2, 2)),\n    Conv2D(32, (3, 3), activation='relu', padding='same'),\n    MaxPooling2D((2, 2)),\n    Conv2D(64, (3, 3), activation='relu', padding='same'),\n    MaxPooling2D((2, 2)),\n    Flatten(),\n    Dense(128, activation='sigmoid'),\n    Dropout(0.2),\n    Dense(120, activation='softmax')\n])\nmodel.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:18:27.362934Z","iopub.execute_input":"2023-12-01T18:18:27.363304Z","iopub.status.idle":"2023-12-01T18:18:27.705835Z","shell.execute_reply.started":"2023-12-01T18:18:27.363272Z","shell.execute_reply":"2023-12-01T18:18:27.704572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Early Stopping ayarları\nearly_stopping = EarlyStopping(monitor='val_loss', patience=3, restore_best_weights=True)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:18:27.707557Z","iopub.execute_input":"2023-12-01T18:18:27.707984Z","iopub.status.idle":"2023-12-01T18:18:27.756945Z","shell.execute_reply.started":"2023-12-01T18:18:27.707940Z","shell.execute_reply":"2023-12-01T18:18:27.752097Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history=model.fit_generator(training_set,validation_data = testing_set,epochs = 5,   callbacks=[early_stopping] )","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:18:27.758729Z","iopub.execute_input":"2023-12-01T18:18:27.759201Z","iopub.status.idle":"2023-12-01T18:44:42.395919Z","shell.execute_reply.started":"2023-12-01T18:18:27.759157Z","shell.execute_reply":"2023-12-01T18:44:42.394813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Eğitim sürecinin sonunda modelin başarı oranını değerlendirin\ntest_loss, test_accuracy = model.evaluate(X_test, y_test)\nprint(f\"Test Loss: {test_loss}, Test Accuracy: {test_accuracy}\")","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:44:42.397892Z","iopub.execute_input":"2023-12-01T18:44:42.398597Z","iopub.status.idle":"2023-12-01T18:45:03.844181Z","shell.execute_reply.started":"2023-12-01T18:44:42.398545Z","shell.execute_reply":"2023-12-01T18:45:03.842708Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport pandas as pd\n\n# Eğitim geçmişini DataFrame'e dönüştürme\nhistory_df = pd.DataFrame(history.history)\n\n# Grafik oluşturma\nplt.figure(figsize=(12, 6))\n\n# Loss değerlerini göster\nplt.subplot(1, 2, 1)\nplt.plot(history_df['loss'], label='loss')\nplt.plot(history_df['val_loss'], label='val_loss')\nplt.title('Model Loss')\nplt.xlabel('Epoch')\nplt.ylabel('Loss')\nplt.legend()\n\n# Accuracy değerlerini göster\nplt.subplot(1, 2, 2)\nplt.plot(history_df['accuracy'], label='accuracy')\nplt.plot(history_df['val_accuracy'], label='val_accuracy')\nplt.title('Model Accuracy')\nplt.xlabel('Epoch')\nplt.ylabel('Accuracy')\nplt.legend()\n\nplt.tight_layout()\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-12-01T18:45:03.846559Z","iopub.execute_input":"2023-12-01T18:45:03.847456Z","iopub.status.idle":"2023-12-01T18:45:04.711686Z","shell.execute_reply.started":"2023-12-01T18:45:03.847394Z","shell.execute_reply":"2023-12-01T18:45:04.710255Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Transfer Learning (EfficientNetB4, Xception, ResNet50)","metadata":{}},{"cell_type":"code","source":"#Bu fonksiyon, önceden eğitilmiş bir modelin belirli bir katmanından özellik haritaları almak için kullanılır. \ndef get_features(model_name, model_preprocessor, input_size, data):\n    input_layer = Input(input_size)\n    preprocessor = model_preprocessor(input_layer)\n    base_model = model_name(weights='imagenet', include_top=False, input_shape=input_size)(preprocessor)\n    avg = GlobalAveragePooling2D()(base_model)\n    feature_extractor = Model(inputs=input_layer, outputs=avg)\n    feature_maps = feature_extractor.predict(data, verbose=1)\n    print('Feature maps shape:', feature_maps.shape)\n    return feature_maps","metadata":{"execution":{"iopub.status.busy":"2023-12-02T17:20:23.988221Z","iopub.execute_input":"2023-12-02T17:20:23.988724Z","iopub.status.idle":"2023-12-02T17:20:23.996440Z","shell.execute_reply.started":"2023-12-02T17:20:23.988685Z","shell.execute_reply":"2023-12-02T17:20:23.995540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"##Bu örnekte, get_features fonksiyonu içinde, belirli bir modeli ve preprocessorü kullanarak özellik çıkarımı yapıyoruz.\n##Daha sonra, örnek modeller (EfficientNetB4, Xception, ResNet50) ve preprocessorleri \n#(effnet_preprocessor, xception_preprocessor, resnet_preprocessor) kullanarak bu özellik çıkarımını gerçekleştiriyoruz.\n\neffnet_preprocessor = tf.keras.applications.efficientnet.preprocess_input\neffnet_features = get_features(EfficientNetB4, effnet_preprocessor, (224, 224, 3),X)\n\nxception_preprocessor = tf.keras.applications.xception.preprocess_input\nxception_features = get_features(Xception, xception_preprocessor, (224, 224, 3), X)\n\nresnet_preprocessor = tf.keras.applications.resnet50.preprocess_input\nresnet_features = get_features(ResNet50, resnet_preprocessor, (224, 224, 3), X)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T17:20:27.053789Z","iopub.execute_input":"2023-12-02T17:20:27.054259Z","iopub.status.idle":"2023-12-02T18:12:42.049493Z","shell.execute_reply.started":"2023-12-02T17:20:27.054220Z","shell.execute_reply":"2023-12-02T18:12:42.048401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_features = np.concatenate([effnet_features, xception_features, resnet_features], axis=-1)\nprint('Final feature maps shape:', final_features.shape)\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T18:13:38.846360Z","iopub.execute_input":"2023-12-02T18:13:38.847631Z","iopub.status.idle":"2023-12-02T18:13:38.942530Z","shell.execute_reply.started":"2023-12-02T18:13:38.847579Z","shell.execute_reply":"2023-12-02T18:13:38.941198Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.layers import BatchNormalization\n\n\nmodel = Sequential()\nmodel.add(Dense(256, activation='relu', input_shape=(final_features.shape[1],)))\nmodel.add(Dropout(0.5))\nmodel.add(BatchNormalization())\nmodel.add(Dropout(0.3))\nmodel.add(Dense(128, activation='relu'))\n#model.add(BatchNormalization())\nmodel.add(Dropout(0.3))\nmodel.add(BatchNormalization())\nmodel.add(Dense(120, activation='softmax'))\n\n\nmodel.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\n\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T22:31:16.985395Z","iopub.execute_input":"2023-12-02T22:31:16.986484Z","iopub.status.idle":"2023-12-02T22:31:17.105010Z","shell.execute_reply.started":"2023-12-02T22:31:16.986443Z","shell.execute_reply":"2023-12-02T22:31:17.104095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#checkpoint = ModelCheckpoint('best_model.h5', monitor='val_accuracy', verbose=1, save_best_only=True, mode='min')\nearly_stopping = EarlyStopping(monitor='val_accuracy', patience=5, restore_best_weights=True)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T22:14:20.186551Z","iopub.execute_input":"2023-12-02T22:14:20.186991Z","iopub.status.idle":"2023-12-02T22:14:20.192165Z","shell.execute_reply.started":"2023-12-02T22:14:20.186955Z","shell.execute_reply":"2023-12-02T22:14:20.191271Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history = model.fit(final_features, y,\n                    batch_size=128,\n                    epochs=20,\n                    validation_split=0.2,\n                    callbacks=[ early_stopping])","metadata":{"execution":{"iopub.status.busy":"2023-12-02T22:31:20.480907Z","iopub.execute_input":"2023-12-02T22:31:20.481356Z","iopub.status.idle":"2023-12-02T22:31:47.809713Z","shell.execute_reply.started":"2023-12-02T22:31:20.481321Z","shell.execute_reply":"2023-12-02T22:31:47.808738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_df = pd.DataFrame(history.history)\nhistory_df[10:]","metadata":{"execution":{"iopub.status.busy":"2023-12-02T22:31:56.970959Z","iopub.execute_input":"2023-12-02T22:31:56.971375Z","iopub.status.idle":"2023-12-02T22:31:56.986592Z","shell.execute_reply.started":"2023-12-02T22:31:56.971341Z","shell.execute_reply":"2023-12-02T22:31:56.985348Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense\nfrom tensorflow.keras.optimizers import Adam\nfrom kerastuner.tuners import RandomSearch\n\n# Verilerinizi yükleyin ve işleyin\n# Örnek olarak, veri yükleme işlemlerini eklemelisiniz.\n\n# Modeli oluşturun ve derleyin\ndef build_model(hp):\n    model = Sequential()\n    model.add(Dropout(0.7, input_shape=(final_features.shape[1],)))\n    model.add(Dense(120, activation='softmax'))\n    model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\n\n    return model\n\n# Keras Tuner RandomSearch için tuner'ı oluşturun\ntuner = RandomSearch(\n    build_model,\n    objective='accuracy',\n    max_trials=5,  # Uygun bir sayı seçebilirsiniz\n    directory='my_dir',\n    project_name='dog_breed_classification'\n)\n\n\n\n# Hiperparametre aramasını başlatın\ntuner.search(x=final_features, y=y, epochs=20, validation_split=0.2,)\n\n# En iyi modeli ve hiperparametreleri alın\nbest_model = tuner.get_best_models(num_models=1)[0]\nbest_hyperparameters = tuner.oracle.get_best_trials(num_trials=1)[0].hyperparameters.values\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T22:06:19.214341Z","iopub.execute_input":"2023-12-02T22:06:19.214798Z","iopub.status.idle":"2023-12-02T22:06:19.762515Z","shell.execute_reply.started":"2023-12-02T22:06:19.214760Z","shell.execute_reply":"2023-12-02T22:06:19.761477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"history_df = pd.DataFrame(history.history)\nhistory_df[15:]","metadata":{"execution":{"iopub.status.busy":"2023-12-02T21:44:27.651327Z","iopub.execute_input":"2023-12-02T21:44:27.651845Z","iopub.status.idle":"2023-12-02T21:44:27.666288Z","shell.execute_reply.started":"2023-12-02T21:44:27.651804Z","shell.execute_reply":"2023-12-02T21:44:27.665151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n# Eğitim geçmişini DataFrame'e dönüştürme\nhistory_df = pd.DataFrame(history.history)\n\n# Grafik oluşturma\nplt.figure(figsize=(12, 6))\n\n# Loss değerlerini göster\nplt.subplot(1, 2, 1)\nplt.plot(history_df['loss'], label='loss')\nplt.plot(history_df['val_loss'], label='val_loss')\nplt.title('Model Loss')\nplt.xlabel('Epoch')\nplt.ylabel('Loss')\nplt.legend()\n\n# Accuracy değerlerini göster\nplt.subplot(1, 2, 2)\nplt.plot(history_df['accuracy'], label='accuracy')\nplt.plot(history_df['val_accuracy'], label='val_accuracy')\nplt.title('Model Accuracy')\nplt.xlabel('Epoch')\nplt.ylabel('Accuracy')\nplt.legend()\n\nplt.tight_layout()\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-12-02T22:32:23.108545Z","iopub.execute_input":"2023-12-02T22:32:23.109020Z","iopub.status.idle":"2023-12-02T22:32:45.044256Z","shell.execute_reply.started":"2023-12-02T22:32:23.108982Z","shell.execute_reply":"2023-12-02T22:32:45.042891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model Evaluation","metadata":{}},{"cell_type":"code","source":"#best_model = load_model('best_model.h5')","metadata":{"execution":{"iopub.status.busy":"2023-12-02T19:57:42.599614Z","iopub.execute_input":"2023-12-02T19:57:42.600067Z","iopub.status.idle":"2023-12-02T19:57:42.693084Z","shell.execute_reply.started":"2023-12-02T19:57:42.600033Z","shell.execute_reply":"2023-12-02T19:57:42.692031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n# Confusion matrix oluştur\nconf_matrix = confusion_matrix(true_labels, predicted_labels)\n\n# Heatmap'i oluştur\nplt.figure(figsize=(12, 10))\nsns.heatmap(conf_matrix, annot=True, cmap='Blues', fmt='d', xticklabels=class_to_num, yticklabels=class_to_num)\nplt.xlabel('Predicted')\nplt.ylabel('True')\nplt.title('Confusion Matrix')\nplt.xticks(rotation=90)\nplt.yticks(rotation=0)\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2023-12-01T19:39:32.911496Z","iopub.execute_input":"2023-12-01T19:39:32.911916Z","iopub.status.idle":"2023-12-01T19:39:33.956472Z","shell.execute_reply.started":"2023-12-01T19:39:32.911883Z","shell.execute_reply":"2023-12-01T19:39:33.954505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_path=\"/kaggle/input/dog-breed-identification/test\"","metadata":{"execution":{"iopub.status.busy":"2023-12-01T19:39:33.957636Z","iopub.status.idle":"2023-12-01T19:39:33.958113Z","shell.execute_reply.started":"2023-12-01T19:39:33.957879Z","shell.execute_reply":"2023-12-01T19:39:33.957904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"effnet_preprocessor = tf.keras.applications.efficientnet.preprocess_input\neffnet_features = get_features(EfficientNetB4, effnet_preprocessor, (224, 224, 3),processed2_images_array)\n\nxception_preprocessor = tf.keras.applications.xception.preprocess_input\n\nxception_features = get_features(Xception, xception_preprocessor, (224, 224, 3), processed2_images_array)\n\nresnet_preprocessor = tf.keras.applications.resnet50.preprocess_input\nresnet_features = get_features(ResNet50, resnet_preprocessor, (224, 224, 3), processed2_images_array)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T18:48:21.431415Z","iopub.execute_input":"2023-12-02T18:48:21.431904Z","iopub.status.idle":"2023-12-02T19:41:59.736530Z","shell.execute_reply.started":"2023-12-02T18:48:21.431865Z","shell.execute_reply":"2023-12-02T19:41:59.734880Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_features2 = np.concatenate([effnet_features, xception_features, resnet_features], axis=-1)\nprint('Final feature maps shape:', final_features2.shape)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T19:45:11.979688Z","iopub.execute_input":"2023-12-02T19:45:11.980710Z","iopub.status.idle":"2023-12-02T19:45:12.238180Z","shell.execute_reply.started":"2023-12-02T19:45:11.980619Z","shell.execute_reply":"2023-12-02T19:45:12.237136Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Predict test labels given test data features.\ny_pred = model.predict(final_features2, batch_size=128)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T22:34:20.513305Z","iopub.execute_input":"2023-12-02T22:34:20.513830Z","iopub.status.idle":"2023-12-02T22:34:22.084050Z","shell.execute_reply.started":"2023-12-02T22:34:20.513791Z","shell.execute_reply":"2023-12-02T22:34:22.083130Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = model.predict(processed2_images_array)\npredicted_labels = np.argmax(predictions, axis=1)\ntrue_labels = np.argmax(y)","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dog_breds=sorted(labelnames)\n\n\nn_classes = len(dog_breeds)\nclass_to_num = dict(zip(dog_breeds, range(n_classes)))\nclass_to_num","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for b in dog_breds:\n    sample_submission_csv[b] = y_pred[:,class_to_num[b]]\nsample_submission_csv.to_csv('pred.csv', index=None)","metadata":{"execution":{"iopub.status.busy":"2023-12-02T23:08:29.295348Z","iopub.execute_input":"2023-12-02T23:08:29.295724Z","iopub.status.idle":"2023-12-02T23:08:31.629103Z","shell.execute_reply.started":"2023-12-02T23:08:29.295692Z","shell.execute_reply":"2023-12-02T23:08:31.627926Z"},"trusted":true},"execution_count":null,"outputs":[]}]}