GithubHelp home page GithubHelp logo

nimradev064 / forest-fire-classification Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 196.4 MB

Utilizes TensorFlow framework to train ResNet-50, VGG-16, and custom CNN models for accurately classifying forest fire images, aiding in early detection and mitigation efforts.

Jupyter Notebook 100.00%
cnn-classification machine-learning-algorithms preprocessing python resnet-50 tensorflow vgg-16

forest-fire-classification's Introduction

Forest Fire Classification

Introduction

In the Forest Fire Classification project, we aim to develop a robust model using TensorFlow framework that accurately identifies instances of forest fires from images. Leveraging pre-trained models like ResNet-50, VGG16 (transfer learning) alongside Convolutional Neural Networks (CNN) facilitates feature extraction and classification processes efficiently. The project involves collecting a diverse dataset of forest fire images along with non-fire images for training and evaluation purposes.

Initially, we preprocess the dataset by resizing, normalizing, and augmenting images to enhance model generalization. We then split the dataset into training, validation, and testing sets to ensure unbiased evaluation. Employing transfer learning, we fine-tune ResNet-50 and VGG16 architectures on the dataset, adapting the pre-trained models' weights to classify forest fire images effectively.
During training, we employ techniques like learning rate scheduling, early stopping, and model checkpoints to optimize model performance and prevent overfitting. Additionally, we utilize techniques such as data augmentation to expand the dataset and improve model robustness. Extensive hyperparameter tuning and model optimization are performed to achieve the desired accuracy threshold of over 90%.

Post-training, rigorous evaluation is conducted on the testing set to assess the model's performance in real-world scenarios. Metrics like accuracy, precision, recall, and F1 score are computed to gauge the model's effectiveness in detecting forest fires accurately. Finally, the model is deployed in production environments where it can actively monitor and identify forest fire occurrences, aiding in timely interventions and mitigating potential disasters.

Steps

  • Installing Python, PyCharm, Git to Computer.
  • Download the source dataset from Kaggle.
  • For Classification algorithm decided to predict the features Classes from the dataset which is Binary classification (fire, not fire).
  • For Regression Problem algorithm decided to predict the feature FWI (Fire weather Index) which is 90%+ correlated to Classes Feature.

Import Libraries:

We import the necessary libraries specifically tailored for forest fire classification. These libraries enable efficient data manipulation for forest fire classification.

Load Dataset :

We upload the dataset on our google drive and then access the forestfire dataset into our colab notebook code file, that allow us to work with the data, enabling data preprocessing, model development, and predictive analysis, all within a collaborative environment.

Identify the Number of Classes :

After access the dataset from google drive , To identify the number of classes in Forest Fire Classification Dataset. This Dataset has two classes Fire and non Fire.

Preprocessing and Feature Engineering :

After access the dataset from google drive, to identify the number of classes in forest fire classification. By using Tensorflow build in module , we split the dataset into training and validation by using 0.2 validation split , shuffle , image size and many other parameters etc. Training dataset is the dataset used to train the machine learning model. The model learns the underlying patterns and relationships in the data by adjusting its parameters. Validation dataset is a separate dataset used to evaluate the model's performance during training. This helps to prevent overfitting, which is when the model learns the training data too well and cannot generalize to new data.

Visualization :

Show the atleast five images from each folder of forest fire classification like fire and non fire.

1 : RGB Images Display: To display an RGB image, the computer first converts the Forest Fire Classification to a digital format. This is done by breaking down the image into a grid of pixels and assigning each pixel a value for each color channel. The computer then sends these values to the monitor, which uses them to control the intensity of the red, green, and blue subpixels for each pixel. 2 : RGB convert into GrayScale images: To convert an RGB Forest Fire image to grayscale, the three color channels are combined into a single channel using a weighted average. The following weights are commonly used:

Grayscale = 0.2989 * Red + 0.5870 * Green + 0.1140 * Blue

These weights are chosen because they mimic the human eye's sensitivity to different colors. The human eye is most sensitive to green light, followed by red light, and then blue light.

RGB

2 : Grayscale images convert into Normalization:

Image normalization is the process of transforming an image so that its pixel values have a mean of zero and a standard deviation of one. This is often done before training a machine learning model on images, as it can help the model to learn more effectively.

To normalize a grayscale image, the following steps are typically taken:

Subtract the mean of the image from each pixel. Divide each pixel by the standard deviation of the image.

This will result in an image with pixel values that are centered around zero and have a standard deviation of one.

Screenshot 2024-02-14 124245

Model Buiding:

CNN model with Tensorflow:

The TensorFlow CNN model described above is a simple but effective model for image classification. It consists of the following layers:

  • Rescaling layer (1./255, input_shape=(img_height, img_width, 3)): Scales the input images down to a range of [0, 1].
  • Conv2D layer (16 filters, 3x3 kernel size, same padding, ReLU activation function): Extracts low-level features from the image, such as edges and corners.
  • MaxPooling2D layer: Reduces the dimensionality of the feature maps by reducing the size of each feature map by half.
  • Conv2D layer (32 filters, 3x3 kernel size, same padding, ReLU activation function): Extracts higher-level features from the image, such as shapes and textures.
  • MaxPooling2D layer: Reduces the dimensionality of the feature maps by reducing the size of each feature map by half.
  • Conv2D layer (64 filters, 3x3 kernel size, same padding, ReLU activation function): Extracts even higher-level features from the image, such as objects and scenes.
  • MaxPooling2D layer: Reduces the dimensionality of the feature maps by reducing the size of each feature map by half.
  • Flatten layer: Converts the feature maps into a 1D vector.
  • Dense layer (128 units, ReLU activation function): Learns higher-level features from the flattened feature maps.
  • Dense layer (num_classes): Outputs the probability distribution over the num_classes output classes. To train your model, you would simply need to compile it using an optimizer and loss function of your choice. Then, you could train it on your training data using the model.fit() method. Once the model is trained, you could evaluate it on your test data using the model.evaluate() method.

VGG16

The model is used for binary image classification, meaning that it will output the probability that an image belongs to one of two classes. The code works as follows:

  • The IMG_SIZE variable is defined to specify the height and width of the input images.
  • The vgg16_weight_path variable is defined to specify the path to the VGG16 pre-trained weights file.
  • The base_model variable is created by loading the VGG16 pre-trained model, but excluding the top layer. This is because the top layer is specific to the dataset that the model was trained on, and we want to train our own top layer for our specific binary image classification task.
  • The model_vgg16 variable is created by creating a Sequential model and adding the base_model to it.
  • A Flatten layer is added to the model to convert the feature maps from the base_model into a 1D vector.
  • A Dropout layer is added to the model to prevent overfitting.
  • A Dense layer with 1 unit and a sigmoid activation function is added to the model as the output layer. This layer will output the probability that an image belongs to one of the two classes.
  • The trainable attribute of the base_model is set to False. This means that the weights of the base_model will not be updated during training, which will make the training process more efficient.
  • The model is compiled using the binary_crossentropy loss function and the Adam optimizer. The accuracy metric is also specified, so that we can track the accuracy of the model during training and evaluation.
  • This model is likely to achieve good performance on a variety of binary image classification tasks. However, it is important to note that the VGG16 pre-trained weights were trained on a dataset that contains a wide variety of images. If your dataset is very different from the dataset that the VGG16 model was trained on, then you may want to consider fine-tuning the model on your own dataset.
  • To fine-tune the model, you would simply need to set the trainable attribute of the base_model to True and train the model as usual. This will allow the model to learn new weights that are specific to your dataset.

Resnet Network:

The model is built using the following steps:

  • The resnet_50 variable is created by loading the ResNet50 pre-trained model.
  • The x variable is assigned to the output of the resnet_50 model.
  • A GlobalAveragePooling2D layer is added to the model. This layer averages the values of each feature map over the spatial dimensions.
  • A Dense layer with 512 units and a ReLU activation function is added to the model. This layer learns higher-level features from the global average pooled features.
  • A Dropout layer with a rate of 0.5 is added to the model. This layer randomly drops out neurons during training to prevent overfitting.
  • A Dense layer with 256 units and a ReLU activation function is added to the model. This layer learns even higher-level features from the dropout layer.
  • A Dropout layer with a rate of 0.5 is added to the model. This layer randomly drops out neurons during training to prevent overfitting.
  • A Dense layer with num_classes units and a softmax activation function is added to the model. This layer outputs the probability distribution over the num_classes output classes.
  • The model is created by passing the inputs and outputs to the Model class.
  • This model is likely to achieve good performance on a variety of image classification tasks. However, it is important to note that the ResNet50 pre-trained weights were trained on a dataset that contains a wide variety of images. If your dataset is very different from the dataset that the ResNet50 model was trained on, then you may want to consider fine-tuning the model on your own dataset.
  • To fine-tune the model, you would simply need to set the trainable attribute of the resnet_50 model to True and train the model as usual. This will allow the model to learn new weights that are specific to your dataset.

Technologies used

Python scikit-learn NumPy Pandas

Tools used

PyCharm Git GitHub

forest-fire-classification's People

Contributors

nimradev064 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.