{"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-06-22T22:48:04.601183Z","iopub.execute_input":"2023-06-22T22:48:04.602285Z","iopub.status.idle":"2023-06-22T22:48:04.62048Z","shell.execute_reply.started":"2023-06-22T22:48:04.602236Z","shell.execute_reply":"2023-06-22T22:48:04.619273Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nimport glob\nfrom keras.models import Sequential\nfrom keras.layers import activation,Flatten,MaxPooling2D,Conv2D,Dense\nfrom keras.layers.normalization import batch_normalization\nimport cv2","metadata":{"execution":{"iopub.status.busy":"2023-06-22T22:48:18.044854Z","iopub.execute_input":"2023-06-22T22:48:18.045321Z","iopub.status.idle":"2023-06-22T22:48:18.053236Z","shell.execute_reply.started":"2023-06-22T22:48:18.045286Z","shell.execute_reply":"2023-06-22T22:48:18.051615Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from zipfile import ZipFile\n\ndataset = '/kaggle/input/dogs-vs-cats/train.zip'\n\nwith ZipFile(dataset, 'r') as zip:\n  zip.extractall()\n  print('The dataset is extracted')","metadata":{"execution":{"iopub.status.busy":"2023-06-22T22:48:27.172526Z","iopub.execute_input":"2023-06-22T22:48:27.173006Z","iopub.status.idle":"2023-06-22T22:48:39.783767Z","shell.execute_reply.started":"2023-06-22T22:48:27.172971Z","shell.execute_reply":"2023-06-22T22:48:39.782527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import cv2\nimport glob\nimport os\n\n# المسار إلى مجلد الصور\nimage_folder = \"/kaggle/working/train\"\n\n# قائمة لتخزين الصور\nimages = []\n\n# قائمة لتخزين العلامات\nlabels = []\n\n# قراءة الصور والعلامات\nfor image_path in glob.glob(os.path.join(image_folder, \"*.jpg\")):\n    image = cv2.imread(image_path,cv2.IMREAD_COLOR)\n    image =cv2.cvtColor(image,cv2.COLOR_BGR2RGB)\n    image =cv2.resize(image,(120,120))\n    label = os.path.basename(image_path).split(\"_\")[0].split('.')[0]  # افتراض أن العلامة موجودة قبل الشرطة المنخفضة\n    images.append(image)\n    labels.append(label)\n\n","metadata":{"execution":{"iopub.status.busy":"2023-06-22T22:48:42.785904Z","iopub.execute_input":"2023-06-22T22:48:42.786452Z","iopub.status.idle":"2023-06-22T22:49:58.433812Z","shell.execute_reply.started":"2023-06-22T22:48:42.786409Z","shell.execute_reply":"2023-06-22T22:49:58.432523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"np.random.RandomState(seed=42).shuffle(images)\nnp.random.RandomState(seed=42).shuffle(labels)\n\nimages = np.array(images)\nlabels = np.array(labels)\n\n# عرض أبعاد الصور وعدد العلامات\nprint(\"Shape of images:\", images.shape)\nprint(\"Number of labels:\", len(labels))","metadata":{"execution":{"iopub.status.busy":"2023-06-22T22:50:17.96067Z","iopub.execute_input":"2023-06-22T22:50:17.961182Z","iopub.status.idle":"2023-06-22T22:50:18.848989Z","shell.execute_reply.started":"2023-06-22T22:50:17.961144Z","shell.execute_reply":"2023-06-22T22:50:18.847518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(images[10])","metadata":{"execution":{"iopub.status.busy":"2023-06-22T17:43:16.377533Z","iopub.execute_input":"2023-06-22T17:43:16.377872Z","iopub.status.idle":"2023-06-22T17:43:16.579443Z","shell.execute_reply.started":"2023-06-22T17:43:16.377846Z","shell.execute_reply":"2023-06-22T17:43:16.578601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nx_train,x_test,y_train,y_test=train_test_split(images,labels,random_state=42,train_size=.75)","metadata":{"execution":{"iopub.status.busy":"2023-06-22T22:50:24.950396Z","iopub.execute_input":"2023-06-22T22:50:24.950913Z","iopub.status.idle":"2023-06-22T22:50:26.288417Z","shell.execute_reply.started":"2023-06-22T22:50:24.950866Z","shell.execute_reply":"2023-06-22T22:50:26.287026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train , x_test = x_train/255.0 ,x_test/255.0","metadata":{"execution":{"iopub.status.busy":"2023-06-22T22:50:27.376008Z","iopub.execute_input":"2023-06-22T22:50:27.376458Z","iopub.status.idle":"2023-06-22T22:50:32.894343Z","shell.execute_reply.started":"2023-06-22T22:50:27.376426Z","shell.execute_reply":"2023-06-22T22:50:32.892998Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.layers import BatchNormalization","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"activation='sigmoid'\n\nfeature=Sequential()\nfeature.add(Conv2D(32,3,activation=activation,padding='same',input_shape=(120,120,3)))\nfeature.add(BatchNormalization())\nfeature.add(MaxPooling2D())\n\nfeature.add(Conv2D(32,3,activation=activation,padding='same'))\nfeature.add(BatchNormalization())\nfeature.add(MaxPooling2D())\n\nfeature.add(Conv2D(64,3,activation=activation,padding='same'))\nfeature.add(BatchNormalization())\nfeature.add(MaxPooling2D())\n\nfeature.add(Flatten())","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications.vgg16 import VGG16\nfeature=VGG16(weights='imagenet',include_top=False,input_shape=(120,120,3))\n\nfor layer in feature.layers:\n    layer.trainable=False","metadata":{"execution":{"iopub.status.busy":"2023-06-21T00:43:47.48263Z","iopub.execute_input":"2023-06-21T00:43:47.483059Z","iopub.status.idle":"2023-06-21T00:43:50.64905Z","shell.execute_reply.started":"2023-06-21T00:43:47.483024Z","shell.execute_reply":"2023-06-21T00:43:50.647707Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2\nfeature=MobileNetV2(weights='imagenet',include_top=False,input_shape=(120,120,3))\n\nfor layer in feature.layers:\n    layer.trainable=False","metadata":{"execution":{"iopub.status.busy":"2023-06-22T22:50:45.220035Z","iopub.execute_input":"2023-06-22T22:50:45.220539Z","iopub.status.idle":"2023-06-22T22:50:48.172222Z","shell.execute_reply.started":"2023-06-22T22:50:45.220501Z","shell.execute_reply":"2023-06-22T22:50:48.17075Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_rf=feature.predict(x_train)","metadata":{"execution":{"iopub.status.busy":"2023-06-22T23:33:17.998321Z","iopub.execute_input":"2023-06-22T23:33:17.998925Z","iopub.status.idle":"2023-06-22T23:35:43.866513Z","shell.execute_reply.started":"2023-06-22T23:33:17.998884Z","shell.execute_reply":"2023-06-22T23:35:43.865165Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_rf=x_rf.reshape(x_rf.shape[0],-1)","metadata":{"execution":{"iopub.status.busy":"2023-06-22T23:36:07.672833Z","iopub.execute_input":"2023-06-22T23:36:07.67333Z","iopub.status.idle":"2023-06-22T23:36:07.679859Z","shell.execute_reply.started":"2023-06-22T23:36:07.673295Z","shell.execute_reply":"2023-06-22T23:36:07.678461Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nl=LabelEncoder()\ny_train=l.fit_transform(y_train)\ny_test=l.fit_transform(y_test)\nprint(l.classes_)\nplt.imshow(x_train[10])\nprint(y_train[10])","metadata":{"execution":{"iopub.status.busy":"2023-06-22T23:23:34.169205Z","iopub.execute_input":"2023-06-22T23:23:34.170745Z","iopub.status.idle":"2023-06-22T23:23:34.518243Z","shell.execute_reply.started":"2023-06-22T23:23:34.170661Z","shell.execute_reply":"2023-06-22T23:23:34.516834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-06-22T23:28:32.865791Z","iopub.execute_input":"2023-06-22T23:28:32.866322Z","iopub.status.idle":"2023-06-22T23:28:32.875942Z","shell.execute_reply.started":"2023-06-22T23:28:32.866286Z","shell.execute_reply":"2023-06-22T23:28:32.874286Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.ensemble import HistGradientBoostingClassifier\nmodel=HistGradientBoostingClassifier(random_state=42)\n\nmodel.fit(x_rf,y_train)","metadata":{"execution":{"iopub.status.busy":"2023-06-22T23:36:13.455024Z","iopub.execute_input":"2023-06-22T23:36:13.455461Z","iopub.status.idle":"2023-06-22T23:42:55.790913Z","shell.execute_reply.started":"2023-06-22T23:36:13.45543Z","shell.execute_reply":"2023-06-22T23:42:55.789465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"x_test_rf=feature.predict(x_test)\nx_test_rf=x_test_rf.reshape(x_test_rf.shape[0],-1)\nprediction_rf=model.predict(x_test_rf)","metadata":{"execution":{"iopub.status.busy":"2023-06-22T23:43:02.777927Z","iopub.execute_input":"2023-06-22T23:43:02.778416Z","iopub.status.idle":"2023-06-22T23:43:47.670937Z","shell.execute_reply.started":"2023-06-22T23:43:02.778381Z","shell.execute_reply":"2023-06-22T23:43:47.669771Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\n\nacc=accuracy_score(y_test,prediction_rf)\nprint(acc)","metadata":{"execution":{"iopub.status.busy":"2023-06-22T23:43:51.680646Z","iopub.execute_input":"2023-06-22T23:43:51.68122Z","iopub.status.idle":"2023-06-22T23:43:51.691515Z","shell.execute_reply.started":"2023-06-22T23:43:51.681178Z","shell.execute_reply":"2023-06-22T23:43:51.689955Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_test[20])","metadata":{"execution":{"iopub.status.busy":"2023-06-22T17:48:20.519764Z","iopub.execute_input":"2023-06-22T17:48:20.520133Z","iopub.status.idle":"2023-06-22T17:48:20.741171Z","shell.execute_reply.started":"2023-06-22T17:48:20.5201Z","shell.execute_reply":"2023-06-22T17:48:20.740449Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"prediction_rf[20]","metadata":{"execution":{"iopub.status.busy":"2023-06-22T17:48:31.622122Z","iopub.execute_input":"2023-06-22T17:48:31.622466Z","iopub.status.idle":"2023-06-22T17:48:31.63032Z","shell.execute_reply.started":"2023-06-22T17:48:31.622441Z","shell.execute_reply":"2023-06-22T17:48:31.629293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.imshow(x_test[10])","metadata":{"execution":{"iopub.status.busy":"2023-06-22T17:48:38.512644Z","iopub.execute_input":"2023-06-22T17:48:38.512971Z","iopub.status.idle":"2023-06-22T17:48:38.682114Z","shell.execute_reply.started":"2023-06-22T17:48:38.512946Z","shell.execute_reply":"2023-06-22T17:48:38.681187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"input_img=input('input the image path')\nfrom IPython.display import Image, display\n\n# Specify the path to the uploaded image\nimage_path = input_img\n\n# Display the image\ndisplay(Image(filename=image_path))\n\n#for image_path in glob.glob(os.path.join(input_img, \"*.jpg\")):\nimage = cv2.imread(input_img)\nimage =cv2.cvtColor(image,cv2.COLOR_BGR2RGB)\nimage =cv2.resize(image,(120,120))\n\nimage =np.array(image)\n\n\n\nimage =image/255\nimage = np.expand_dims(image, axis=0)\nx_rf=feature.predict(image)\nx_rf=x_rf.reshape(x_rf.shape[0],-1)\n\nprediction_rf=model.predict(x_rf)\n\nprint(prediction_rf)\nif prediction_rf[0]==0:\n    print('cat')\nelse:\n    print('dog')","metadata":{"execution":{"iopub.status.busy":"2023-06-22T23:47:15.719675Z","iopub.execute_input":"2023-06-22T23:47:15.720291Z","iopub.status.idle":"2023-06-22T23:47:23.698425Z","shell.execute_reply.started":"2023-06-22T23:47:15.720247Z","shell.execute_reply":"2023-06-22T23:47:23.69688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from zipfile import ZipFile\n\ndataset = '/kaggle/input/dogs-vs-cats/test1.zip'\n\nwith ZipFile(dataset, 'r') as zip:\n  zip.extractall()\n  print('The dataset is extracted')","metadata":{"execution":{"iopub.status.busy":"2023-06-22T23:00:19.099529Z","iopub.execute_input":"2023-06-22T23:00:19.100817Z","iopub.status.idle":"2023-06-22T23:00:25.764358Z","shell.execute_reply.started":"2023-06-22T23:00:19.100683Z","shell.execute_reply":"2023-06-22T23:00:25.763405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}