Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions Detection Models/Fire-Detection-YOLOv8/README.md
Original file line number Diff line number Diff line change
@@ -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 <path_to_your_image_or_video> --output <path_to_save_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.

57 changes: 57 additions & 0 deletions Detection Models/Fire-Detection-YOLOv8/main.py
Original file line number Diff line number Diff line change
@@ -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 <path_to_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)