{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":7327,"databundleVersionId":861871,"sourceType":"competition"}],"dockerImageVersionId":30699,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install tensorflow\nimport tensorflow as tf\nimport timeit\n\ndevice_name = tf.test.gpu_device_name()\nif device_name != '/device:GPU:0':\n  print(\n      '\\n\\nThis error most likely means that this notebook is not '\n      'configured to use a GPU.  Change this in Notebook Settings via the '\n      'command palette (cmd/ctrl-shift-P) or the Edit menu.\\n\\n')\n  raise SystemError('GPU device not found')\n\ndef cpu():\n  with tf.device('/cpu:0'):\n    random_image_cpu = tf.random.normal((100, 100, 100, 3))\n    net_cpu = tf.keras.layers.Conv2D(32, 7)(random_image_cpu)\n    return tf.math.reduce_sum(net_cpu)\n\ndef gpu():\n  with tf.device('/device:GPU:0'):\n    random_image_gpu = tf.random.normal((100, 100, 100, 3))\n    net_gpu = tf.keras.layers.Conv2D(32, 7)(random_image_gpu)\n    return tf.math.reduce_sum(net_gpu)\n  \n# We run each op once to warm up; see: https://stackoverflow.com/a/45067900\ncpu()\ngpu()\n\n# Run the op several times.\nprint('Time (s) to convolve 32x7x7x3 filter over random 100x100x100x3 images '\n      '(batch x height x width x channel). Sum of ten runs.')\nprint('CPU (s):')\ncpu_time = timeit.timeit('cpu()', number=10, setup=\"from __main__ import cpu\")\nprint(cpu_time)\nprint('GPU (s):')\ngpu_time = timeit.timeit('gpu()', number=10, setup=\"from __main__ import gpu\")\nprint(gpu_time)\nprint('GPU speedup over CPU: {}x'.format(int(cpu_time/gpu_time)))","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:46:30.885572Z","iopub.execute_input":"2024-12-30T05:46:30.886186Z","iopub.status.idle":"2024-12-30T05:47:01.124235Z","shell.execute_reply.started":"2024-12-30T05:46:30.886146Z","shell.execute_reply":"2024-12-30T05:47:01.123236Z"},"scrolled":true,"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tensorflow as tf\nimport tensorflow_hub as hub\ntf.__version__, hub.__version__","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:01.125878Z","iopub.execute_input":"2024-12-30T05:47:01.126149Z","iopub.status.idle":"2024-12-30T05:47:01.414398Z","shell.execute_reply.started":"2024-12-30T05:47:01.126126Z","shell.execute_reply":"2024-12-30T05:47:01.413577Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tf.config.list_physical_devices('GPU')","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:01.415163Z","iopub.execute_input":"2024-12-30T05:47:01.415422Z","iopub.status.idle":"2024-12-30T05:47:01.420456Z","shell.execute_reply.started":"2024-12-30T05:47:01.415403Z","shell.execute_reply":"2024-12-30T05:47:01.419642Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nlabels=pd.read_csv('/kaggle/input/dog-breed-identification/labels.csv')","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:01.422647Z","iopub.execute_input":"2024-12-30T05:47:01.423229Z","iopub.status.idle":"2024-12-30T05:47:01.450699Z","shell.execute_reply.started":"2024-12-30T05:47:01.423184Z","shell.execute_reply":"2024-12-30T05:47:01.450043Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labels.head()","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:01.451528Z","iopub.execute_input":"2024-12-30T05:47:01.451792Z","iopub.status.idle":"2024-12-30T05:47:01.468104Z","shell.execute_reply.started":"2024-12-30T05:47:01.451771Z","shell.execute_reply":"2024-12-30T05:47:01.467248Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labels.info()","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:01.469110Z","iopub.execute_input":"2024-12-30T05:47:01.469442Z","iopub.status.idle":"2024-12-30T05:47:01.491779Z","shell.execute_reply.started":"2024-12-30T05:47:01.469414Z","shell.execute_reply":"2024-12-30T05:47:01.490987Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labels.describe()","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:01.492781Z","iopub.execute_input":"2024-12-30T05:47:01.493021Z","iopub.status.idle":"2024-12-30T05:47:01.518087Z","shell.execute_reply.started":"2024-12-30T05:47:01.493002Z","shell.execute_reply":"2024-12-30T05:47:01.517246Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labels['breed'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:01.519286Z","iopub.execute_input":"2024-12-30T05:47:01.519612Z","iopub.status.idle":"2024-12-30T05:47:01.527660Z","shell.execute_reply.started":"2024-12-30T05:47:01.519584Z","shell.execute_reply":"2024-12-30T05:47:01.526902Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labels['breed'].value_counts().plot(figsize=(25,6),kind='bar');","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:01.528579Z","iopub.execute_input":"2024-12-30T05:47:01.528802Z","iopub.status.idle":"2024-12-30T05:47:02.885364Z","shell.execute_reply.started":"2024-12-30T05:47:01.528784Z","shell.execute_reply":"2024-12-30T05:47:02.884484Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labels['breed'].value_counts().mean(),labels['breed'].value_counts().median()","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:02.887916Z","iopub.execute_input":"2024-12-30T05:47:02.888178Z","iopub.status.idle":"2024-12-30T05:47:02.898651Z","shell.execute_reply.started":"2024-12-30T05:47:02.888156Z","shell.execute_reply":"2024-12-30T05:47:02.897752Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from IPython.display import Image\nImage('/kaggle/input/dog-breed-identification/train/000bec180eb18c7604dcecc8fe0dba07.jpg')","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:02.899696Z","iopub.execute_input":"2024-12-30T05:47:02.899917Z","iopub.status.idle":"2024-12-30T05:47:02.917142Z","shell.execute_reply.started":"2024-12-30T05:47:02.899899Z","shell.execute_reply":"2024-12-30T05:47:02.916369Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nos.listdir('/kaggle/input/dog-breed-identification/train')[:10]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:02.918069Z","iopub.execute_input":"2024-12-30T05:47:02.918329Z","iopub.status.idle":"2024-12-30T05:47:03.138359Z","shell.execute_reply.started":"2024-12-30T05:47:02.918310Z","shell.execute_reply":"2024-12-30T05:47:03.137495Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"files=['/kaggle/input/dog-breed-identification/train/'+fname+'.jpg' for fname in labels['id']]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.139409Z","iopub.execute_input":"2024-12-30T05:47:03.139645Z","iopub.status.idle":"2024-12-30T05:47:03.145893Z","shell.execute_reply.started":"2024-12-30T05:47:03.139626Z","shell.execute_reply":"2024-12-30T05:47:03.144866Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"files[:10]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.147040Z","iopub.execute_input":"2024-12-30T05:47:03.147369Z","iopub.status.idle":"2024-12-30T05:47:03.159319Z","shell.execute_reply.started":"2024-12-30T05:47:03.147342Z","shell.execute_reply":"2024-12-30T05:47:03.158437Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if len(files)==len(os.listdir('/kaggle/input/dog-breed-identification/train')):\n    print('Ye')\nelse:\n    print('Nay')","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.160159Z","iopub.execute_input":"2024-12-30T05:47:03.160456Z","iopub.status.idle":"2024-12-30T05:47:03.173043Z","shell.execute_reply.started":"2024-12-30T05:47:03.160426Z","shell.execute_reply":"2024-12-30T05:47:03.172251Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Image(files[9000])","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.174069Z","iopub.execute_input":"2024-12-30T05:47:03.174324Z","iopub.status.idle":"2024-12-30T05:47:03.188549Z","shell.execute_reply.started":"2024-12-30T05:47:03.174305Z","shell.execute_reply":"2024-12-30T05:47:03.187647Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"labels.iloc[9000]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.189532Z","iopub.execute_input":"2024-12-30T05:47:03.189802Z","iopub.status.idle":"2024-12-30T05:47:03.196034Z","shell.execute_reply.started":"2024-12-30T05:47:03.189784Z","shell.execute_reply":"2024-12-30T05:47:03.195158Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import numpy as np\nbreeds=labels['breed'].to_numpy()\n# np.array(breeds)  does the same thing\nbreeds","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.196934Z","iopub.execute_input":"2024-12-30T05:47:03.197124Z","iopub.status.idle":"2024-12-30T05:47:03.207854Z","shell.execute_reply.started":"2024-12-30T05:47:03.197108Z","shell.execute_reply":"2024-12-30T05:47:03.207034Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"if len(breeds)==len(files):\n    print('Ye')\nelse:\n    print('Nay')","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.208705Z","iopub.execute_input":"2024-12-30T05:47:03.208922Z","iopub.status.idle":"2024-12-30T05:47:03.220974Z","shell.execute_reply.started":"2024-12-30T05:47:03.208905Z","shell.execute_reply":"2024-12-30T05:47:03.220144Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"unique_breeds=np.unique(breeds)\nlen(unique_breeds)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.221752Z","iopub.execute_input":"2024-12-30T05:47:03.221959Z","iopub.status.idle":"2024-12-30T05:47:03.237029Z","shell.execute_reply.started":"2024-12-30T05:47:03.221942Z","shell.execute_reply":"2024-12-30T05:47:03.236251Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"unique_breeds","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.238542Z","iopub.execute_input":"2024-12-30T05:47:03.238902Z","iopub.status.idle":"2024-12-30T05:47:03.248000Z","shell.execute_reply.started":"2024-12-30T05:47:03.238878Z","shell.execute_reply":"2024-12-30T05:47:03.247302Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"breeds[1],breeds[1]==unique_breeds\n# breeds[1]==unique_breeds","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.248805Z","iopub.execute_input":"2024-12-30T05:47:03.249024Z","iopub.status.idle":"2024-12-30T05:47:03.258367Z","shell.execute_reply.started":"2024-12-30T05:47:03.249006Z","shell.execute_reply":"2024-12-30T05:47:03.257650Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"boolean_labels=[breed==unique_breeds for breed in breeds]\nboolean_labels","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-12-30T05:47:03.259137Z","iopub.execute_input":"2024-12-30T05:47:03.259358Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(boolean_labels)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(breeds[2]) #prints the name of breed from the breed column in the dataframe\nprint(np.where(breeds[2]==unique_breeds)) #returns intex where True is returned when compared to unique_breeds\nprint(boolean_labels[2].argmax()) #Highest value in a boolean_label is 1 (True). Returns index of that index\nboolean_labels[2].astype(int)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(files)","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X=files\ny=boolean_labels","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Image(files[13])","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from matplotlib.pyplot import imread\nimage=imread(files[13])\nimage","metadata":{"execution":{"iopub.status.idle":"2024-12-30T05:47:03.592097Z","shell.execute_reply.started":"2024-12-30T05:47:03.581323Z","shell.execute_reply":"2024-12-30T05:47:03.591430Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image.shape","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.593028Z","iopub.execute_input":"2024-12-30T05:47:03.593421Z","iopub.status.idle":"2024-12-30T05:47:03.603713Z","shell.execute_reply.started":"2024-12-30T05:47:03.593390Z","shell.execute_reply":"2024-12-30T05:47:03.602963Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image[:2]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.604782Z","iopub.execute_input":"2024-12-30T05:47:03.605577Z","iopub.status.idle":"2024-12-30T05:47:03.615310Z","shell.execute_reply.started":"2024-12-30T05:47:03.605544Z","shell.execute_reply":"2024-12-30T05:47:03.614590Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tf.constant(image)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.616179Z","iopub.execute_input":"2024-12-30T05:47:03.616499Z","iopub.status.idle":"2024-12-30T05:47:03.629009Z","shell.execute_reply.started":"2024-12-30T05:47:03.616469Z","shell.execute_reply":"2024-12-30T05:47:03.628352Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Image(files[0])","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.629890Z","iopub.execute_input":"2024-12-30T05:47:03.630080Z","iopub.status.idle":"2024-12-30T05:47:03.639704Z","shell.execute_reply.started":"2024-12-30T05:47:03.630064Z","shell.execute_reply":"2024-12-30T05:47:03.638975Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"NUM_IMAGES=1000 #@param {type='slider',min=1000,max=10000,step=1000} this works in colab","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.640794Z","iopub.execute_input":"2024-12-30T05:47:03.641056Z","iopub.status.idle":"2024-12-30T05:47:03.646074Z","shell.execute_reply.started":"2024-12-30T05:47:03.641037Z","shell.execute_reply":"2024-12-30T05:47:03.645428Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nX_train,X_val,y_train,y_val=train_test_split(X[:NUM_IMAGES],y[:NUM_IMAGES],train_size=0.8)\n\nlen(X_train),len(X_val),len(y_train),len(y_val)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:03.647109Z","iopub.execute_input":"2024-12-30T05:47:03.647382Z","iopub.status.idle":"2024-12-30T05:47:04.051219Z","shell.execute_reply.started":"2024-12-30T05:47:03.647341Z","shell.execute_reply":"2024-12-30T05:47:04.050353Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train[:10],y_train[:10]","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-12-30T05:47:04.052310Z","iopub.execute_input":"2024-12-30T05:47:04.052580Z","iopub.status.idle":"2024-12-30T05:47:04.060273Z","shell.execute_reply.started":"2024-12-30T05:47:04.052560Z","shell.execute_reply":"2024-12-30T05:47:04.059409Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#    PREPROCESSING THE IMAGE\n# 1. Take image path as input\n# 2. Use tf to read image into variable \n# 3. Turn that jpg into tensors\n# 4. Normalise color values from 0-255 to 0-1\n# 5. Resize to (224,224)\n# 6. Return Modified Image","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:04.061217Z","iopub.execute_input":"2024-12-30T05:47:04.061473Z","iopub.status.idle":"2024-12-30T05:47:04.069815Z","shell.execute_reply.started":"2024-12-30T05:47:04.061454Z","shell.execute_reply":"2024-12-30T05:47:04.069154Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"IMG_SIZE=224\n\ndef process_image(image_path):\n    image=tf.io.read_file(image_path) #reading image into some tensor string bullshit\n    image=tf.image.decode_jpeg(image,channels=3) #decoding image to tensor matrix w 3 colour channels (R,G,B)\n    image=tf.image.convert_image_dtype(image, tf.float32) #normalising 0-255 to 0-1\n    image=tf.image.resize(image,size=[IMG_SIZE,IMG_SIZE])\n    \n    \n    return image \n    ","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:04.070757Z","iopub.execute_input":"2024-12-30T05:47:04.070986Z","iopub.status.idle":"2024-12-30T05:47:04.081142Z","shell.execute_reply.started":"2024-12-30T05:47:04.070968Z","shell.execute_reply":"2024-12-30T05:47:04.080431Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"image_path=files[0]\nimage=tf.io.read_file(image_path) #reading image\nimage","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-12-30T05:47:04.081946Z","iopub.execute_input":"2024-12-30T05:47:04.082135Z","iopub.status.idle":"2024-12-30T05:47:04.104960Z","shell.execute_reply.started":"2024-12-30T05:47:04.082120Z","shell.execute_reply":"2024-12-30T05:47:04.104076Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tf.image.decode_jpeg(tf.io.read_file(files[3]),channels=3)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:04.105921Z","iopub.execute_input":"2024-12-30T05:47:04.106138Z","iopub.status.idle":"2024-12-30T05:47:04.122143Z","shell.execute_reply.started":"2024-12-30T05:47:04.106121Z","shell.execute_reply":"2024-12-30T05:47:04.121534Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tf.io.read_file(files[0])","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-12-30T05:47:04.123008Z","iopub.execute_input":"2024-12-30T05:47:04.123284Z","iopub.status.idle":"2024-12-30T05:47:04.131943Z","shell.execute_reply.started":"2024-12-30T05:47:04.123264Z","shell.execute_reply":"2024-12-30T05:47:04.131255Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"tf.image.convert_image_dtype(tf.image.decode_jpeg(tf.io.read_file(files[3]),channels=3),tf.float32)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:04.132973Z","iopub.execute_input":"2024-12-30T05:47:04.133703Z","iopub.status.idle":"2024-12-30T05:47:04.153971Z","shell.execute_reply.started":"2024-12-30T05:47:04.133675Z","shell.execute_reply":"2024-12-30T05:47:04.153126Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# GETTING TUPLE OF (IMAGE,LABEL)\n\ndef get_label(path,label):\n    return process_image(path),label","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:04.154875Z","iopub.execute_input":"2024-12-30T05:47:04.155117Z","iopub.status.idle":"2024-12-30T05:47:04.158763Z","shell.execute_reply.started":"2024-12-30T05:47:04.155098Z","shell.execute_reply":"2024-12-30T05:47:04.157982Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"(process_image(X[13]),tf.constant(y[13]))","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-12-30T05:47:04.159630Z","iopub.execute_input":"2024-12-30T05:47:04.159839Z","iopub.status.idle":"2024-12-30T05:47:04.181765Z","shell.execute_reply.started":"2024-12-30T05:47:04.159822Z","shell.execute_reply":"2024-12-30T05:47:04.180979Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"BATCH_SIZE=32\n\ndef create_batch(X,y=None,batch_size=BATCH_SIZE,valid_data=False,test_data=False):\n    #Shuffles training data\n    if test_data:\n        print(\"Creating test batches...\")\n        #Receives tensors and creates a dataset out of it.... only filepaths\n        data=tf.data.Dataset.from_tensor_slices((tf.constant(X)))\n        data_batch=data.map(process_image).batch(BATCH_SIZE)\n        return data_batch\n    \n    elif valid_data:\n        print('Creating validation batches...')\n        #Receives tensors of path and label, and returns batches \n        data=tf.data.Dataset.from_tensor_slices((tf.constant(X),tf.constant(y)))\n        # get_label preprocesses the image and returns (image,label) tuple\n        data_batch=data.map(get_label).batch(BATCH_SIZE)\n        return data_batch\n    \n    else:\n        print(\"Creating train batches\")\n        data=tf.data.Dataset.from_tensor_slices((tf.constant(X),tf.constant(y)))\n        data=data.shuffle(len(X))\n        data_batch=data.map(get_label).batch(BATCH_SIZE)\n        return data_batch\n        \n        \n        \n        \n        ","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:04.182751Z","iopub.execute_input":"2024-12-30T05:47:04.183032Z","iopub.status.idle":"2024-12-30T05:47:04.188890Z","shell.execute_reply.started":"2024-12-30T05:47:04.183006Z","shell.execute_reply":"2024-12-30T05:47:04.188048Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"data=tf.data.Dataset.from_tensor_slices((tf.constant(X),tf.constant(y)))\nlist(data)","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-12-30T05:47:04.189684Z","iopub.execute_input":"2024-12-30T05:47:04.189916Z","iopub.status.idle":"2024-12-30T05:47:06.506368Z","shell.execute_reply.started":"2024-12-30T05:47:04.189898Z","shell.execute_reply":"2024-12-30T05:47:06.505506Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data=create_batch(X_train,y_train)\nval_data=create_batch(X_val,y_val,valid_data=True)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:06.507608Z","iopub.execute_input":"2024-12-30T05:47:06.507926Z","iopub.status.idle":"2024-12-30T05:47:06.617322Z","shell.execute_reply.started":"2024-12-30T05:47:06.507901Z","shell.execute_reply":"2024-12-30T05:47:06.616489Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_data.element_spec, val_data.element_spec","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:06.618557Z","iopub.execute_input":"2024-12-30T05:47:06.619130Z","iopub.status.idle":"2024-12-30T05:47:06.624520Z","shell.execute_reply.started":"2024-12-30T05:47:06.619098Z","shell.execute_reply":"2024-12-30T05:47:06.623634Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import matplotlib.pyplot as plt\n\ndef show25img(images,labels):\n    plt.figure(figsize=(10,10))\n    \n    for i in range (25):\n        ax=plt.subplot(5,5,i+1) #(rows,columns,index)\n        plt.imshow(images[i])\n        plt.title(unique_breeds[labels[i].argmax()])\n        plt.axis(\"off\")","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:06.625452Z","iopub.execute_input":"2024-12-30T05:47:06.625686Z","iopub.status.idle":"2024-12-30T05:47:06.636022Z","shell.execute_reply.started":"2024-12-30T05:47:06.625667Z","shell.execute_reply":"2024-12-30T05:47:06.635332Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_img,train_label=next(train_data.as_numpy_iterator())\n# train_img\nshow25img(train_img,train_label) #shuffles everytime I run this... why?","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:06.636920Z","iopub.execute_input":"2024-12-30T05:47:06.637115Z","iopub.status.idle":"2024-12-30T05:47:08.660701Z","shell.execute_reply.started":"2024-12-30T05:47:06.637098Z","shell.execute_reply":"2024-12-30T05:47:08.659859Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_img,val_label=next(val_data.as_numpy_iterator())\nshow25img(val_img,val_label)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:08.661819Z","iopub.execute_input":"2024-12-30T05:47:08.662116Z","iopub.status.idle":"2024-12-30T05:47:10.566265Z","shell.execute_reply.started":"2024-12-30T05:47:08.662091Z","shell.execute_reply":"2024-12-30T05:47:10.565234Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"IMG_SIZE","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:10.567312Z","iopub.execute_input":"2024-12-30T05:47:10.567571Z","iopub.status.idle":"2024-12-30T05:47:10.572773Z","shell.execute_reply.started":"2024-12-30T05:47:10.567550Z","shell.execute_reply":"2024-12-30T05:47:10.571884Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"INPUT_SHAPE=[0,IMG_SIZE,IMG_SIZE,3]\nOUTPUT_SHAPE=len(unique_breeds)\nMODEL_URL=\"https://tfhub.dev/google/imagenet/mobilenet_v2_130_224/classification/4\"","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:10.573768Z","iopub.execute_input":"2024-12-30T05:47:10.574017Z","iopub.status.idle":"2024-12-30T05:47:10.583126Z","shell.execute_reply.started":"2024-12-30T05:47:10.573992Z","shell.execute_reply":"2024-12-30T05:47:10.582439Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def create_model(input_shape=INPUT_SHAPE,output_shape=OUTPUT_SHAPE,model=MODEL_URL):\n    print(\"Building model with \",MODEL_URL)\n    \n    # Set up model layers\n    model = tf.keras.Sequential([hub.KerasLayer(MODEL_URL), # Layer 1 (input layer)\n                                 tf.keras.layers.Dense(units=OUTPUT_SHAPE,activation=\"softmax\") # Layer 2 (output layer)\n                                 ])\n    #Compile the model\n    model.compile(loss=tf.keras.losses.CategoricalCrossentropy(),\n                  optimizer=tf.keras.optimizers.Adam(),\n                  metrics=[\"accuracy\"])\n    \n    #Build the model\n    model.build(INPUT_SHAPE)\n    \n    return model","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:10.584099Z","iopub.execute_input":"2024-12-30T05:47:10.584424Z","iopub.status.idle":"2024-12-30T05:47:10.594577Z","shell.execute_reply.started":"2024-12-30T05:47:10.584384Z","shell.execute_reply":"2024-12-30T05:47:10.593674Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model=create_model()\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:10.595996Z","iopub.execute_input":"2024-12-30T05:47:10.596314Z","iopub.status.idle":"2024-12-30T05:47:13.184168Z","shell.execute_reply.started":"2024-12-30T05:47:10.596287Z","shell.execute_reply":"2024-12-30T05:47:13.183388Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"os.makedirs(\"/kaggle/working/logs\")","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:13.185139Z","iopub.execute_input":"2024-12-30T05:47:13.185396Z","iopub.status.idle":"2024-12-30T05:47:13.189362Z","shell.execute_reply.started":"2024-12-30T05:47:13.185376Z","shell.execute_reply":"2024-12-30T05:47:13.188263Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:13.190614Z","iopub.execute_input":"2024-12-30T05:47:13.190928Z","iopub.status.idle":"2024-12-30T05:47:14.290154Z","shell.execute_reply.started":"2024-12-30T05:47:13.190900Z","shell.execute_reply":"2024-12-30T05:47:14.289069Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%load_ext tensorboard\nimport datetime\n\ndef tensorboard_callback():\n    logdir = os.path.join(\"drive/My Drive/Data/logs\",\n                            # Make it so the logs get tracked whenever we run an experiment\n                            datetime.datetime.now().strftime(\"%Y%m%d-%H%M%S\"))    \n    return tf.keras.callbacks.TensorBoard(logdir)\n","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:14.291832Z","iopub.execute_input":"2024-12-30T05:47:14.292598Z","iopub.status.idle":"2024-12-30T05:47:14.311735Z","shell.execute_reply.started":"2024-12-30T05:47:14.292561Z","shell.execute_reply":"2024-12-30T05:47:14.311080Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"early_stop=tf.keras.callbacks.EarlyStopping(monitor=\"val_accuracy\",patience=3)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:14.312735Z","iopub.execute_input":"2024-12-30T05:47:14.312964Z","iopub.status.idle":"2024-12-30T05:47:14.346178Z","shell.execute_reply.started":"2024-12-30T05:47:14.312947Z","shell.execute_reply":"2024-12-30T05:47:14.345547Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Ye\" if tf.config.list_physical_devices(\"GPU\") else \"Nay\")","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:14.347175Z","iopub.execute_input":"2024-12-30T05:47:14.347829Z","iopub.status.idle":"2024-12-30T05:47:14.361033Z","shell.execute_reply.started":"2024-12-30T05:47:14.347809Z","shell.execute_reply":"2024-12-30T05:47:14.360391Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"NUM_EPOCHS=100\ndef train_model():\n    model=create_model()\n    tb=tensorboard_callback()\n    \n    model.fit(x=train_data,epochs=NUM_EPOCHS,validation_data=val_data,validation_freq=1,callbacks=[tb,early_stop])\n    \n    return model","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:14.361889Z","iopub.execute_input":"2024-12-30T05:47:14.362077Z","iopub.status.idle":"2024-12-30T05:47:14.372953Z","shell.execute_reply.started":"2024-12-30T05:47:14.362060Z","shell.execute_reply":"2024-12-30T05:47:14.372232Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model=train_model()","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:14.374042Z","iopub.execute_input":"2024-12-30T05:47:14.374695Z","iopub.status.idle":"2024-12-30T05:47:37.309168Z","shell.execute_reply.started":"2024-12-30T05:47:14.374662Z","shell.execute_reply":"2024-12-30T05:47:37.308505Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# %tensorboard --logdir /kaggle/working/logs         ##Does not work on kaggle","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:37.310361Z","iopub.execute_input":"2024-12-30T05:47:37.310718Z","iopub.status.idle":"2024-12-30T05:47:37.315143Z","shell.execute_reply.started":"2024-12-30T05:47:37.310687Z","shell.execute_reply":"2024-12-30T05:47:37.314235Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions = model.predict(val_data,verbose=1)\npredictions","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:37.316217Z","iopub.execute_input":"2024-12-30T05:47:37.316457Z","iopub.status.idle":"2024-12-30T05:47:38.091421Z","shell.execute_reply.started":"2024-12-30T05:47:37.316438Z","shell.execute_reply":"2024-12-30T05:47:38.090558Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"predictions.shape","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:38.092453Z","iopub.execute_input":"2024-12-30T05:47:38.092729Z","iopub.status.idle":"2024-12-30T05:47:38.097829Z","shell.execute_reply.started":"2024-12-30T05:47:38.092708Z","shell.execute_reply":"2024-12-30T05:47:38.097020Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"idx=0\nprint(predictions[idx])\nprint(f\"Max value is: {np.max(predictions[idx])}\")\nprint(f\"index of max value is: {np.argmax(predictions[idx])}\")\nprint(f\"predicted breed is {unique_breeds[np.argmax(predictions[idx])]}\")\n# print(f\"actual breed is {})","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:38.098920Z","iopub.execute_input":"2024-12-30T05:47:38.099735Z","iopub.status.idle":"2024-12-30T05:47:38.110691Z","shell.execute_reply.started":"2024-12-30T05:47:38.099712Z","shell.execute_reply":"2024-12-30T05:47:38.109694Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def get_y_val(index):\n    return unique_breeds[np.argmax(predictions[index])]","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-12-30T05:47:38.111633Z","iopub.execute_input":"2024-12-30T05:47:38.111858Z","iopub.status.idle":"2024-12-30T05:47:38.121389Z","shell.execute_reply.started":"2024-12-30T05:47:38.111838Z","shell.execute_reply":"2024-12-30T05:47:38.120513Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"get_y_val(0)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:38.122492Z","iopub.execute_input":"2024-12-30T05:47:38.123010Z","iopub.status.idle":"2024-12-30T05:47:38.132398Z","shell.execute_reply.started":"2024-12-30T05:47:38.122989Z","shell.execute_reply":"2024-12-30T05:47:38.131565Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def unbatchify(data):\n    images=[]\n    labels=[]\n    \n    for image,label in data.unbatch().as_numpy_iterator():\n        images.append(image)\n        labels.append(label)\n    return images,labels\n    ","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:38.133303Z","iopub.execute_input":"2024-12-30T05:47:38.133603Z","iopub.status.idle":"2024-12-30T05:47:38.142184Z","shell.execute_reply.started":"2024-12-30T05:47:38.133584Z","shell.execute_reply":"2024-12-30T05:47:38.141342Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_img,val_label=unbatchify(val_data)\nval_label","metadata":{"scrolled":true,"execution":{"iopub.status.busy":"2024-12-30T05:47:38.143281Z","iopub.execute_input":"2024-12-30T05:47:38.143789Z","iopub.status.idle":"2024-12-30T05:47:38.424663Z","shell.execute_reply.started":"2024-12-30T05:47:38.143761Z","shell.execute_reply":"2024-12-30T05:47:38.423767Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def plot_pred(index):\n    y_val=get_y_val(index)\n    y_actual=unique_breeds[np.argmax(val_label[index])]\n    img=val_img[index]\n    y_prob=np.max(predictions[index])\n    \n    plt.imshow(img)\n    plt.axis(\"off\")\n    \n    if y_val==y_actual:\n        color=\"green\"\n    else:\n        color=\"red\"\n            \n    plt.title(f\"{y_val} {(y_prob*100):.2f}% ({y_actual})\",color=color)\n    ","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:38.425835Z","iopub.execute_input":"2024-12-30T05:47:38.426093Z","iopub.status.idle":"2024-12-30T05:47:38.431210Z","shell.execute_reply.started":"2024-12-30T05:47:38.426073Z","shell.execute_reply":"2024-12-30T05:47:38.430258Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plot_pred(13)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:38.432179Z","iopub.execute_input":"2024-12-30T05:47:38.432503Z","iopub.status.idle":"2024-12-30T05:47:38.723990Z","shell.execute_reply.started":"2024-12-30T05:47:38.432470Z","shell.execute_reply":"2024-12-30T05:47:38.723139Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"get_y_val(1)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:38.725218Z","iopub.execute_input":"2024-12-30T05:47:38.725553Z","iopub.status.idle":"2024-12-30T05:47:38.731104Z","shell.execute_reply.started":"2024-12-30T05:47:38.725522Z","shell.execute_reply":"2024-12-30T05:47:38.730404Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_label[1]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:38.732080Z","iopub.execute_input":"2024-12-30T05:47:38.732313Z","iopub.status.idle":"2024-12-30T05:47:38.745020Z","shell.execute_reply.started":"2024-12-30T05:47:38.732294Z","shell.execute_reply":"2024-12-30T05:47:38.744126Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:38.746259Z","iopub.execute_input":"2024-12-30T05:47:38.746640Z","iopub.status.idle":"2024-12-30T05:47:39.824237Z","shell.execute_reply.started":"2024-12-30T05:47:38.746612Z","shell.execute_reply":"2024-12-30T05:47:39.823355Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def save_model(model,suffix=None):\n    modeldir=os.path.join(\"models\",datetime.datetime.now().strftime(\"%Y%m%d-%H%M%s\"))\n    \n    model_path=modeldir+\"-\"+suffix+\".h5\"\n    print(f\"saving to {model_path}\")\n    \n    model.save(model_path)\n    return model_path\n\ndef load_model(model_path):\n    print(f\"loading from {model_path}\")\n    \n    model=tf.keras.models.load_model(model_path,custom_objects={\"KerasLayer\":hub.KerasLayer})\n    \n    return model","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:39.825779Z","iopub.execute_input":"2024-12-30T05:47:39.826064Z","iopub.status.idle":"2024-12-30T05:47:39.831881Z","shell.execute_reply.started":"2024-12-30T05:47:39.826040Z","shell.execute_reply":"2024-12-30T05:47:39.830992Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# save_model(model,\"1000-mobilenetV2-Adam\")\nmodel.save(\"models/1000-mobilenetV2-Adam.h5\", overwrite=True)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:47:39.833076Z","iopub.execute_input":"2024-12-30T05:47:39.833386Z","iopub.status.idle":"2024-12-30T05:47:40.095964Z","shell.execute_reply.started":"2024-12-30T05:47:39.833359Z","shell.execute_reply":"2024-12-30T05:47:40.095250Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"yoyo=load_model(\"/kaggle/working/models/1000-mobilenetV2-Adam.h5\")","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:49:16.674751Z","iopub.execute_input":"2024-12-30T05:49:16.675626Z","iopub.status.idle":"2024-12-30T05:49:18.163440Z","shell.execute_reply.started":"2024-12-30T05:49:16.675596Z","shell.execute_reply":"2024-12-30T05:49:18.162745Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"yoyo.evaluate(val_data)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:49:20.975167Z","iopub.execute_input":"2024-12-30T05:49:20.975934Z","iopub.status.idle":"2024-12-30T05:49:21.904705Z","shell.execute_reply.started":"2024-12-30T05:49:20.975905Z","shell.execute_reply":"2024-12-30T05:49:21.903920Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(X)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:49:39.815854Z","iopub.execute_input":"2024-12-30T05:49:39.816432Z","iopub.status.idle":"2024-12-30T05:49:39.821980Z","shell.execute_reply.started":"2024-12-30T05:49:39.816401Z","shell.execute_reply":"2024-12-30T05:49:39.820978Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(y)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:49:40.950794Z","iopub.execute_input":"2024-12-30T05:49:40.951128Z","iopub.status.idle":"2024-12-30T05:49:40.956502Z","shell.execute_reply.started":"2024-12-30T05:49:40.951101Z","shell.execute_reply":"2024-12-30T05:49:40.955664Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"full_data=create_batch(X,y)\nfull_data\n","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:49:41.263632Z","iopub.execute_input":"2024-12-30T05:49:41.263912Z","iopub.status.idle":"2024-12-30T05:49:41.331380Z","shell.execute_reply.started":"2024-12-30T05:49:41.263891Z","shell.execute_reply":"2024-12-30T05:49:41.330537Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"full_model=create_model()","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:49:44.110409Z","iopub.execute_input":"2024-12-30T05:49:44.110780Z","iopub.status.idle":"2024-12-30T05:49:45.341941Z","shell.execute_reply.started":"2024-12-30T05:49:44.110756Z","shell.execute_reply":"2024-12-30T05:49:45.341253Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"full_model_tb=tensorboard_callback()\nfull_model_stop=tf.keras.callbacks.EarlyStopping(monitor=\"accuracy\",patience=5)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:49:50.292529Z","iopub.execute_input":"2024-12-30T05:49:50.292856Z","iopub.status.idle":"2024-12-30T05:49:50.297291Z","shell.execute_reply.started":"2024-12-30T05:49:50.292831Z","shell.execute_reply":"2024-12-30T05:49:50.296364Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"full_model.fit(x=full_data,epochs=NUM_EPOCHS,callbacks=[full_model_tb,full_model_stop])","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:49:52.293354Z","iopub.execute_input":"2024-12-30T05:49:52.294002Z","iopub.status.idle":"2024-12-30T05:55:22.524897Z","shell.execute_reply.started":"2024-12-30T05:49:52.293977Z","shell.execute_reply":"2024-12-30T05:55:22.524072Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# save_model(full_model,\"full_trained-mobilenetV2-Adam\")\nfull_model.save(\"models/full_trained_mobilenetV2-Adam.h5\", overwrite=True)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:55:32.262100Z","iopub.execute_input":"2024-12-30T05:55:32.262779Z","iopub.status.idle":"2024-12-30T05:55:32.458408Z","shell.execute_reply.started":"2024-12-30T05:55:32.262750Z","shell.execute_reply":"2024-12-30T05:55:32.457680Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_path=\"/kaggle/input/dog-breed-identification/test/\"\ntest_file=[test_path + fname for fname in os.listdir(test_path)]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:55:35.808517Z","iopub.execute_input":"2024-12-30T05:55:35.808840Z","iopub.status.idle":"2024-12-30T05:55:36.393209Z","shell.execute_reply.started":"2024-12-30T05:55:35.808814Z","shell.execute_reply":"2024-12-30T05:55:36.392240Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_file[:10]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:55:38.064020Z","iopub.execute_input":"2024-12-30T05:55:38.064372Z","iopub.status.idle":"2024-12-30T05:55:38.070405Z","shell.execute_reply.started":"2024-12-30T05:55:38.064343Z","shell.execute_reply":"2024-12-30T05:55:38.069478Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"len(test_file)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:55:39.159516Z","iopub.execute_input":"2024-12-30T05:55:39.160211Z","iopub.status.idle":"2024-12-30T05:55:39.165428Z","shell.execute_reply.started":"2024-12-30T05:55:39.160171Z","shell.execute_reply":"2024-12-30T05:55:39.164439Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data=create_batch(test_file,test_data=True)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:55:40.009157Z","iopub.execute_input":"2024-12-30T05:55:40.010102Z","iopub.status.idle":"2024-12-30T05:55:40.031302Z","shell.execute_reply.started":"2024-12-30T05:55:40.010075Z","shell.execute_reply":"2024-12-30T05:55:40.030464Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_data","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:55:42.200750Z","iopub.execute_input":"2024-12-30T05:55:42.201329Z","iopub.status.idle":"2024-12-30T05:55:42.206812Z","shell.execute_reply.started":"2024-12-30T05:55:42.201301Z","shell.execute_reply":"2024-12-30T05:55:42.205914Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_predictions=full_model.predict(test_data,verbose=1)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:55:44.874914Z","iopub.execute_input":"2024-12-30T05:55:44.875267Z","iopub.status.idle":"2024-12-30T05:56:11.050560Z","shell.execute_reply.started":"2024-12-30T05:55:44.875236Z","shell.execute_reply":"2024-12-30T05:56:11.049826Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_predictions[:10]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:56:13.233299Z","iopub.execute_input":"2024-12-30T05:56:13.233636Z","iopub.status.idle":"2024-12-30T05:56:13.240134Z","shell.execute_reply.started":"2024-12-30T05:56:13.233608Z","shell.execute_reply":"2024-12-30T05:56:13.239263Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_predictions.shape","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:56:14.632920Z","iopub.execute_input":"2024-12-30T05:56:14.633772Z","iopub.status.idle":"2024-12-30T05:56:14.639227Z","shell.execute_reply.started":"2024-12-30T05:56:14.633738Z","shell.execute_reply":"2024-12-30T05:56:14.638237Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\npreds_df=pd.DataFrame(columns=[\"id\"]+list(unique_breeds))\npreds_df","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:56:17.408848Z","iopub.execute_input":"2024-12-30T05:56:17.409520Z","iopub.status.idle":"2024-12-30T05:56:17.425804Z","shell.execute_reply.started":"2024-12-30T05:56:17.409493Z","shell.execute_reply":"2024-12-30T05:56:17.425045Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_ids=[fname[:-4] for fname in os.listdir(\"/kaggle/input/dog-breed-identification/test\")]\n# test_ids=[fname[:-4] for fname in test_ids]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:56:22.037039Z","iopub.execute_input":"2024-12-30T05:56:22.037727Z","iopub.status.idle":"2024-12-30T05:56:22.047628Z","shell.execute_reply.started":"2024-12-30T05:56:22.037698Z","shell.execute_reply":"2024-12-30T05:56:22.046729Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_ids[:10]","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:56:23.960095Z","iopub.execute_input":"2024-12-30T05:56:23.960455Z","iopub.status.idle":"2024-12-30T05:56:23.966123Z","shell.execute_reply.started":"2024-12-30T05:56:23.960428Z","shell.execute_reply":"2024-12-30T05:56:23.965257Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"preds_df[\"id\"]=test_ids\npreds_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:56:25.399523Z","iopub.execute_input":"2024-12-30T05:56:25.400348Z","iopub.status.idle":"2024-12-30T05:56:25.429579Z","shell.execute_reply.started":"2024-12-30T05:56:25.400318Z","shell.execute_reply":"2024-12-30T05:56:25.428832Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"preds_df[list(unique_breeds)]=test_predictions\npreds_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:56:27.223569Z","iopub.execute_input":"2024-12-30T05:56:27.224357Z","iopub.status.idle":"2024-12-30T05:56:27.269222Z","shell.execute_reply.started":"2024-12-30T05:56:27.224329Z","shell.execute_reply":"2024-12-30T05:56:27.268399Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"preds_df.to_csv(\"submission.csv\",index=False)","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:56:36.010468Z","iopub.execute_input":"2024-12-30T05:56:36.010795Z","iopub.status.idle":"2024-12-30T05:56:37.279170Z","shell.execute_reply.started":"2024-12-30T05:56:36.010769Z","shell.execute_reply":"2024-12-30T05:56:37.278501Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"preds_df.shape","metadata":{"execution":{"iopub.status.busy":"2024-12-30T05:56:41.393597Z","iopub.execute_input":"2024-12-30T05:56:41.394443Z","iopub.status.idle":"2024-12-30T05:56:41.399779Z","shell.execute_reply.started":"2024-12-30T05:56:41.394404Z","shell.execute_reply":"2024-12-30T05:56:41.398830Z"},"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}