{"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\n#for 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-11-09T06:30:55.021221Z","iopub.execute_input":"2023-11-09T06:30:55.021579Z","iopub.status.idle":"2023-11-09T06:30:55.378957Z","shell.execute_reply.started":"2023-11-09T06:30:55.021549Z","shell.execute_reply":"2023-11-09T06:30:55.378128Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nif 'tensorflow' in sys.modules:\n    del sys.modules['tensorflow']\n!pip install tensorflow==2.8.0 \nif 'tensorflow-io' in sys.modules:\n    del sys.modules['tensorflow-io']\n!pip install tensorflow-io==0.24.0","metadata":{"jupyter":{"source_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip list","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom PIL import Image\ndef image_to_tensor(file):\n    img = Image.open(file)\n    return tf.convert_to_tensor(img)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:30:55.38372Z","iopub.execute_input":"2023-11-09T06:30:55.384001Z","iopub.status.idle":"2023-11-09T06:30:58.745841Z","shell.execute_reply.started":"2023-11-09T06:30:55.383976Z","shell.execute_reply":"2023-11-09T06:30:58.744317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"gpus = tf.config.experimental.list_physical_devices('GPU')\nfor gpu in gpus:\n    tf.config.experimental.set_memory_growth(gpu, True)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:30:58.748993Z","iopub.execute_input":"2023-11-09T06:30:58.750359Z","iopub.status.idle":"2023-11-09T06:30:58.875831Z","shell.execute_reply.started":"2023-11-09T06:30:58.750306Z","shell.execute_reply":"2023-11-09T06:30:58.874746Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport imghdr\nfrom matplotlib import pyplot as plt","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:00.837227Z","iopub.execute_input":"2023-11-09T06:31:00.837884Z","iopub.status.idle":"2023-11-09T06:31:00.875548Z","shell.execute_reply.started":"2023-11-09T06:31:00.837849Z","shell.execute_reply":"2023-11-09T06:31:00.874834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = cv2.imread(\"/kaggle/input/anyas-gojo-revival-aerospace-enigma/train/glider/image100.jpg\")\nplt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:01.165201Z","iopub.execute_input":"2023-11-09T06:31:01.165545Z","iopub.status.idle":"2023-11-09T06:31:01.65812Z","shell.execute_reply.started":"2023-11-09T06:31:01.165517Z","shell.execute_reply":"2023-11-09T06:31:01.657087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_dir = '/kaggle/input/new-datas/anyas-gojo-revival-aerospace-enigma/train'\nimage_exts = ['jpeg' , 'bmp', 'png']","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:01.725977Z","iopub.execute_input":"2023-11-09T06:31:01.726283Z","iopub.status.idle":"2023-11-09T06:31:01.730853Z","shell.execute_reply.started":"2023-11-09T06:31:01.726256Z","shell.execute_reply":"2023-11-09T06:31:01.729903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for image_class in os.listdir(data_dir):\n    for image in os.listdir(os.path.join(data_dir, image_class)):\n        image_path = os.path.join(data_dir, image_class, image)\n        try:\n            img = cv2.imread(image_path)\n            tip = imghdr.what(image_path)\n            if tip not in image_exts:\n                #print('Image not in ext list{}',format(image_path))\n                #os.remove(image_path)\n                print(tip)\n                print(image_path)\n        except Exception as e:\n            #print('Issue with image {}'.format(image_path))\n            #os.remove(image_path)\n            print(\"Error opening the following path: \")\n            print(tip)\n            print(image_path)\n                ","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:02.162079Z","iopub.execute_input":"2023-11-09T06:31:02.162426Z","iopub.status.idle":"2023-11-09T06:31:15.365163Z","shell.execute_reply.started":"2023-11-09T06:31:02.162397Z","shell.execute_reply":"2023-11-09T06:31:15.364354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_dir = '/kaggle/input/test-datas/test'\nfor image in os.listdir(data_dir):\n    \n    image_path = os.path.join(data_dir, image)\n    try:\n        img = cv2.imread(image_path)\n        tip = imghdr.what(image_path)\n        if tip not in image_exts:\n                #print('Image not in ext list{}',format(image_path))\n                #os.remove(image_path)\n            print(tip)\n            print(image_path)\n    except Exception as e:\n            #print('Issue with image {}'.format(image_path))\n            #os.remove(image_path)\n        print(\"Error opening the following path: \")\n        print(tip)\n        print(image_path)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:15.366862Z","iopub.execute_input":"2023-11-09T06:31:15.367147Z","iopub.status.idle":"2023-11-09T06:31:17.143202Z","shell.execute_reply.started":"2023-11-09T06:31:15.367122Z","shell.execute_reply":"2023-11-09T06:31:17.142102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"d = '/kaggle/input/new-datas/anyas-gojo-revival-aerospace-enigma/train'\ndata = tf.keras.utils.image_dataset_from_directory(d)\nprint(data)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:17.144677Z","iopub.execute_input":"2023-11-09T06:31:17.145468Z","iopub.status.idle":"2023-11-09T06:31:19.616552Z","shell.execute_reply.started":"2023-11-09T06:31:17.145426Z","shell.execute_reply":"2023-11-09T06:31:19.615535Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_iterator = data.as_numpy_iterator()\nbatch = data_iterator.next()\nprint(batch[0].shape)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:19.618755Z","iopub.execute_input":"2023-11-09T06:31:19.619064Z","iopub.status.idle":"2023-11-09T06:31:20.55038Z","shell.execute_reply.started":"2023-11-09T06:31:19.619036Z","shell.execute_reply":"2023-11-09T06:31:20.549218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#This basically prints all the labels of each picture\nbatch[1]","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:20.551392Z","iopub.execute_input":"2023-11-09T06:31:20.552138Z","iopub.status.idle":"2023-11-09T06:31:20.559298Z","shell.execute_reply.started":"2023-11-09T06:31:20.552096Z","shell.execute_reply":"2023-11-09T06:31:20.558238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(ncols=10, figsize=(20,20))\nfor idx, img in enumerate(batch[0][:10]):\n    ax[idx].imshow(img.astype(int))\n    ax[idx].title.set_text(batch[1][idx])","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:20.560645Z","iopub.execute_input":"2023-11-09T06:31:20.561654Z","iopub.status.idle":"2023-11-09T06:31:22.351661Z","shell.execute_reply.started":"2023-11-09T06:31:20.561615Z","shell.execute_reply":"2023-11-09T06:31:22.350762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"* Commercial = 0\n* Glider = 1\n* Helicopter = 2\n* MIG-29 = 3\n* Sukhoi = 4","metadata":{}},{"cell_type":"code","source":"scaled = batch[0] / 255\nscaled.max()","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:22.352996Z","iopub.execute_input":"2023-11-09T06:31:22.353565Z","iopub.status.idle":"2023-11-09T06:31:22.368291Z","shell.execute_reply.started":"2023-11-09T06:31:22.353535Z","shell.execute_reply":"2023-11-09T06:31:22.367469Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Preprocessing Data","metadata":{}},{"cell_type":"markdown","source":"Scaling Data","metadata":{}},{"cell_type":"code","source":"data = data.map(lambda x,y: (x/255, y))\nscaled_iterator = data.as_numpy_iterator()","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:22.369789Z","iopub.execute_input":"2023-11-09T06:31:22.370458Z","iopub.status.idle":"2023-11-09T06:31:22.418923Z","shell.execute_reply.started":"2023-11-09T06:31:22.370418Z","shell.execute_reply":"2023-11-09T06:31:22.417885Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"batch = scaled_iterator.next()\nbatch[0].shape","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:22.420146Z","iopub.execute_input":"2023-11-09T06:31:22.420449Z","iopub.status.idle":"2023-11-09T06:31:23.396215Z","shell.execute_reply.started":"2023-11-09T06:31:22.420424Z","shell.execute_reply":"2023-11-09T06:31:23.394962Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig, ax = plt.subplots(ncols=10, figsize=(20,20))\nfor idx, img in enumerate(batch[0][:10]):\n    ax[idx].imshow(img)\n    ax[idx].title.set_text(batch[1][idx])","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:23.400144Z","iopub.execute_input":"2023-11-09T06:31:23.400788Z","iopub.status.idle":"2023-11-09T06:31:25.453388Z","shell.execute_reply.started":"2023-11-09T06:31:23.40075Z","shell.execute_reply":"2023-11-09T06:31:25.452438Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Splitting Data","metadata":{}},{"cell_type":"code","source":"train_size = int(len(data)*.7)\nval_size = int(len(data)*.2)\ntest_size = len(data) - train_size - val_size","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:25.454777Z","iopub.execute_input":"2023-11-09T06:31:25.455139Z","iopub.status.idle":"2023-11-09T06:31:25.461576Z","shell.execute_reply.started":"2023-11-09T06:31:25.455108Z","shell.execute_reply":"2023-11-09T06:31:25.460541Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(data))\nprint(train_size)\nprint(val_size)\nprint(test_size)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:25.462839Z","iopub.execute_input":"2023-11-09T06:31:25.463109Z","iopub.status.idle":"2023-11-09T06:31:25.47221Z","shell.execute_reply.started":"2023-11-09T06:31:25.463086Z","shell.execute_reply":"2023-11-09T06:31:25.471237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = data.take(train_size)\nval = data.skip(train_size).take(val_size)\ntest = data.skip(train_size + val_size).take(test_size)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:25.473396Z","iopub.execute_input":"2023-11-09T06:31:25.47401Z","iopub.status.idle":"2023-11-09T06:31:25.48819Z","shell.execute_reply.started":"2023-11-09T06:31:25.473976Z","shell.execute_reply":"2023-11-09T06:31:25.487224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(train))\nprint(len(val))\nprint(len(test))","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:25.489298Z","iopub.execute_input":"2023-11-09T06:31:25.489602Z","iopub.status.idle":"2023-11-09T06:31:25.497341Z","shell.execute_reply.started":"2023-11-09T06:31:25.489573Z","shell.execute_reply":"2023-11-09T06:31:25.496365Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Training the Data","metadata":{}},{"cell_type":"markdown","source":"Building the Deep Learning Model","metadata":{}},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Conv2D, MaxPooling2D, Dense, Flatten","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:25.498429Z","iopub.execute_input":"2023-11-09T06:31:25.498806Z","iopub.status.idle":"2023-11-09T06:31:25.507246Z","shell.execute_reply.started":"2023-11-09T06:31:25.498777Z","shell.execute_reply":"2023-11-09T06:31:25.506278Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = Sequential()\n\n#Adding a convolution layer and a max pooling layer\nmodel.add(Conv2D(16, (3,3) , 1, activation = 'relu', input_shape = (256,256,3)))\nmodel.add(MaxPooling2D())\n\nmodel.add(Conv2D(32, (3,3), 1, activation = 'relu'))\nmodel.add(MaxPooling2D())\n\nmodel.add(Conv2D(32, (3,3), 1, activation = 'relu'))\nmodel.add(MaxPooling2D())\n\nmodel.add(Conv2D(16, (3,3), 1, activation = 'relu'))\nmodel.add(MaxPooling2D())\n\nmodel.add(Conv2D(16, (3,3), 1, activation = 'relu'))\nmodel.add(MaxPooling2D())\n\nmodel.add(Flatten())\n\nmodel.add(Dense(256, activation = 'relu'))\nmodel.add(Dense(5, activation = 'sigmoid'))\n","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:25.508252Z","iopub.execute_input":"2023-11-09T06:31:25.508536Z","iopub.status.idle":"2023-11-09T06:31:25.653429Z","shell.execute_reply.started":"2023-11-09T06:31:25.508505Z","shell.execute_reply":"2023-11-09T06:31:25.652468Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile('adam', loss = tf.losses.SparseCategoricalCrossentropy(), metrics=['accuracy'])","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:31.502068Z","iopub.execute_input":"2023-11-09T06:31:31.50306Z","iopub.status.idle":"2023-11-09T06:31:31.522769Z","shell.execute_reply.started":"2023-11-09T06:31:31.50301Z","shell.execute_reply":"2023-11-09T06:31:31.521883Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.summary()","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:31.987785Z","iopub.execute_input":"2023-11-09T06:31:31.988125Z","iopub.status.idle":"2023-11-09T06:31:32.025225Z","shell.execute_reply.started":"2023-11-09T06:31:31.988099Z","shell.execute_reply":"2023-11-09T06:31:32.024313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Training the data","metadata":{}},{"cell_type":"code","source":"os.rmdir(\"/kaggle/working/logs\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.makedirs('/kaggle/working/logs')","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"logdir = '/kaggle/working/logs'\ntensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir = logdir)\nprint(train)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:31:37.783792Z","iopub.execute_input":"2023-11-09T06:31:37.784159Z","iopub.status.idle":"2023-11-09T06:31:37.789857Z","shell.execute_reply.started":"2023-11-09T06:31:37.78413Z","shell.execute_reply":"2023-11-09T06:31:37.788834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hist = model.fit(train, epochs = 40, validation_data = val, callbacks=[tensorboard_callback])","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:40:46.552873Z","iopub.execute_input":"2023-11-09T06:40:46.553808Z","iopub.status.idle":"2023-11-09T06:47:46.633627Z","shell.execute_reply.started":"2023-11-09T06:40:46.55377Z","shell.execute_reply":"2023-11-09T06:47:46.632764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Plotting Performance","metadata":{}},{"cell_type":"code","source":"fig = plt.figure()\nplt.plot(hist.history['accuracy'], color='teal', label='loss')\nplt.plot(hist.history['val_accuracy'], color='orange', label='val_loss')\nfig.suptitle('Loss', fontsize=20)\nplt.legend(loc='upper left')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:47:56.571843Z","iopub.execute_input":"2023-11-09T06:47:56.57225Z","iopub.status.idle":"2023-11-09T06:47:56.791624Z","shell.execute_reply.started":"2023-11-09T06:47:56.57222Z","shell.execute_reply":"2023-11-09T06:47:56.790595Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Evaluating Performance","metadata":{}},{"cell_type":"code","source":"from tensorflow.keras.metrics import Precision, Recall","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:48:02.41193Z","iopub.execute_input":"2023-11-09T06:48:02.412334Z","iopub.status.idle":"2023-11-09T06:48:02.41836Z","shell.execute_reply.started":"2023-11-09T06:48:02.412301Z","shell.execute_reply":"2023-11-09T06:48:02.417123Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pre = Precision\nre = Recall()\nprint(type(test))","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:48:02.75324Z","iopub.execute_input":"2023-11-09T06:48:02.753905Z","iopub.status.idle":"2023-11-09T06:48:02.765104Z","shell.execute_reply.started":"2023-11-09T06:48:02.753874Z","shell.execute_reply":"2023-11-09T06:48:02.764146Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for batch in test.as_numpy_iterator():\n    X, Y = batch\n    yhat = model.predict(X)\nprint(yhat)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:48:04.87162Z","iopub.execute_input":"2023-11-09T06:48:04.87205Z","iopub.status.idle":"2023-11-09T06:48:11.377231Z","shell.execute_reply.started":"2023-11-09T06:48:04.872013Z","shell.execute_reply":"2023-11-09T06:48:11.37612Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_classes = [np.argmax(element) for element in yhat]\nprint(y_classes[:5])\nprint(Y[:5])","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:48:11.378862Z","iopub.execute_input":"2023-11-09T06:48:11.379212Z","iopub.status.idle":"2023-11-09T06:48:11.385756Z","shell.execute_reply.started":"2023-11-09T06:48:11.379178Z","shell.execute_reply":"2023-11-09T06:48:11.38475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"classes = ['Commercial', 'Glider', 'Helicopter', 'MIG-29', 'Sukhoi']","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:48:17.755386Z","iopub.execute_input":"2023-11-09T06:48:17.756261Z","iopub.status.idle":"2023-11-09T06:48:17.76086Z","shell.execute_reply.started":"2023-11-09T06:48:17.756222Z","shell.execute_reply":"2023-11-09T06:48:17.759762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"img = cv2.imread('/kaggle/input/test-datas/test/image105.jpg')","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:48:18.118485Z","iopub.execute_input":"2023-11-09T06:48:18.119256Z","iopub.status.idle":"2023-11-09T06:48:18.128499Z","shell.execute_reply.started":"2023-11-09T06:48:18.11922Z","shell.execute_reply":"2023-11-09T06:48:18.127739Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:48:20.274966Z","iopub.execute_input":"2023-11-09T06:48:20.27535Z","iopub.status.idle":"2023-11-09T06:48:20.586597Z","shell.execute_reply.started":"2023-11-09T06:48:20.275317Z","shell.execute_reply":"2023-11-09T06:48:20.585572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resize = tf.image.resize(img, (256,256))\nplt.imshow(resize.numpy().astype(int))\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:48:23.863225Z","iopub.execute_input":"2023-11-09T06:48:23.863615Z","iopub.status.idle":"2023-11-09T06:48:24.175508Z","shell.execute_reply.started":"2023-11-09T06:48:23.863581Z","shell.execute_reply":"2023-11-09T06:48:24.174555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"yhat = model.predict(np.expand_dims(resize/255,0))\nnp.argmax(yhat)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:48:27.135081Z","iopub.execute_input":"2023-11-09T06:48:27.135443Z","iopub.status.idle":"2023-11-09T06:48:27.377152Z","shell.execute_reply.started":"2023-11-09T06:48:27.135412Z","shell.execute_reply":"2023-11-09T06:48:27.376079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def image_predictor(filename):\n    img = cv2.imread(filename)\n    resize = tf.image.resize(img, (256,256))\n    yhat = model.predict(np.expand_dims(resize/255,0))\n    x = yhat[0]\n    print(x)\n    return int(np.argmax(yhat))","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:55:27.578316Z","iopub.execute_input":"2023-11-09T06:55:27.579036Z","iopub.status.idle":"2023-11-09T06:55:27.584442Z","shell.execute_reply.started":"2023-11-09T06:55:27.579Z","shell.execute_reply":"2023-11-09T06:55:27.583397Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(np.argmax(0.9))\na = image_predictor('/kaggle/input/test-datas/test/image39.jpg')\nprint (type(a))\nprint(a)","metadata":{"execution":{"iopub.status.busy":"2023-11-09T07:01:18.507856Z","iopub.execute_input":"2023-11-09T07:01:18.508332Z","iopub.status.idle":"2023-11-09T07:01:18.582517Z","shell.execute_reply.started":"2023-11-09T07:01:18.50827Z","shell.execute_reply":"2023-11-09T07:01:18.581649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def number_return()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"a = image_predictor('/kaggle/input/test-datas/test/image105.jpg')\nprediction = []\nfor image in os.listdir(data_dir):\n    image_path = os.path.join(data_dir, image)\n    prediction.append([image, image_predictor(image_path)])\nprint(prediction[:5])","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:48:32.61079Z","iopub.execute_input":"2023-11-09T06:48:32.611724Z","iopub.status.idle":"2023-11-09T06:48:50.590875Z","shell.execute_reply.started":"2023-11-09T06:48:32.611653Z","shell.execute_reply":"2023-11-09T06:48:50.589868Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"file_names = []\nfile_prediction = []\nfor i in range(len(prediction)):\n    file_names.append(prediction[i][0])\n    file_prediction.append(classes[prediction[i][1]])\ndf = pd.DataFrame(file_names, columns=['image_path'])\nser = pd.Series(file_prediction)\ndf.insert(loc = 1, column='Class', value=ser)\ndf","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:49:00.698439Z","iopub.execute_input":"2023-11-09T06:49:00.699263Z","iopub.status.idle":"2023-11-09T06:49:00.739848Z","shell.execute_reply.started":"2023-11-09T06:49:00.699228Z","shell.execute_reply":"2023-11-09T06:49:00.738925Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('image_sub.csv')","metadata":{"execution":{"iopub.status.busy":"2023-11-09T06:49:10.467053Z","iopub.execute_input":"2023-11-09T06:49:10.467871Z","iopub.status.idle":"2023-11-09T06:49:10.476595Z","shell.execute_reply.started":"2023-11-09T06:49:10.467837Z","shell.execute_reply":"2023-11-09T06:49:10.475824Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}