{"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":"# 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","execution":{"iopub.status.busy":"2023-10-13T09:53:05.768067Z","iopub.execute_input":"2023-10-13T09:53:05.76846Z","iopub.status.idle":"2023-10-13T09:53:43.452206Z","shell.execute_reply.started":"2023-10-13T09:53:05.768435Z","shell.execute_reply":"2023-10-13T09:53:43.45142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport os\nfrom PIL import Image\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout\nfrom tensorflow.keras.utils import to_categorical\n","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:53:43.453527Z","iopub.execute_input":"2023-10-13T09:53:43.453957Z","iopub.status.idle":"2023-10-13T09:53:51.944333Z","shell.execute_reply.started":"2023-10-13T09:53:43.453929Z","shell.execute_reply":"2023-10-13T09:53:51.943284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels_df = pd.read_csv('/kaggle/input/dog-breed-identification/labels.csv')\n","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:53:51.945505Z","iopub.execute_input":"2023-10-13T09:53:51.946136Z","iopub.status.idle":"2023-10-13T09:53:51.982408Z","shell.execute_reply.started":"2023-10-13T09:53:51.946082Z","shell.execute_reply":"2023-10-13T09:53:51.981505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dir = \"/kaggle/input/dog-breed-identification/train\"\ntest_dir = \"/kaggle/input/dog-breed-identification/test\"","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:53:51.984624Z","iopub.execute_input":"2023-10-13T09:53:51.985532Z","iopub.status.idle":"2023-10-13T09:53:51.989833Z","shell.execute_reply.started":"2023-10-13T09:53:51.985499Z","shell.execute_reply":"2023-10-13T09:53:51.988952Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def load_images(directory):\n    images = []\n    for filename in os.listdir(directory):\n        img = Image.open(os.path.join(directory, filename))\n        img = img.resize((128, 128))\n        img = np.array(img)\n        images.append(img)\n    return np.array(images)","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:53:51.991022Z","iopub.execute_input":"2023-10-13T09:53:51.99189Z","iopub.status.idle":"2023-10-13T09:53:52.001573Z","shell.execute_reply.started":"2023-10-13T09:53:51.991861Z","shell.execute_reply":"2023-10-13T09:53:52.000633Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_images = --------------------\ntest_images = ---------------------","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:53:52.002759Z","iopub.execute_input":"2023-10-13T09:53:52.003316Z","iopub.status.idle":"2023-10-13T09:57:05.752274Z","shell.execute_reply.started":"2023-10-13T09:53:52.003287Z","shell.execute_reply":"2023-10-13T09:57:05.751163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"label_mapping = -----------------------------------------------\n\nlabels = ------------------------------------------\n","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:57:05.7538Z","iopub.execute_input":"2023-10-13T09:57:05.754167Z","iopub.status.idle":"2023-10-13T09:57:05.776628Z","shell.execute_reply.started":"2023-10-13T09:57:05.754107Z","shell.execute_reply":"2023-10-13T09:57:05.775686Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_size = 0.2\nrandom_seed = 42","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:57:05.777925Z","iopub.execute_input":"2023-10-13T09:57:05.778685Z","iopub.status.idle":"2023-10-13T09:57:05.784813Z","shell.execute_reply.started":"2023-10-13T09:57:05.778656Z","shell.execute_reply":"2023-10-13T09:57:05.783858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"num_samples = ---------------\nnum_validation_samples = ---------------------","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:57:05.786238Z","iopub.execute_input":"2023-10-13T09:57:05.787147Z","iopub.status.idle":"2023-10-13T09:57:05.79821Z","shell.execute_reply.started":"2023-10-13T09:57:05.787097Z","shell.execute_reply":"2023-10-13T09:57:05.797334Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"indices = np.arange(num_samples)\nnp.random.seed(random_seed)\nnp.random.shuffle(indices)","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:57:05.801689Z","iopub.execute_input":"2023-10-13T09:57:05.802431Z","iopub.status.idle":"2023-10-13T09:57:05.810077Z","shell.execute_reply.started":"2023-10-13T09:57:05.802403Z","shell.execute_reply":"2023-10-13T09:57:05.809061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_indices = indices[num_validation_samples:]\nval_indices = indices[:num_validation_samples]","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:57:05.811651Z","iopub.execute_input":"2023-10-13T09:57:05.812367Z","iopub.status.idle":"2023-10-13T09:57:05.825021Z","shell.execute_reply.started":"2023-10-13T09:57:05.812336Z","shell.execute_reply":"2023-10-13T09:57:05.824043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val = train_images[train_indices], train_images[val_indices]\ny_train, y_val = labels[train_indices], labels[val_indices]","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:57:05.826296Z","iopub.execute_input":"2023-10-13T09:57:05.826618Z","iopub.status.idle":"2023-10-13T09:57:05.985436Z","shell.execute_reply.started":"2023-10-13T09:57:05.826591Z","shell.execute_reply":"2023-10-13T09:57:05.984379Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential([\n    ---------------------\n    ---------------------\n    ---------------------\n    ---------------------\n    ---------------------\n    ---------------------\n])\n","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:57:05.986844Z","iopub.execute_input":"2023-10-13T09:57:05.987821Z","iopub.status.idle":"2023-10-13T09:57:10.645953Z","shell.execute_reply.started":"2023-10-13T09:57:05.987788Z","shell.execute_reply":"2023-10-13T09:57:10.645043Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#complie the model here ","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:57:10.647182Z","iopub.execute_input":"2023-10-13T09:57:10.647513Z","iopub.status.idle":"2023-10-13T09:57:10.665168Z","shell.execute_reply.started":"2023-10-13T09:57:10.647484Z","shell.execute_reply":"2023-10-13T09:57:10.664369Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print the model summary here \n","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:57:10.666461Z","iopub.execute_input":"2023-10-13T09:57:10.666968Z","iopub.status.idle":"2023-10-13T09:57:10.692708Z","shell.execute_reply.started":"2023-10-13T09:57:10.66694Z","shell.execute_reply":"2023-10-13T09:57:10.692067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"batch_size = 32\nepochs = --\n\nhistory = model.fit(X_train, y_train, batch_size=batch_size, epochs=epochs, validation_data=(X_val, y_val))","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:57:10.693477Z","iopub.execute_input":"2023-10-13T09:57:10.693749Z","iopub.status.idle":"2023-10-13T09:57:53.46153Z","shell.execute_reply.started":"2023-10-13T09:57:10.693712Z","shell.execute_reply":"2023-10-13T09:57:53.460464Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#test the prediction and print it ","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:58:31.787563Z","iopub.execute_input":"2023-10-13T09:58:31.787901Z","iopub.status.idle":"2023-10-13T09:58:35.518499Z","shell.execute_reply.started":"2023-10-13T09:58:31.787873Z","shell.execute_reply":"2023-10-13T09:58:35.517377Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print(np.argmax(test_predictions[0]))","metadata":{"execution":{"iopub.status.busy":"2023-10-13T09:59:28.408408Z","iopub.execute_input":"2023-10-13T09:59:28.408747Z","iopub.status.idle":"2023-10-13T09:59:28.415269Z","shell.execute_reply.started":"2023-10-13T09:59:28.408718Z","shell.execute_reply":"2023-10-13T09:59:28.413823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predicted_breeds = [list(label_mapping.keys())[list(label_mapping.values()).index(np.argmax(prediction))] for prediction in test_predictions]\n\n# Create a DataFrame with image IDs and predicted breed labels\n----------------------------------------------------------------------\n\n# Save the submission file as a CSV\n----------------------------------------------------------------------","metadata":{"execution":{"iopub.status.busy":"2023-10-13T10:05:32.800553Z","iopub.execute_input":"2023-10-13T10:05:32.800889Z","iopub.status.idle":"2023-10-13T10:05:32.925827Z","shell.execute_reply.started":"2023-10-13T10:05:32.800862Z","shell.execute_reply":"2023-10-13T10:05:32.924865Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#read the csv ","metadata":{"execution":{"iopub.status.busy":"2023-10-13T10:06:35.655894Z","iopub.execute_input":"2023-10-13T10:06:35.656279Z","iopub.status.idle":"2023-10-13T10:06:35.672809Z","shell.execute_reply.started":"2023-10-13T10:06:35.65625Z","shell.execute_reply":"2023-10-13T10:06:35.671887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#print sub(head())\n\n","metadata":{"execution":{"iopub.status.busy":"2023-10-13T10:07:05.819938Z","iopub.execute_input":"2023-10-13T10:07:05.820285Z","iopub.status.idle":"2023-10-13T10:07:05.826892Z","shell.execute_reply.started":"2023-10-13T10:07:05.820255Z","shell.execute_reply":"2023-10-13T10:07:05.825831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}