Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
AI-Powered Real-Time License Plate Recognition
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2023-281
AI-Powered Real-Time License Plate Recognition
Commits
28fdd4a2
Commit
28fdd4a2
authored
Sep 06, 2023
by
Prasad Dananjaya Wilagama
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add app.py to the repo
parent
2b0e9400
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
app.py
app.py
+62
-0
No files found.
app.py
0 → 100644
View file @
28fdd4a2
import
streamlit
as
st
from
keras.models
import
load_model
from
PIL
import
Image
import
numpy
as
np
import
io
import
matplotlib.pyplot
as
plt
# Load the model
loaded_model
=
load_model
(
'advanced_car_classification_model_md.h5'
,
compile
=
False
)
# Define car classes
car_classes
=
[
"alto_modified"
,
"civic_modified"
,
"wagonr_modified"
]
# Create file uploader widget
st
.
title
(
"Advanced Modified Car Classification"
)
st
.
write
(
"Upload an image and let the model predict the car class."
)
uploader
=
st
.
file_uploader
(
label
=
"Upload an image"
,
type
=
[
"jpg"
,
"jpeg"
,
"png"
],
accept_multiple_files
=
False
)
# Define prediction function
def
predict_car
(
image_data
):
img
=
Image
.
open
(
image_data
)
img
=
img
.
resize
((
150
,
150
))
# Resize to 150x150
img_array
=
np
.
array
(
img
)
/
255.0
img_array
=
np
.
expand_dims
(
img_array
,
axis
=
0
)
predictions
=
loaded_model
.
predict
(
img_array
)[
0
]
predicted_class_index
=
np
.
argmax
(
predictions
)
predicted_car_class
=
car_classes
[
predicted_class_index
]
return
predicted_car_class
,
predictions
# Display uploaded image and prediction
if
uploader
:
st
.
subheader
(
"Uploaded Image"
)
uploaded_image
=
uploader
.
read
()
st
.
image
(
uploaded_image
,
caption
=
'Uploaded Image'
,
use_column_width
=
True
)
predicted_car
,
prediction_probs
=
predict_car
(
io
.
BytesIO
(
uploaded_image
))
st
.
subheader
(
"Prediction"
)
st
.
write
(
f
"Predicted Car: {predicted_car}"
)
st
.
subheader
(
"Prediction Probabilities"
)
col1
,
col2
=
st
.
columns
(
2
)
with
col1
:
st
.
write
(
"Alto Modified"
)
st
.
write
(
"Civic Modified"
)
with
col2
:
st
.
write
(
f
"{prediction_probs[0]:.2
%
}"
)
st
.
write
(
f
"{prediction_probs[1]:.2
%
}"
)
st
.
subheader
(
"Prediction Probability Chart"
)
# Create a simple pie chart using Matplotlib
fig
,
ax
=
plt
.
subplots
()
ax
.
pie
(
prediction_probs
,
labels
=
car_classes
,
autopct
=
'
%1.1
f
%%
'
,
startangle
=
90
)
ax
.
axis
(
'equal'
)
# Equal aspect ratio ensures the pie chart is circular.
st
.
pyplot
(
fig
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment