diff --git a/Detection Models/Fire-Detection-YOLOv8/README.md b/Detection Models/Fire-Detection-YOLOv8/README.md new file mode 100644 index 000000000..0ada2b547 --- /dev/null +++ b/Detection Models/Fire-Detection-YOLOv8/README.md @@ -0,0 +1,66 @@ + +# Fire Detection using YOLOv8 + +## :red_circle: Title +Fire Detection using YOLOv8 + +## :red_circle: Aim +The aim of this project is to implement a fire detection system using the YOLOv8 (You Only Look Once) object detection model to identify fire in images and videos. + +## :red_circle: Brief Explanation +This project leverages the YOLOv8 architecture, which is known for its speed and accuracy in object detection tasks. The model is trained to detect fire and can be applied in various domains, including safety monitoring and environmental protection. + +### Key Features: +- **Real-Time Fire Detection**: Quickly identifies fire in images and videos. +- **Model Implementation**: Easy integration of YOLOv8 for fire detection tasks. +- **Flexible Usage**: Can be adapted for different environments and scenarios. + +### Requirements +To run this project, you will need the following dependencies: +- Python 3.x +- PyTorch +- OpenCV +- NumPy +- Matplotlib + +## Installation +1. Clone the repository: + ```bash + git clone https://github.com/rugved0102/Fire-Detection-using-YOLOv8.git + cd Fire-Detection-using-YOLOv8/Fire-Detection-YOLOv8 + ``` + +2. Install the required packages: + ```bash + pip install -r requirements.txt + ``` + +## Usage +You can use the `main.py` file to implement fire detection using YOLOv8. Below is a brief explanation of how to use it: + +1. Prepare your input images. +2. Run the following command: + ```bash + python main.py --input --output + ``` +3. The output will display the detected fire instances along with the confidence score. + +### Example +```bash +python main.py --input path/to/image.jpg --output path/to/output.jpg +``` + +## Screenshots 📷 +![image](https://github.com/user-attachments/assets/415f5dfe-ee33-42b4-aa8e-2466ad8c6d45) + + +## Contributions +Feel free to contribute to this project. Please adhere to the following guidelines while making contributions: +- Follow PEP 8 standards for code. +- Use meaningful commit messages. +- Ensure the code works as expected before submitting a pull request. +- Comment your code for better readability. + +## License +This project is licensed under the MIT License. See the LICENSE file for more details. + diff --git a/Detection Models/Fire-Detection-YOLOv8/main.py b/Detection Models/Fire-Detection-YOLOv8/main.py new file mode 100644 index 000000000..acc3340c4 --- /dev/null +++ b/Detection Models/Fire-Detection-YOLOv8/main.py @@ -0,0 +1,57 @@ +# main.py +""" +Fire Detection using YOLOv8 + +This script demonstrates how to use YOLOv8 for detecting fire in images. +It loads a pre-trained YOLOv8 model, takes an input image, and performs fire detection. +Ensure that the YOLOv8 model is trained or fine-tuned for fire detection before using. + +Follow PEP 8 coding standards. + +Usage: + python main.py --image +""" + +import argparse +import cv2 +from ultralytics import YOLO + +# Function to perform fire detection using YOLOv8 +def detect_fire(image_path): + """ + Detects fire in an input image using YOLOv8 model. + + Parameters: + image_path (str): The path to the input image for fire detection. + + Returns: + None + """ + # Load the YOLOv8 model (pre-trained or fine-tuned on fire detection) + model = YOLO("yolov8n.pt") # Replace "yolov8n.pt" with the path to your YOLOv8 fire detection model + + # Load image using OpenCV + image = cv2.imread(image_path) + if image is None: + print(f"Error: Could not open image from {image_path}") + return + + # Perform detection + results = model(image) + + # Display the results + print(f"Fire detected in the image: {image_path}") + results.show() # This will open a window to display the image with detection results + + # Save the results image + results.save(save_dir="runs/detect/fire_detection") + +if __name__ == "__main__": + # Set up argument parsing for the input image + parser = argparse.ArgumentParser(description="Fire detection using YOLOv8.") + parser.add_argument("--image", required=True, help="Path to the input image for fire detection.") + args = parser.parse_args() + + # Call the detection function with the input image + detect_fire(args.image) +