Skip to content

Commit

Permalink
Merge branch 'abhisheks008:main' into enhance_bangle_defect
Browse files Browse the repository at this point in the history
  • Loading branch information
Arihant-Bhandari authored May 27, 2024
2 parents 3a4795f + 51481de commit cd434eb
Show file tree
Hide file tree
Showing 464 changed files with 82,801 additions and 155 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/auto-comment-on-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Auto Comment on Issue

on:
issues:
types: [opened]

permissions:
issues: write

jobs:
comment:
runs-on: ubuntu-latest

steps:
- name: Add Comment to Issue
run: |
COMMENT=$(cat <<EOF
{
"body": "Thank you for creating this issue! We'll look into it as soon as possible. Your contributions are highly appreciated! 😊"
}
EOF
)
RESPONSE=$(curl -s -o response.json -w "%{http_code}" \
-X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments \
-d "$COMMENT")
cat response.json
if [ "$RESPONSE" -ne 201 ]; then
echo "Failed to add comment"
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions .github/workflows/autocomment-iss-close.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Comment on Issue Close

on:
issues:
types: [closed]

jobs:
greet-on-close:
runs-on: ubuntu-latest
permissions:
issues: write

steps:
- name: Greet User
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = context.payload.issue;
const issueCreator = issue.user.login;
const issueNumber = issue.number;
const sender = context.payload.sender.login;
const assignee = context.payload.issue.assignee.login;
// Define maintainers as a list of usernames who should not trigger this action
const maintainers = ['maintainer1', 'maintainer2']; // Replace with actual maintainer usernames
// Check if the issue was closed by a maintainer
if (!maintainers.includes(sender)) {
const greetingMessage = `Hello @${assignee}! Your issue #${issueNumber} has been closed. Thank you for your contribution!`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
});
}
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 not shown.
91 changes: 91 additions & 0 deletions Anti Spoofing Project using DL/WebApp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# **🔴 Project Title: Anti-Spoofing Project**

# **🔴 Goal:**
The main goal of this project is to create a deep learning model that can accurately identify real images from various types of spoofed images, including replays and cut-outs. The purpose is to develop an effective anti-spoofing system for enhanced security.

# **🔴 Dataset:**
The dataset used for this project can be found at: [Dataset Link](https://www.kaggle.com/datasets/tapakah68/anti-spoofing). It contains a collection of real and spoofed images, which will be used for training and evaluation.

# **🔴 Description:**
This project focuses on implementing a deep learning model for anti-spoofing. The goal is to accurately differentiate between images of different kind such as real image, replay, prinout, layout and cut out. to enhance security measures. Various algorithms and models will be explored to achieve the desired results.

# **🔴 Visualization:**

![Anti-spoof img3](https://github.com/PABITRA34/pk/assets/98800533/d7ed9d83-3975-4751-977e-2fa790387f02)
![Anti-spoof img 4](https://github.com/PABITRA34/pk/assets/98800533/5dcdedf3-a71f-49f9-abd3-61a9b3295e7d)

https://github.com/PABITRA34/pk/assets/98800533/a7de0693-70a4-477a-be71-a6108519be34

# **🔴 What I Have Done:**
To develop the anti-spoofing Web App, the following steps were followed:

1. Setting Up the Environment
- Backend (Flask) :
Install Flask and dependencies: Use pip or pipenv to install Flask and any other necessary Python libraries (e.g., OpenCV, TensorFlow).

2. Loading and Preparing the Model
- Load the pre-trained model: Use TensorFlow/Keras to load the trained anti-spoofing model.
- Define helper functions: Create functions to process input images/videos and make predictions using the model.

3. Developing the Backend
-Flask Routes
- Upload route: Serve the main HTML page.
- Process route: Handle file uploads from the user (images or videos).
- Prediction route: Process the uploaded files, run them through the model, and return the results.

4. Building the Frontend
- HTML Templates
- Main Page: Include a form for uploading images/videos and a section to display results.
-Result Display: Use placeholders in the HTML to dynamically show the prediction results.
- CSS Styling :
Styling Elements: Style buttons, forms, and results display for better user experience.

5. Integrating Backend and Frontend
Form Handling: Ensure the form in the HTML template correctly posts data to the Flask backend.

6. Testing
Local Testing: Run the Flask app locally to test all functionalities and ensure the model predictions are correct.
Debugging: Checked for and fixed arising issues or bugs.

# **🔴 Models Used:**
The following models were used in this project:

1. Convolutional Neural Network (CNN):
- Used for image classification tasks.
- Provides a baseline for comparison.

2. Recurrent Neural Network (RNN):
- Used for sequence-based analysis.
- Explored for its potential in anti-spoofing tasks.

3. Siamese Neural Network:
- Chosen over CNN and RNN models.
- Specifically designed for image similarity and one-shot learning tasks.
- Capable of accurately measuring similarity between images.
- Well-suited for detecting and classifying between images.

The Siamese model was selected for its unique architecture and its ability to accurately compare and measure similarity between images, making it a suitable choice for the anti-spoofing task.

# **🔴 Libraries Needed:**
The following libraries are required for this project:
- TensorFlow
- Flask
- Keras
- OpenCV
- NumPy
- Matplotlib
-Werkzeug.utils
-Scikit-learn
- Pandas
-Os

# **🔴 Conclusion:**
In conclusion, the Siamese model outperformed the CNN and RNN models in terms of accuracy for the anti-spoofing task. Its unique architecture, specifically designed for image similarity and one-shot learning, proved to be effective in accurately differentiating between different types of images. The Siamese model provides a robust solution for enhancing security measures against various types of image-based spoofing attacks.

# **Author:**

Pabitra Kumar Bera

GitHub: https://github.com/PABITRA34

LinkedIn: https://www.linkedin.com/in/pabitra34/
Binary file not shown.
Binary file not shown.
95 changes: 95 additions & 0 deletions Anti Spoofing Project using DL/WebApp/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from flask import Flask, render_template, request, redirect, url_for
from werkzeug.utils import secure_filename
import os
import cv2
import numpy as np
from tensorflow.keras.models import load_model

app = Flask(__name__)

# Define the folder to store uploaded videos
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
UPLOAD_FOLDER = os.path.join(BASE_DIR, 'Uploads')
if not os.path.exists(UPLOAD_FOLDER):
os.makedirs(UPLOAD_FOLDER)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

# Load the Siamese model in .h5 format
model_path = os.path.join(BASE_DIR, 'model.h5')
print("Loading model from:", model_path)
try:
siamese_model = load_model(model_path)

except Exception as e:
siamese_model = None

# Function to preprocess a video frame
def preprocess_frame(frame):
frame = cv2.resize(frame, (224, 224))
frame = frame / 255.0 # Normalize pixel values to the range [0, 1]
frame = np.expand_dims(frame, axis=0) # Add batch dimension
return frame


def predict_class(frame1, frame2):
if siamese_model is None:
return "spoof"

pred = siamese_model.predict([frame1, frame2])
pred_class = np.argmax(pred)

if pred_class == 0:
return "Genuine"
else:
return "Spoof"

# Route to upload a video file
@app.route('/upload', methods=['POST'])
def upload_file():
if 'file' not in request.files:
return render_template('index.html', error='No file part')

file = request.files['file']
if file.filename == '':
return render_template('index.html', error='No selected file')

filename = secure_filename(file.filename)
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
try:
file.save(file_path)
return redirect(url_for('process_video', file_path=file_path))
except Exception as e:
return render_template('index.html', error=str(e))

# Route to process and classify the uploaded video
@app.route('/process', methods=['GET'])
def process_video():
print("Video processing started")
file_path = request.args.get('file_path')
if not file_path or not os.path.exists(file_path):
print("File path error:", file_path)
return render_template('index.html', error='Invalid file path')

cap = cv2.VideoCapture(file_path)
if not cap.isOpened():
return render_template('index.html', error='Error loading video')

ret1, frame1 = cap.read()
ret2, frame2 = cap.read()
if not ret1 or not ret2:
cap.release()
return render_template('index.html', error='Error reading video frames')

frame1 = preprocess_frame(frame1)
frame2 = preprocess_frame(frame2)

predicted_label = predict_class(frame1, frame2)
cap.release()
return render_template('process.html', message='Video processed successfully', predicted_label=predicted_label)

@app.route('/')
def index():
return render_template('index.html')

if __name__ == '__main__':
app.run(debug=True)
Binary file added Anti Spoofing Project using DL/WebApp/model.h5
Binary file not shown.
50 changes: 50 additions & 0 deletions Anti Spoofing Project using DL/WebApp/static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Styles for the body */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
}

/* Styles for the h1 */
h1 {
text-align: center;
margin-top: 50px;
color: #333;
}

/* Styles for the form */
form {
width: 50%;
margin: 0 auto;
text-align: center;
}

/* Styles for the input[type="file"] */
input[type="file"] {
display: block;
margin: 0 auto;
margin-top: 20px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
}

/* Styles for the submit button */
input[type="submit"] {
display: block;
margin: 0 auto;
margin-top: 20px;
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
}

/* Styles for the submit button hover state */
input[type="submit"]:hover {
background-color: #0056b3;
}
40 changes: 40 additions & 0 deletions Anti Spoofing Project using DL/WebApp/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Video Upload</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body {
background-image: url('https://www.pymnts.com/wp-content/uploads/2019/12/Biometric-Authentication-Digital-ID-Spoofing.jpg');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100vh;
}
</style>
</head>
<body>
<h1 style="background-color: aqua ; text-align: center;"> Welcome To Anti-Spoofing System</h1>
<div class="container mt-5">
<div class="card">
<div class="card-body">
<h3 class="card-title"> Please Upload a Video</h3>
{% if error %}
<div class="alert alert-danger" role="alert">
{{ error }}
</div>
{% endif %}
<form action="/upload" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="file">Choose file</label>
<input type="file" class="form-control" id="file" name="file">
</div>
<button type="submit" class="btn btn-primary">Upload and Detect</button>
</form>
</div>
</div>
</div>
</body>
</html>
43 changes: 43 additions & 0 deletions Anti Spoofing Project using DL/WebApp/templates/process.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Process Status</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" />
<style>
body {
background-image: url('https://blog.dormakaba.com/tachyon/2020/04/Blog_In-Post-pictures_022.jpg?fit=1024,1024');
background-size: cover;
background-repeat: no-repeat;
background-position: center;
height: 100vh;
}
</style>
</head>
<body>
<h1 style="background-color: aqua ; text-align: center;">Result of Spoof Detection</h1>

<div class="container mt-5">
<div class="card">
<div class="card-body">
{% if message %}
<div class="alert alert-success" role="alert">
{{ message }}
</div>
{% endif %}
{% if predicted_label %}
<div class="alert alert-info" role="alert">
Predicted label: {{ predicted_label }}
</div>
{% elif error %}
<div class="alert alert-danger" role="alert">
{{ error }}
</div>
{% endif %}
<a href="/" class="btn btn-primary mt-3">Go Back</a>
</div>
</div>
</div>
</body>
</html>
Loading

0 comments on commit cd434eb

Please sign in to comment.