Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP-IA-Syntax-Error
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VIGEOLAS-CHOURY Paul
TP-IA-Syntax-Error
Commits
6b30b339
Commit
6b30b339
authored
4 months ago
by
paul_pvc
Browse files
Options
Downloads
Patches
Plain Diff
push GLCM pas optimisé
parent
f55f2fc6
No related branches found
No related tags found
1 merge request
!1
Gris
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
TP.py
+26
-4
26 additions, 4 deletions
TP.py
TestTP.py
+1
-1
1 addition, 1 deletion
TestTP.py
with
27 additions
and
5 deletions
TP.py
+
26
−
4
View file @
6b30b339
...
...
@@ -31,8 +31,29 @@ def buildSampleFromPath(path1, path2, size=0):
def
computePixelBW_histo
(
image
):
return
Image
.
fromarray
(
np
.
array
(
image
.
convert
(
"
L
"
))).
histogram
()
return
image
.
convert
(
"
L
"
).
histogram
()
def
compute_glcm
(
image
):
img_array
=
np
.
array
(
image
)
distance
,
angle
=
5
,
0
glcm
=
np
.
zeros
((
256
,
256
))
offsets
=
(
int
(
distance
*
np
.
cos
(
angle
)),
int
(
distance
*
np
.
sin
(
angle
)))
for
i
in
range
(
image
.
height
-
abs
(
offsets
[
1
])):
for
j
in
range
(
image
.
width
-
abs
(
offsets
[
0
])):
px1
=
img_array
[
i
,
j
]
px2
=
img_array
[
i
+
offsets
[
1
],
j
+
offsets
[
0
]]
glcm
[
px1
,
px2
]
+=
1
glcm
/=
np
.
sum
(
glcm
)
return
glcm
def
extract_data_glcm
(
glcm
):
contrast
=
np
.
sum
([[(
i
-
j
)
**
2
*
glcm
[
i
,
j
]
for
j
in
range
(
glcm
.
shape
[
1
])]
for
i
in
range
(
glcm
.
shape
[
0
])])
energy
=
np
.
sum
(
glcm
**
2
)
homogeneity
=
np
.
sum
(
[[(
glcm
[
i
,
j
]
/
(
1
+
abs
(
i
-
j
)))
for
j
in
range
(
glcm
.
shape
[
1
])]
for
i
in
range
(
glcm
.
shape
[
0
])])
return
[
contrast
,
energy
,
homogeneity
]
def
computeDict
(
image_path
,
path
,
y_true_value
,
max_size
:
tuple
):
"""
...
...
@@ -56,6 +77,7 @@ def computeDict(image_path, path, y_true_value, max_size: tuple):
#"resized_image": resized,
"
X_histo
"
:
computeHisto
(
resized
),
"
X_pixelbw
"
:
computePixelBW_histo
(
resized
),
"
X_glcm_data
"
:
extract_data_glcm
(
compute_glcm
(
resized
)),
"
y_true_class
"
:
y_true_value
,
"
y_predicted_class
"
:
None
}
...
...
@@ -94,7 +116,7 @@ def fitFromHisto(S, algo):
S_train
,
S_test
,
y_train
,
y_test
=
train_test_split
(
S
,
y
,
test_size
=
0.2
,
random_state
=
42
)
X_train
=
np
.
array
([
np
.
array
(
l
[
"
X_histo
"
]
+
l
[
"
X_
pixelbw
"
])
for
l
in
S_train
])
X_train
=
np
.
array
([
np
.
array
(
l
[
"
X_histo
"
]
+
l
[
"
X_
glcm_data
"
])
for
l
in
S_train
])
#X_train = df[["X_histo", "X_pixelbw"]]
#print(X_train)
#print(len(X_train[0]))
...
...
@@ -113,7 +135,7 @@ def predictFromHisto(S, model, list_dict=True):
:param list_dict: is the sample in list(dict)
:return: None
"""
tab
=
model
.
predict
(
np
.
array
([
x
[
"
X_histo
"
]
+
x
[
"
X_
pixelbw
"
]
for
x
in
S
]))
tab
=
model
.
predict
(
np
.
array
([
x
[
"
X_histo
"
]
+
x
[
"
X_
glcm_data
"
]
for
x
in
S
]))
if
list_dict
:
for
i
in
range
(
len
(
S
)):
S
[
i
][
"
y_predicted_class
"
]
=
tab
[
i
]
...
...
This diff is collapsed.
Click to expand it.
TestTP.py
+
1
−
1
View file @
6b30b339
...
...
@@ -29,7 +29,7 @@ def test_sample():
def
global_test
():
S
=
TP
.
buildSampleFromPath
(
path1_t
,
path2_t
)
classifier
,
S_test
,
y_test
,
S_train
,
y_train
=
TP
.
fitFromHisto
(
S
,
SVC
())
classifier
,
S_test
,
y_test
,
S_train
,
y_train
=
TP
.
fitFromHisto
(
S
,
SVC
(
kernel
=
"
rbf
"
))
TP
.
predictFromHisto
(
S
,
classifier
)
print
(
"
Erreur empirique :
"
,
TP
.
computeError
(
S_train
),
"
erreurs
"
)
print
(
"
Erreur réelle :
"
,
TP
.
computeError
(
S_test
),
"
erreurs
"
)
...
...
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