Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Images classification
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Saidi Aya
Images classification
Compare revisions
f98665d7f50f55d75899ce9c854fd1881cdd1b2e to 77a998597680f561ba61027ec6c9e614a7cf0552
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
saidia/image-classification
Select target project
No results found
77a998597680f561ba61027ec6c9e614a7cf0552
Select Git revision
Branches
main
1 result
Swap
Target
saidia/image-classification
Select target project
saidia/image-classification
1 result
f98665d7f50f55d75899ce9c854fd1881cdd1b2e
Select Git revision
Branches
main
1 result
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (4)
Update knn.py
· 06f5ead5
Saidi Aya
authored
2 years ago
06f5ead5
Update mlp.py
· bda06e60
Saidi Aya
authored
2 years ago
bda06e60
Update read_cifar.py
· 9e3f4f8e
Saidi Aya
authored
2 years ago
9e3f4f8e
Create accuracy_knn.png
· 77a99859
Saidi Aya
authored
2 years ago
77a99859
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
knn.py
+5
-1
5 additions, 1 deletion
knn.py
mlp.py
+5
-1
5 additions, 1 deletion
mlp.py
read_cifar.py
+5
-5
5 additions, 5 deletions
read_cifar.py
results/accuracy_knn.png
+0
-0
0 additions, 0 deletions
results/accuracy_knn.png
with
15 additions
and
7 deletions
knn.py
View file @
77a99859
#Libraries
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
math
import
random
from
read_cifar
import
*
#Functions
def
distance_matrix
(
Y
,
X
):
#This function takes as parameters two matrices X and Y
...
...
@@ -26,7 +30,7 @@ def knn_predict(dists, labels_train, k):
def
evaluate_knn
(
data_train
,
labels_train
,
data_test
,
labels_test
,
k
):
#This function evaluates the knn classifier rate
labels_test_
_
pred
=
knn_predict
(
distance_matrix
(
data_train
,
data_test
),
labels_train
,
k
)
labels_test_pred
=
knn_predict
(
distance_matrix
(
data_train
,
data_test
),
labels_train
,
k
)
num_samples
=
data_test
.
shape
[
0
]
num_correct
=
(
labels_test
==
labels_test_pred
).
sum
().
item
()
accuracy
=
100
*
(
num_correct
/
num_samples
)
#The accuracy is the percentage of the correctly predicted classes
...
...
This diff is collapsed.
Click to expand it.
mlp.py
View file @
77a99859
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
math
import
random
from
read_cifar
import
*
#We are using the segmoid activation function
def
segmoid
(
x
):
return
1
/
(
1
+
np
.
exp
(
-
x
))
...
...
@@ -19,7 +23,7 @@ def learn_once_mse(w1,b1,w2,b2,data,targets,learning_rate):
A2
=
segmoid
(
np
.
matmul
(
A1
,
w2
)
+
b2
)
#Let calculate the partial derivates
#2
D_A2
=
2
*
(
A2
-
t
r
agets
)
D_A2
=
2
*
(
A2
-
ta
r
gets
)
D_A2_T
=
np
.
matmul
(
A2
,(
1
-
A2
).
T
)
D_Z2
=
np
.
matmul
(
D_A2_T
,
D_A2
)
D_W2
=
np
.
matmul
(
A1
.
T
,
D_Z2
)
...
...
This diff is collapsed.
Click to expand it.
read_cifar.py
View file @
77a99859
...
...
@@ -29,13 +29,13 @@ def read_cifar(directory_path):
for
i
in
range
(
len
(
files
)):
fichier
=
directory_path
+
files
[
i
]
data_dict
=
unpickle
(
fichier
)
M
=
data_dict
[
b
'
data
'
]
D
=
data_dict
[
b
'
data
'
]
L
=
data_dict
[
b
'
labels
'
]
L
=
np
.
array
(
L
)
data
=
np
.
vstack
((
X
,
M
))
labels
=
np
.
hstack
((
Y
,
L
))
data
=
X
[
N
:
2
*
N
,]
labels
=
Y
[
A
:,]
data
=
np
.
vstack
((
data
,
D
))
labels
=
np
.
hstack
((
labels
,
L
))
data
=
data
[
N
:
2
*
N
,]
labels
=
labels
[
A
:,]
return
data
,
labels
def
split_dataset
(
data
,
labels
,
split
):
...
...
This diff is collapsed.
Click to expand it.
results/accuracy_knn.png
0 → 100644
View file @
77a99859
1.24 KiB
This diff is collapsed.
Click to expand it.