{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":3362,"databundleVersionId":31148,"sourceType":"competition"}],"dockerImageVersionId":30356,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import zipfile\n\ntrain_path = '/kaggle/input/dogs-vs-cats/train.zip'\n\nz = zipfile.ZipFile(train_path)\nz.extractall()","metadata":{"execution":{"iopub.status.busy":"2023-01-20T08:42:05.378823Z","iopub.execute_input":"2023-01-20T08:42:05.379243Z","iopub.status.idle":"2023-01-20T08:42:18.952995Z","shell.execute_reply.started":"2023-01-20T08:42:05.37916Z","shell.execute_reply":"2023-01-20T08:42:18.951901Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.cluster.vq import kmeans, vq\nfrom sklearn.svm import LinearSVC\nfrom sklearn.preprocessing import StandardScaler\nimport os","metadata":{"execution":{"iopub.status.busy":"2023-01-20T08:42:18.956886Z","iopub.execute_input":"2023-01-20T08:42:18.957828Z","iopub.status.idle":"2023-01-20T08:42:19.901821Z","shell.execute_reply.started":"2023-01-20T08:42:18.957784Z","shell.execute_reply":"2023-01-20T08:42:19.900659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_dir='/kaggle/working/train'\nif  not os.path.exists((os.path.join(train_dir,'cat'))):\n    os.mkdir(os.path.join(train_dir,'cat'))\nif  not os.path.exists((os.path.join(train_dir,'dog'))):\n    os.mkdir(os.path.join(train_dir,'dog'))\n    \nfor file in os.listdir(train_dir):\n    if file[-3]=='j':\n        if file[0]=='c':\n            os.replace(os.path.join(train_dir,file),os.path.join(train_dir,'cat',file))\n        else:\n            os.replace(os.path.join(train_dir,file),os.path.join(train_dir,'dog',file))","metadata":{"execution":{"iopub.status.busy":"2023-01-20T08:42:19.90351Z","iopub.execute_input":"2023-01-20T08:42:19.903954Z","iopub.status.idle":"2023-01-20T08:42:20.60584Z","shell.execute_reply.started":"2023-01-20T08:42:19.903914Z","shell.execute_reply":"2023-01-20T08:42:20.60477Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_path = \"/kaggle/working/train\"\nlabels = []\ntrain_img_list = []\ntrain_id_list = []\nfor idx, folder_path in enumerate(os.listdir(train_path)) :\n    full_path = f'{train_path}/{folder_path}'\n    labels.append(folder_path)\n    for image_path in os.listdir(full_path):\n        train_id_list.append(idx)\n        full_img_path = f'{train_path}/{folder_path}/{image_path}'\n        train_img_list.append(full_img_path)","metadata":{"execution":{"iopub.status.busy":"2023-01-20T08:42:20.608192Z","iopub.execute_input":"2023-01-20T08:42:20.608562Z","iopub.status.idle":"2023-01-20T08:42:20.642355Z","shell.execute_reply.started":"2023-01-20T08:42:20.608526Z","shell.execute_reply":"2023-01-20T08:42:20.641209Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print (labels)","metadata":{"execution":{"iopub.status.busy":"2023-01-20T08:42:20.643992Z","iopub.execute_input":"2023-01-20T08:42:20.644679Z","iopub.status.idle":"2023-01-20T08:42:20.650992Z","shell.execute_reply.started":"2023-01-20T08:42:20.644631Z","shell.execute_reply":"2023-01-20T08:42:20.649793Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sift = cv2.SIFT_create()\n\ntrain_descriptor_list = []\nfor img in train_img_list:\n    image = cv2.imread (img)\n    _, train_descriptor = sift.detectAndCompute (image, None)\n    train_descriptor_list.append(train_descriptor)\n\nstacked_descriptor_list = train_descriptor_list[0]\n\nfor descriptor in train_descriptor_list[1:]:\n    stacked_descriptor_list = np.vstack ((stacked_descriptor_list, descriptor))\n\nstacked_descriptor_list = np.float32(stacked_descriptor_list)","metadata":{"execution":{"iopub.status.busy":"2023-01-20T08:44:04.599204Z","iopub.execute_input":"2023-01-20T08:44:04.599651Z"},"trusted":true},"execution_count":null,"outputs":[]}]}