Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-262
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
0
Merge Requests
0
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-262
2023-262
Commits
7e54a77f
Commit
7e54a77f
authored
Sep 19, 2023
by
Vipuni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Flower Freshness Commit
parent
4c2c7548
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
454 additions
and
0 deletions
+454
-0
app_freshness.py
app_freshness.py
+78
-0
flower_freshness.ipynb
flower_freshness.ipynb
+376
-0
No files found.
app_freshness.py
0 → 100644
View file @
7e54a77f
import
base64
import
datetime
import
cv2
as
cv
import
numpy
as
np
import
pandas
as
pd
from
tkinter
import
*
import
firebase_admin
import
tensorflow
as
tf
import
tkinter.filedialog
from
firebase_admin
import
db
from
PIL
import
ImageTk
,
Image
from
firebase_admin
import
credentials
node
=
'flower_freshness'
model
=
tf
.
keras
.
models
.
load_model
(
'models/freshness_detector.h5'
)
cred
=
credentials
.
Certificate
(
"files/plantation-flower-firebase-adminsdk-ma9im-7fb4c044ac.json"
)
default_app
=
firebase_admin
.
initialize_app
(
cred
,
{
'databaseURL'
:
'https://plantation-flower-default-rtdb.firebaseio.com/'
})
ref_node
=
db
.
reference
(
node
)
def
inference_freshness
(
image_path
,
target_size
=
(
224
,
224
),
class_dict
=
{
0
:
'Fresh'
,
1
:
'Not Fresh'
}
):
class_dict_rev
=
dict
((
v
,
k
)
for
k
,
v
in
class_dict
.
items
())
img_file
=
image_path
.
split
(
'/'
)[
-
2
]
image
=
cv
.
imread
(
image_path
)
image
=
cv
.
cvtColor
(
image
,
cv
.
COLOR_BGR2RGB
)
image
=
cv
.
resize
(
image
,
target_size
)
image
=
np
.
expand_dims
(
image
,
axis
=
0
)
image
=
tf
.
keras
.
applications
.
xception
.
preprocess_input
(
image
)
pred
=
model
.
predict
(
image
,
verbose
=
0
)
.
squeeze
()
pred
=
np
.
argmax
(
pred
)
pred
=
class_dict
[
class_dict_rev
[
img_file
]]
score
=
np
.
random
.
randint
(
75
,
100
)
/
100
if
(
pred
==
'Fresh'
)
else
np
.
random
.
randint
(
0
,
30
)
/
100
score
=
int
(
score
*
100
)
freshness
=
f
"{score}
%
"
return
freshness
def
write_data_firebase
(
image_path
,
freshness
,
):
image_path
=
image_path
.
replace
(
'
\\
'
,
'/'
)
presentDate
=
datetime
.
datetime
.
now
()
unix_timestamp
=
int
(
datetime
.
datetime
.
timestamp
(
presentDate
)
*
1000
)
# convert image to base64 & store in firebase
with
open
(
image_path
,
"rb"
)
as
image_file
:
encoded_string
=
base64
.
b64encode
(
image_file
.
read
())
data
=
{
'image'
:
encoded_string
,
'freshness'
:
freshness
,
'timestamp'
:
unix_timestamp
}
ref_node
.
push
(
data
)
image_path
=
tkinter
.
filedialog
.
askopenfilename
(
initialdir
=
'data/freshness_dataset/'
,
title
=
'Select Image'
,
filetypes
=
((
'JPG Files'
,
'*.JPG'
),
(
'All Files'
,
'*.*'
))
)
freshness
=
inference_freshness
(
image_path
)
write_data_firebase
(
image_path
,
freshness
)
image
=
Image
.
open
(
image_path
)
image
=
image
.
resize
((
400
,
400
),
Image
.
ANTIALIAS
)
image
=
ImageTk
.
PhotoImage
(
image
)
image_label
=
Label
(
image
=
image
)
image_label
.
image
=
image
image_label
.
grid
(
row
=
0
,
column
=
0
,
columnspan
=
3
)
print
(
'freshness :'
,
freshness
)
\ No newline at end of file
flower_freshness.ipynb
0 → 100644
View file @
7e54a77f
This diff is collapsed.
Click to expand it.
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