Giter Club home page Giter Club logo

computer-vision-image-classification_svm's Introduction

๐Ÿ–ผ๏ธ Basic Image Classification for Wood (Defects & Normal) ๐ŸŒณ using SVM Classifier

Here I am providing a basic script for image classification of Defected and Normal woods based on the CT images (jpg) using an SVM classifier. Please note that this script is intended for understanding the process involved in classification, so accuracy may not be optimal. To achieve better accuracy, additional modifications and optimizations may be necessary.

โฌ†๏ธ Importing Libraries:

  • numpy: To perform numerical operations
  • os: Interacts with the operating system for handling file paths.
  • cv2: To perfrom Image processing tasks.
  • pandas: Data Analysis.
  • train_test_split: For splitting the dataset into training, testing and validation sets.
  • StandardScaler: For scaling features.
  • SVC: To use Support Vector Classification.
  • accuracy_score and classification_report: Evaluating the model's performance.
  • matplotlib.pyplot: Data visualization.

Loading โ†ป Data:

  • Define the directory path (dire) and categories of images.
  • Here reading images from the specified directory (location), after this resize the images into a standard size (SIZE), and store them in the images list.
  • After this assigning labels to the loaded images based on their categories and store them in the labels list.

๐Ÿ” Feature Extraction:

  • Define a function feature_extractor to extract features from images. Here we used GLCM (Gray-Level Co-occurrence Matrix).
  • Iterate over each image in the dataset and calculate GLCM properties such as contrast, dissimilarity, homogeneity, and energy.
  • Store the extracted features in a pandas DataFrame (image_dataset).

๐Ÿ›ข Data Splitting:

  • Split the dataset into training and testing sets using train_test_split, with 15% of the data allocated for testing.
  • Further split the training set into training and validation sets using train_test_split, with 10% of the training data allocated for validation.

โš–๏ธ Feature Scaling:

  • Scale the features in the training, validation, and test sets using StandardScaler.

๐ŸŽฏ Model Training:

  • Initialize an SVM classifier (SVC) with a linear kernel and default hyperparameters.
  • Train the SVM classifier on the scaled training data.

๐Ÿ“‹ Model Evaluation:

  • Make predictions on the validation and test data using the trained model.
  • Calculate the accuracy scores for the training, validation, and test sets.
  • Print the training, validation, and test accuracies.
  • Generate a classification report to evaluate precision, recall, and F1-score for each class.

๐Ÿ“Š Visualization:

  • Plot decision boundaries for the validation and test sets to visualize the SVM's classification.

Conclusion:

This script provides a comprehensive workflow, including data loading, preprocessing, model training, evaluation, and visualization, to classify images of woods into defected and normal.

computer-vision-image-classification_svm's People

Contributors

gokultcr 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.