Skip to content

Commit

Permalink
Merge pull request #668 from tanuj437/main
Browse files Browse the repository at this point in the history
Mineral classification
  • Loading branch information
abhisheks008 authored Jun 23, 2024
2 parents c7ea0d5 + f8f8c68 commit 9448bdc
Show file tree
Hide file tree
Showing 31 changed files with 355 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Mineral Classification/Dataset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Dataset Description
Explore the fascinating world of minerals with our meticulously curated dataset. This dataset captures high-quality images of various minerals, each labeled with its respective class. By analyzing this dataset, you will gain valuable insights into the visual characteristics that distinguish different mineral types, aiding in accurate and efficient mineral classification.

## Key Features
**Diverse Mineral Classes:** Understand the unique visual features of ten distinct mineral types, ranging from common minerals like quartz to precious gems like diamond.

**High-Quality Images:** Each mineral class is represented by high-resolution images, ensuring that intricate details are captured for thorough analysis.

**Balanced Representation:** While some classes have more images than others, the dataset provides a balanced overview of different minerals, facilitating effective training and testing of classification models.

## Data Collection
The images have been carefully labeled based on their mineral type. This structured approach ensures that each image is correctly categorized, providing a reliable dataset for training machine learning models.
Can Download the dataset from visit the [Kaggle page](https://www.kaggle.com/datasets/spadini/mineral-classification).

About This File
This dataset contains images organized into ten subfolders, each representing a different mineral class. The total number of images and classes are as follows:

Total Classes: 10
* apatite: 5 images
* calcite: 8 images
* corundum: 2 images
* diamond: 3 images
* fluorite: 12 images
* gypsum: 7 images
* orthoclase: 3 images
* quartz: 11 images
* talc: 5 images
* topaz: 6 images
Sample Images
Here are a few sample images from the dataset:

Apatite:
![img2](https://github.com/tanuj437/Mineral-Classification/assets/128210429/6a443a5f-6c36-4ff4-9b1d-d7a47a1e0582)


Diamond:
![img2](https://github.com/tanuj437/Mineral-Classification/assets/128210429/2b97d485-8e42-495b-8638-b086735d288d)

For more details and to access the dataset, please visit the relevant directory within this project.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Mineral Classification/Dataset/img/talc/img1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions Mineral Classification/Model/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Mineral Classification - Model
## 📝 Description
This folder contains the pre-trained machine learning models and scripts used for classifying mineral images. The aim is to automatically categorize images into their respective mineral classes, enhancing our understanding and identification of various minerals.

## 📂 Contents
**Mineral_Classification_Model_Training.ipynb:** Jupyter Notebook containing the complete process of data preprocessing, model training, evaluation, and visualization.
**README.md:** This document.
**mineral_classification_model.pkl:** Pre-trained Logistic Regression model used for mineral classification.
## 🎯 Goal
The goal of this mineral classification project is to accurately identify mineral types from images using various machine learning models. By automatically classifying these images, the project aims to aid researchers and enthusiasts in mineral identification and analysis.

## 🧮 What I Did
In this mineral classification project, various models were evaluated to find the most effective one for classifying mineral images. The models evaluated include:

## Models Used
**Random Forest**
A robust ensemble learning method that combines multiple decision trees to improve classification accuracy.

**Support Vector Machine (SVM)**
A powerful classifier that finds the optimal hyperplane for separating different classes in the feature space.

**K-Nearest Neighbors (KNN)**
A simple, instance-based learning algorithm that classifies a sample based on the majority class among its k-nearest neighbors.

**Convolutional Neural Network (CNN)**
A deep learning model particularly effective for image classification tasks due to its ability to capture spatial hierarchies.

**Logistic Regression**
A statistical model that uses a logistic function to model binary dependent variables, extended here for multi-class classification.

**Decision Tree**
A model that splits the data into subsets based on feature values, creating a tree-like structure for classification.

**Extra Trees**
An ensemble learning method similar to Random Forest, but with more randomness injected into the tree construction process.
## Data Preprocessing and Augmentation

**Image Resizing and Normalization:** Images were resized to 224x224 pixels and normalized to ensure consistency.

**Feature Engineering:** Flattened images and applied standard scaling.

**Data Splitting:** Divided data into training, validation, and test sets for robust model evaluation.
## 🚀 Models Implemented
**Random Forest**
Performance: Achieved 100% accuracy due to the small dataset size.

**Support Vector Machine (SVM)**
Performance: Achieved 100% accuracy.

**K-Nearest Neighbors (KNN)**
Performance: Achieved 100% accuracy.

**Convolutional Neural Network (CNN)**
Performance: Achieved 100% accuracy.

**Logistic Regression**
Performance: Achieved 100% accuracy.

**Decision Tree**
Performance: Achieved 100% accuracy.

**Extra Trees**
Performance: Achieved 100% accuracy.
## 📈 Performance of the Models
All models achieved 100% accuracy, indicating that the dataset is relatively small and potentially not very complex, allowing all models to perfectly classify the images.

## 📢 Conclusion
The mineral classification project demonstrates that various machine learning models can accurately classify mineral images with high accuracy. The models help in automating the process of mineral identification, providing valuable assistance to researchers and enthusiasts.

## ✒️ Connect with Me
Tanuj Saxena [LinkedIn](https://www.linkedin.com/in/tanuj-saxena-970271252/)
1 change: 1 addition & 0 deletions Mineral Classification/Model/mineral-classification.ipynb

Large diffs are not rendered by default.

Binary file not shown.
94 changes: 94 additions & 0 deletions Mineral Classification/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Mineral-Classification
Explore the classification of minerals using machine learning techniques, analyzing images to identify and categorize different mineral types. Gain insights into the diversity of minerals and their visual characteristics through image data analysis.
<img width="926" alt="webapp" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/de679733-b0e8-4383-8b22-93d918e842ee">


## 📝 Abstract
Mineral Classification involves using machine learning models to automatically classify images of minerals into specific categories. Techniques like convolutional neural networks (CNNs) are employed to extract features from mineral images, enabling accurate classification based on visual attributes.

## 🔍 Methodology
**Importing Libraries**
-Libraries such as NumPy, Pandas, Sklearn, Transformers, and others are imported for data manipulation, visualization, and machine learning model building.

**Loading the Dataset**
-The dataset consists of images of various minerals categorized into different classes based on their types.

**Data Preprocessing**
-Data preprocessing involves tasks such as resizing images, normalizing pixel values, and augmenting data to enhance model performance and robustness.

**Training the Models**
-Multiple models are trained, including CNNs, Random Forest, SVM, KNN, Logistic Regression, Decision Tree, and Extra Tree classifiers, to classify mineral images.

**Model Performance Analysis**
-Performance metrics such as accuracy, precision, and recall are computed to evaluate and compare the effectiveness of each model.

**Model Prediction**
-The trained models are used to predict the types of minerals in unseen images, showcasing their classification capabilities.

**Deploy**
-Streamlit is utilized to deploy a web application for real-time mineral classification, enabling users to upload images and receive instant classification results.

**Data and Model File Download**
-The dataset used for training and the pre-trained models are available for download and further exploration.. [Kaggle Dataset Link](https://www.kaggle.com/datasets/spadini/mineral-classification)

### Project Directory Structure
```
BRICS Sentiment Analysis
|- Dataset
|- img
|- apatite/
|- calcite/
|- corundum/
|- diamond/
|- fluorite/
|- gypsum/
|- orthoclase/
|- quartz/
|- talc/
|- topaz/
|- README.md
|- Model
|- mineral_classification.ipynb
|- README.md
|- mineral_classification_model.pkl
|- Web App
|- app.py
|- README.md
|- Images
|- CNN_conf.png
|- README.md
|- Decision_tree_conf.png
|- SVM_conf.png
|- classifying_minerals.mp4
|- comparision.png
|- extra_tree_classification_conf.png
|- logistic_regression.png
|- minerals.png
|- prediction.png
|- random_forest_conf.png
|- webapp.png
|- requirements.txt
|-README.md
```

## How to Use
**Requirements**
-Ensure you have the necessary libraries and dependencies installed. You can find the list of required packages in the requirements.txt file.

**Download Data**
-Download the img dataset from Kaggle mentioned in the dataset section of the project.

**Run the Jupyter Notebook**
-Open the provided Jupyter Notebook file and run each cell sequentially. Make sure to update any file paths or configurations as needed for your environment.

**Training and Evaluation**
-Train the models using the provided data and evaluate their performance using metrics such as accuracy and loss.

**Interpret Results**
-Analyze the model's performance using the visualizations and metrics provided in the notebook.

Feel free to reach out if you encounter any issues or need further assistance with running the notebook.

## Connect with Me
Tanuj Saxena [LinkedIn](https://www.linkedin.com/in/tanuj-saxena-970271252/)
45 changes: 45 additions & 0 deletions Mineral Classification/Webapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

# Mineral Classification Web App

## Goal 🎯
This project focuses on classifying mineral images into distinct categories using machine learning models. The goal is to automatically identify different types of minerals based on their visual characteristics captured in images.

## Model(s) Used for the Web App 🧮
The model used in this web app is a pre-trained Logistic Regression, which has been fine-tuned for mineral classification.

## Video Demonstration

https://github.com/tanuj437/ML-Crate/assets/128210429/465d9f47-a531-4ad9-8de7-d795c338e2d2


## Photo Demonstration

<img width="926" alt="webapp" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/b98cc82c-5a5f-453f-862d-8bd7ddd6f9bc">

<img width="923" alt="prediction" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/dedc0fd9-b1d1-4637-a0dd-afc756428824">


## How to Run the Web App

### Requirements
Ensure you have the necessary libraries and dependencies installed. You can find the list of required packages in the `requirements.txt` file.

### Installation
1. **Clone the repository:**
```bash
gh repo clone tanuj437/Mineral-Classification
cd Mineral-Classification<img width="926" alt="webapp" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/2eec0b1a-9f9f-44de-a5ac-cbedf38f5c52">

```
2. **Install the Dependencies**
```bash
pip install -r requirements.txt
```
3. **Run the Streamlit app**
```bash
streamlit run app.py
```
### Signature ✒️
Tanuj Saxena

[![LinkedIn](https://img.shields.io/badge/LinkedIn-%230077B5.svg?logo=linkedin&logoColor=white)](https://www.linkedin.com/in/tanuj-saxena-970271252/)
52 changes: 52 additions & 0 deletions Mineral Classification/Webapp/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import streamlit as st
import numpy as np
import pickle
from sklearn.preprocessing import StandardScaler
from PIL import Image
from pathlib import Path

# Define the paths
MODEL_PATH ='Webapp/mineral_classification_model.pkl'
IMAGE_PATH = Path("Dataset/img")
if not IMAGE_PATH.exists():
st.error(f"Image directory does not exist: {IMAGE_PATH}")

# Load class names dynamically
class_names = sorted([d.name for d in IMAGE_PATH.iterdir() if d.is_dir()])

# Load the trained model
with open(MODEL_PATH, 'rb') as file:
lr_model = pickle.load(file)

# Define the image transformations
def preprocess_image(image):
image = image.resize((224, 224)).convert('RGB')
image_array = np.array(image)
image_array = image_array / 255.0
return image_array.reshape(1, -1)

# Streamlit app
st.title('Mineral Classification Web App')

st.write("""
Upload an image of a mineral and the model will predict its class.
""")

# Image uploader
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "png"])

if uploaded_file is not None:
image = Image.open(uploaded_file)
st.image(image, caption='Uploaded Image', use_column_width=True)
st.write("")
st.write("Classifying...")

# Preprocess the image
image_array = preprocess_image(image)

# Make prediction
prediction = lr_model.predict(image_array)
predicted_class = class_names[prediction[0]]

# Display the result
st.write(f"Predicted Class: {predicted_class}")
Binary file added Mineral Classification/images/CNN_conf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Mineral Classification/images/KNN_conf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions Mineral Classification/images/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Images Folder
The images folder contains various visualizations generated during the exploratory data analysis (EDA) and model evaluation phases of the mineral classification project. These visualizations provide valuable insights into the dataset and the performance of the classification models. Below is a detailed description of the contents:

**1. Label Distribution**
Label Distribution
This graph illustrates the distribution of mineral labels in the dataset. It provides insights into the balance of the dataset and whether there are any imbalances that need to be addressed during model training.

**2. Sample Images**
Sample Mineral Images
A selection of images from each mineral class to give an overview of the dataset's content and variety.
<img width="499" alt="mineral_classification" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/4f5c4774-cde2-4eec-992f-91d20ca9cee4">
<img width="492" alt="mineral_classification_2" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/9d76658e-d7d5-494d-bf6e-d81973c77681">
<img width="497" alt="mineral_classification_3" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/516badce-b6a5-4e23-bca7-c751106a5a3a">


**3. Model Performance**
**Confusion Matrix**
This matrix shows the performance of the model by illustrating the number of correct and incorrect classifications for each mineral type.
<img width="423" alt="Decision_tree_conf" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/e25ca30d-b495-4b24-b9a3-7df47f6bbf2e">
<img width="422" alt="logistic_regression_conf" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/b788dc9e-3e08-479f-8904-4f79ec6c0648">
<img width="422" alt="KNN_conf" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/7c147f20-c82d-43af-be1a-9c6dfe00a825">
<img width="422" alt="SVM_conf" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/78350003-c438-4071-9f15-0223cdc74e18">
<img width="422" alt="random_forest_conf" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/d1d0bdaf-3825-4113-ab45-22340bf1e8d5">
<img width="420" alt="extra_tree_classification_conf" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/8081e0f7-9575-4a6b-9d26-0313ba29ed87">
<img width="452" alt="CNN_conf" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/b26bc253-1edf-4e61-8ba0-40d7395946e9">

**Accuracy and Loss Plots**
Plots showing the training and validation accuracy and loss over epochs to visualize the model's learning progress and performance.
<img width="675" alt="comparision" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/707f4d76-9337-4e6e-9cf3-10c54b44da36">


**4. Feature Importance**
**Feature Importance**
A visualization highlighting the most important features (if applicable) used by the model to make classification decisions.


**5. Data Augmentation Examples**
**Data Augmentation**
<img width="158" alt="Screenshot 2024-06-18 210706" src="https://github.com/tanuj437/Mineral-Classification/assets/128210429/718ad481-876f-4141-acf9-ae19d4d60233">

Examples of augmented mineral images used to increase the dataset size and variability for better model training.

📢 Conclusion
These visualizations provide an in-depth look at the dataset and the performance of the various machine learning models used for mineral classification. They help in understanding the strengths and areas for improvement in the models, guiding further enhancements.
Binary file added Mineral Classification/images/SVM_conf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added Mineral Classification/images/comparision.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Mineral Classification/images/minerals.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Mineral Classification/images/prediction.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Mineral Classification/images/webapp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions Mineral Classification/requirement.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
numpy==1.21.2
scikit-learn==0.24.2
torch==1.9.0
torchvision==0.10.0
Pillow==8.3.1
opencv-python==4.5.3.56
matplotlib==3.4.3
streamlit==0.86.0
pandas==1.3.3

0 comments on commit 9448bdc

Please sign in to comment.