{"id":24880681,"url":"https://github.com/arif-miad/plant-species-classification-using-cnn","last_synced_at":"2026-04-19T04:36:31.963Z","repository":{"id":275150478,"uuid":"925230737","full_name":"Arif-miad/Plant-Species-Classification-using-CNN","owner":"Arif-miad","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-31T13:46:54.000Z","size":287,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-27T06:16:11.460Z","etag":null,"topics":["cnn","deep-learning","image-classification","keras","python","seaborn","tensorflow"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Arif-miad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-31T13:38:59.000Z","updated_at":"2025-01-31T13:46:58.000Z","dependencies_parsed_at":"2025-01-31T14:32:12.405Z","dependency_job_id":"48b81fab-7267-4b74-a001-f7f96ed73b33","html_url":"https://github.com/Arif-miad/Plant-Species-Classification-using-CNN","commit_stats":null,"previous_names":["arif-miad/plant-species-classification-using-cnn"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Arif-miad/Plant-Species-Classification-using-CNN","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arif-miad%2FPlant-Species-Classification-using-CNN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arif-miad%2FPlant-Species-Classification-using-CNN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arif-miad%2FPlant-Species-Classification-using-CNN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arif-miad%2FPlant-Species-Classification-using-CNN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Arif-miad","download_url":"https://codeload.github.com/Arif-miad/Plant-Species-Classification-using-CNN/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Arif-miad%2FPlant-Species-Classification-using-CNN/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272982764,"owners_count":25025984,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-31T02:00:09.071Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cnn","deep-learning","image-classification","keras","python","seaborn","tensorflow"],"created_at":"2025-02-01T11:19:10.657Z","updated_at":"2026-04-19T04:36:31.836Z","avatar_url":"https://github.com/Arif-miad.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n\n#### 🌱 **Plant Species Classification using CNN**  \n\n![Plants](https://github.com/Arif-miad/Plant-Species-Classification-using-CNN/blob/main/ezgif-3f8cceb92a8cf.jpg)  \n\n---\n\n## 📖 **Overview**  \nThis project focuses on **classifying plant species** using a **Convolutional Neural Network (CNN)**. The dataset consists of synthetic plant images categorized into five classes:  \n\n- 🌵 **Cactus**  \n- 🌿 **Fern**  \n- 🌹 **Rose**  \n- 🌻 **Sunflower**  \n- 🌷 **Tulip**  \n\nWe use **TensorFlow \u0026 Keras** to train a deep learning model for **image classification**. The final trained model is evaluated, saved, and can be deployed for real-time predictions.  \n\n---\n\n## 📂 **Dataset Structure**  \n\n```\nplants-classification/\n│── dataset/\n│   ├── train/\n│   │   ├── cactus/\n│   │   ├── fern/\n│   │   ├── rose/\n│   │   ├── sunflower/\n│   │   ├── tulip/\n│   ├── val/\n│   │   ├── cactus/\n│   │   ├── fern/\n│   │   ├── rose/\n│   │   ├── sunflower/\n│   │   ├── tulip/\n│   ├── train.cache\n│   ├── val.cache\n```\n\n---\n\n## 🚀 **Project Implementation**  \n\n### **✔ 1️⃣ Data Loading**  \nWe load images from the dataset using `tf.keras.preprocessing.image_dataset_from_directory()`.  \n\n```python\ntrain_ds = tf.keras.preprocessing.image_dataset_from_directory(\n    \"dataset/train\", image_size=(224, 224), batch_size=32\n)\nval_ds = tf.keras.preprocessing.image_dataset_from_directory(\n    \"dataset/val\", image_size=(224, 224), batch_size=32\n)\n```\n\n---\n\n### **✔ 2️⃣ Preprocessing \u0026 Data Augmentation**  \nWe normalize pixel values and apply transformations like flipping and rotation.  \n\n```python\ndata_augmentation = tf.keras.Sequential([\n    tf.keras.layers.RandomFlip(\"horizontal\"),\n    tf.keras.layers.RandomRotation(0.2),\n])\n```\n\n---\n\n### **✔ 3️⃣ CNN Model Creation**  \nA deep learning model is built using Convolutional Neural Networks (CNNs).  \n\n```python\nmodel = tf.keras.Sequential([\n    tf.keras.layers.Rescaling(1./255, input_shape=(224, 224, 3)),\n    data_augmentation,\n\n    tf.keras.layers.Conv2D(32, (3,3), activation=\"relu\"),\n    tf.keras.layers.MaxPooling2D(),\n\n    tf.keras.layers.Conv2D(64, (3,3), activation=\"relu\"),\n    tf.keras.layers.MaxPooling2D(),\n\n    tf.keras.layers.Conv2D(128, (3,3), activation=\"relu\"),\n    tf.keras.layers.MaxPooling2D(),\n\n    tf.keras.layers.Flatten(),\n    tf.keras.layers.Dense(128, activation=\"relu\"),\n    tf.keras.layers.Dropout(0.5),\n    tf.keras.layers.Dense(5, activation=\"softmax\")\n])\n```\n\n---\n\n### **✔ 4️⃣ Model Training \u0026 Evaluation**  \nThe model is compiled and trained using **Adam optimizer** and **sparse categorical crossentropy loss**.  \n\n```python\nmodel.compile(optimizer=\"adam\",\n              loss=\"sparse_categorical_crossentropy\",\n              metrics=[\"accuracy\"])\n\nhistory = model.fit(train_ds, validation_data=val_ds, epochs=20)\n```\n\nWe then evaluate the trained model:  \n\n```python\nloss, accuracy = model.evaluate(val_ds)\nprint(f\"Validation Accuracy: {accuracy*100:.2f}%\")\n```\n\n---\n\n### **✔ 5️⃣ Predictions on New Images**  \nWe load an image and use the trained model to predict its class.  \n\n```python\ndef predict_image(image_path, model, class_names):\n    img = tf.keras.preprocessing.image.load_img(image_path, target_size=(224, 224))\n    img_array = tf.keras.preprocessing.image.img_to_array(img)\n    img_array = tf.expand_dims(img_array, 0)\n\n    predictions = model.predict(img_array)\n    predicted_class = class_names[np.argmax(predictions)]\n    confidence = np.max(predictions)\n\n    plt.imshow(img)\n    plt.title(f\"Prediction: {predicted_class} ({confidence:.2f})\")\n    plt.axis(\"off\")\n    plt.show()\n\npredict_image(\"dataset/val/rose/rose1.jpg\", model, train_ds.class_names)\n```\n\n---\n\n### **✔ 6️⃣ Model Saving \u0026 Deployment**  \nSave the trained model for future use.  \n\n```python\nmodel.save(\"plant_classification_model.h5\")\n```\n\nConvert to **TensorFlow Lite** for mobile or edge deployment.  \n\n```python\nconverter = tf.lite.TFLiteConverter.from_keras_model(model)\ntflite_model = converter.convert()\n\nwith open(\"plant_classification_model.tflite\", \"wb\") as f:\n    f.write(tflite_model)\n```\n\n---\n\n## 📌 **Results \u0026 Accuracy**  \nThe CNN model achieves high accuracy in classifying plant species.  \n📈 **Validation Accuracy:** **~95%**  \n\n---\n\n## 🛠 **Technologies Used**  \n- **Python**  \n- **TensorFlow / Keras**  \n- **Matplotlib**  \n- **NumPy**  \n- **OpenCV** (for image processing)  \n\n---\n\n## 📝 **Future Improvements**  \n🔹 Use a **larger dataset** for better accuracy.  \n🔹 Implement **Transfer Learning (ResNet, MobileNet, EfficientNet)** for improved performance.  \n🔹 Deploy as a **Flask API or Streamlit App** for real-world use.  \n\n---\n\n## 🎯 **Conclusion**  \nThis project demonstrates a **CNN-based deep learning model** for classifying plants into different species. The trained model can be further **optimized, fine-tuned, and deployed** for real-world applications.  \n\n---\n\n## ⭐ **Contribute**  \nIf you find this project useful, feel free to **⭐ Star the repository** and **Fork it**! 🚀  \n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farif-miad%2Fplant-species-classification-using-cnn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farif-miad%2Fplant-species-classification-using-cnn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farif-miad%2Fplant-species-classification-using-cnn/lists"}