Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Facial expression detection
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Automatants
Facial expression detection
Commits
0a66de78
Commit
0a66de78
authored
4 years ago
by
Timothé Boulet
Browse files
Options
Downloads
Patches
Plain Diff
add utils.py file
parent
820db5ec
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
loadFer2013ds.py
+10
-5
10 additions, 5 deletions
loadFer2013ds.py
utils.py
+24
-0
24 additions, 0 deletions
utils.py
with
34 additions
and
5 deletions
loadFer2013ds.py
+
10
−
5
View file @
0a66de78
...
@@ -4,15 +4,18 @@ import numpy as np
...
@@ -4,15 +4,18 @@ import numpy as np
import
cv2
import
cv2
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
maxNbrImages
=
484845
nbrImages
=
35887
maxNbrImages
=
nbrImages
emotions
=
[
"
Angry
"
,
"
Disgust
"
,
"
Fear
"
,
"
Happy
"
,
"
Sad
"
,
"
Suprise
"
,
"
Neutral
"
]
emotions
=
[
"
Angry
"
,
"
Disgust
"
,
"
Fear
"
,
"
Happy
"
,
"
Sad
"
,
"
Suprise
"
,
"
Neutral
"
]
def
traitement
(
a
,
b
,
c
):
#For testing
def
traitement
(
a
,
b
,
c
):
#For testing
arr
=
strToArray
(
b
)
print
(
a
)
plt
.
imshow
(
arr
)
plt
.
show
()
pass
pass
# arr = strToArray(b)
# print(a)
# plt.imshow(arr)
# plt.show()
# pass
def
strToArray
(
string
):
#Fer2013 provides images as string so it needs to be transformed
def
strToArray
(
string
):
#Fer2013 provides images as string so it needs to be transformed
A
=
[]
A
=
[]
...
@@ -61,5 +64,7 @@ with open(filename,'r',encoding='utf-8') as file:
...
@@ -61,5 +64,7 @@ with open(filename,'r',encoding='utf-8') as file:
X
.
append
(
strToArray
(
stringImage
))
X
.
append
(
strToArray
(
stringImage
))
Y
.
append
(
emotionNbr
)
Y
.
append
(
emotionNbr
)
print
(
f
"
Image
{
i
}
sur
{
nbrImages
}
chargée
"
,
end
=
'
\r
'
)
X
=
np
.
array
(
X
)
X
=
np
.
array
(
X
)
Y
=
np
.
array
(
Y
)
Y
=
np
.
array
(
Y
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
utils.py
0 → 100644
+
24
−
0
View file @
0a66de78
def
afficher
(
image
):
if
len
(
image
.
shape
)
==
3
:
if
image
.
shape
[
2
]
==
3
:
# (h,l,3)
plt
.
imshow
(
image
)
elif
image
.
shape
[
2
]
==
1
:
# (h,l,1)->(h,l)
image2
=
image
plt
.
imshow
(
tf
.
squeeze
(
image
))
elif
len
(
image
.
shape
)
==
2
:
# (h,l)
plt
.
imshow
(
image
)
def
predir
():
pass
def
normAndResize
(
image
):
#For an array image of shape (a,b,c) or (a,b), transform it into (h,l,p). Also normalize it.
image
=
cv2
.
resize
(
image
,
dsize
=
(
h
,
l
),
interpolation
=
cv2
.
INTER_CUBIC
)
#resize for h and l #
if
len
(
image
.
shape
)
==
3
and
p
==
1
and
image
.
shape
[
2
]
!=
1
:
#if we want (h,l,3) -> (h,l,1) , we first transform it in to (h,l) (grey the image)
image
=
image
.
mean
(
2
)
image
=
np
.
reshape
(
image
,
(
h
,
l
,
p
))
#restore third dimension
image
=
image
.
astype
(
"
float32
"
)
image
=
image
/
255
#normalisation
return
image
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment