Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Team SneakyTurtle Submission #32

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9cf09dd
Update README.md
adityarags Jun 8, 2023
dcdda4b
Update README.md
adityarags Jun 8, 2023
9dec908
Deployment: Static Image Output
adityarags Jun 8, 2023
a484c52
Added Requirements.txt
adityarags Jun 8, 2023
5a96778
README: Instructions Updated
adityarags Jun 8, 2023
8f8e924
Update README.md
adityarags Jun 8, 2023
4ab958f
Update README.md
adityarags Jun 8, 2023
ff4ba79
Update README.md
adityarags Jun 9, 2023
b3bf1da
Update README.md
adityarags Jun 9, 2023
c07d4db
Create README.md
adityarags Jun 9, 2023
dd566b7
Add files via upload
adityarags Jun 9, 2023
13dc0e6
Update README.md
adityarags Jun 9, 2023
22f6d99
Update README.md
adityarags Jun 9, 2023
7bf722d
Update README.md
adityarags Jun 9, 2023
125b874
Update README.md
adityarags Jun 9, 2023
4e3dc18
Add files via upload
adityarags Jun 9, 2023
4cb8f7e
Update app.py
adityarags Jun 9, 2023
5ccbd16
Update requirements.txt
adityarags Jun 9, 2023
79505ce
Update index.html
adityarags Jun 9, 2023
e9b3c5e
Update app.py
adityarags Jun 9, 2023
c3144a6
"Deployment: Final Updates"
adityarags Jun 10, 2023
efe0589
Update README.md
adityarags Jul 1, 2023
b23614d
Update README.md
adityarags Jul 1, 2023
70b2494
Update README.md
adityarags Jul 1, 2023
6ae7d2f
Update app.py
adityarags Jul 1, 2023
9681145
Update prediction.py
adityarags Jul 1, 2023
bfe5d7d
Add files via upload
adityarags Jul 1, 2023
5af4579
Add files via upload
adityarags Jul 1, 2023
3c4cf75
Update index.html
adityarags Jul 1, 2023
254611e
Unnecessary File Removed
adityarags Jul 1, 2023
2c3cf21
Update README.md
adityarags Jul 1, 2023
8d485d2
Update README.md
adityarags Jul 1, 2023
91e5185
Update README.md
adityarags Jul 1, 2023
874db94
Update README.md
adityarags Jul 1, 2023
0555eb7
Update README.md
adityarags Jul 1, 2023
87a7f68
Update README.md
adityarags Jul 1, 2023
fc5f1ad
Update README.md
adityarags Jul 1, 2023
5ceba16
Update README.md
adityarags Jul 1, 2023
690476a
Update README.md
adityarags Jul 1, 2023
96ee46e
Update README.md
adityarags Jul 2, 2023
e27e48f
Updated Jupyter Notebooks Added
adityarags Jul 2, 2023
0f298c2
Updated Jupyter Notebooks added
adityarags Jul 2, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
28 changes: 28 additions & 0 deletions Deployment/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from flask import Flask, render_template, request, url_for
from prediction import predict

app = Flask(__name__, template_folder = "templates")


# Controllers
@app.route("/")
def mainPage():
return render_template("index.html", page = "Home")

@app.route("/predict", methods = ["GET", "POST"])
def home():
output = "hold"
if request.method == "POST":
f = request.files['file']
f.save("static/inputImage.jpg")
output = "show"
predict()
return render_template("index.html", output = output, page = "Predict")


@app.route("/team")
def team():
return render_template("index.html", page = "Team")

if __name__ == "__main__":
app.run(debug = True)
68 changes: 68 additions & 0 deletions Deployment/prediction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import cv2
import supervision as sv
import torch
import pytorch_lightning as pl
from transformers import DetrForObjectDetection, DetrImageProcessor
from PIL import Image
import numpy as np
from torchvision.utils import draw_bounding_boxes





DEVICE = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
CHECKPOINT = 'facebook/detr-resnet-50'
CONFIDENCE_TRESHOLD = 0.5
IOU_TRESHOLD = 0.8
image_processor = DetrImageProcessor.from_pretrained(CHECKPOINT, ignore_mismatched_sizes = True )
model = DetrForObjectDetection.from_pretrained(CHECKPOINT, ignore_mismatched_sizes = True)


model.load_state_dict(torch.load("vehicle_det.pth", map_location = DEVICE), strict = False)


categories = {0: {'id': 0, 'name': 'cars', 'supercategory': 'none'},
1: {'id': 1, 'name': 'biker', 'supercategory': 'cars'},
2: {'id': 2, 'name': 'pedestrian', 'supercategory': 'cars'},
3: {'id': 3, 'name': 'car', 'supercategory': 'cars'},
4: {'id': 4, 'name': 'trafficLight', 'supercategory': 'cars'}}

id2label = {k: v['name'] for k,v in categories.items()}
label2id = {v['name']: k for k,v in categories.items()}
box_annotator = sv.BoxAnnotator()



def predict():
image = np.asarray(Image.open("static/inputImage.jpg"))


with torch.no_grad():

# load image and predict
inputs = image_processor(images=image, return_tensors='pt')
outputs = model(**inputs)

# post-process
target_sizes = torch.tensor([image.shape[:2]])
results = image_processor.post_process_object_detection(
outputs=outputs,
threshold=CONFIDENCE_TRESHOLD,
target_sizes=target_sizes
)[0]

# annotate
detections = sv.Detections.from_transformers(transformers_results=results).with_nms(threshold=0.5)
print(detections[0])
labels = [f"{id2label[class_id]} {confidence:.2f}" for _, mask, confidence, class_id, _ in detections if class_id <= 4]
xys = [xyxy for xyxy, mask, confidence, class_id, _ in detections if class_id <= 4]
print(labels)
palette = ["orange", "blue", "green", "pink", "black"]
colors = [palette[label2id[_.split()[0]]] for _ in labels]
for i in range(len(labels)):
print(xys[i][0])
cv2.rectangle(image, (int(xys[i][0]), int(xys[i][1])), (int(xys[i][2]), int(xys[i][3])), (0, 255, 0), 2)
cv2.putText(image, labels[i], (int(xys[i][0]), int(xys[i][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2, cv2.LINE_AA)
# frame = box_annotator.annotate(scene=image.copy(), detections=detections, labels=labels )
cv2.imwrite("static/output.jpg", cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
64 changes: 64 additions & 0 deletions Deployment/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
aiohttp==3.8.4
aiosignal==1.3.1
async-timeout==4.0.2
attrs==23.1.0
blinker==1.6.2
certifi==2023.5.7
charset-normalizer==3.1.0
click==8.1.3
colorama==0.4.6
contourpy==1.0.7
cycler==0.11.0
datasets==2.12.0
dill==0.3.6
filelock==3.12.0
Flask==2.3.2
fonttools==4.39.4
frozenlist==1.3.3
fsspec==2023.5.0
huggingface-hub==0.15.1
idna==3.4
importlib-metadata==6.6.0
importlib-resources==5.12.0
itsdangerous==2.1.2
Jinja2==3.1.2
kiwisolver==1.4.4
lightning-utilities==0.8.0
MarkupSafe==2.1.3
matplotlib==3.7.1
mpmath==1.3.0
multidict==6.0.4
multiprocess==0.70.14
networkx==3.1
numpy==1.24.3
opencv-python==4.7.0.72
packaging==23.1
pandas==2.0.2
Pillow==9.5.0
pyarrow==12.0.0
pyparsing==3.0.9
python-dateutil==2.8.2
pytorch-lightning==2.0.3
pytz==2023.3
PyYAML==6.0
regex==2023.6.3
requests==2.31.0
responses==0.18.0
safetensors==0.3.1
six==1.16.0
supervision==0.9.0
sympy==1.12
timm==0.9.2
tokenizers==0.13.3
torch==2.0.1
torchmetrics==0.11.4
torchvision==0.15.2
tqdm==4.65.0
transformers==4.30.0
typing_extensions==4.6.3
tzdata==2023.3
urllib3==2.0.3
Werkzeug==2.3.5
xxhash==3.2.0
yarl==1.9.2
zipp==3.15.0
Binary file added Deployment/static/Member1.jpg
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 Deployment/static/Member2.jpg
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 Deployment/static/Member3.jpg
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 Deployment/static/banner.jpg
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 Deployment/static/inputImage.jpg
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 Deployment/static/output.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions Deployment/static/styles/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
body {
background-color: #f1f1f1;
}
.ourTeam-hedding p{
color: #979797;
}
.ourTeam-hedding strong{
color: black;
}
.ourTeam-hedding{
margin-bottom: 50px;
}
.ourTeam-hedding h1{
font-size: 25px;
font-weight: bold;
color: #145889;
}
.ourTeam-box{
border-radius: 2px;
border-top: 6px solid #5DDDD3;
margin: 0px;
background-color: #FFFFFF;
margin-bottom: 30px;
}
.section1{
padding: 30px 0px 30px 0px;
}
.section1 img{
border-radius: 50%;
height: 130px;
width: 130px;
}
.section2 p{
font-weight: bold;
color: #5DDDD3;
letter-spacing: 1px;
}
.section2 span{
color: #979597;
}
.section3{
background-color: #5DDDD3;
}
.section3 i{
color: #ffffff !important;
padding: 15px;
font-size: 15px;
}
.section-info{
border-top: 6px solid #90DFAA;
}
.section-info p{
color: #90DFAA;
}
.section-info .section3{
background-color: #90DFAA;
}
.section-danger{
border-top: 6px solid #FD8469;
}
.section-danger p{
color: #FD8469;
}
.section-danger .section3{
background-color: #FD8469;
}


Loading