Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Image 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
Audard Lucile
Image classification
Compare revisions
8047c92f712a910c77b57d9350391fe4773bccad to 69c44ac44367e95f9b61b2aaceab2e8ac6a5506e
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
laudard/image-classification
Select target project
No results found
69c44ac44367e95f9b61b2aaceab2e8ac6a5506e
Select Git revision
Branches
main
1 result
Swap
Target
laudard/image-classification
Select target project
laudard/image-classification
1 result
8047c92f712a910c77b57d9350391fe4773bccad
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
2
Update read_cifar.py
· 7cb02fb3
Audard Lucile
authored
Oct 23, 2023
7cb02fb3
Create knn.py
· 69c44ac4
Audard Lucile
authored
Oct 23, 2023
69c44ac4
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
knn.py
+36
-0
36 additions, 0 deletions
knn.py
read_cifar.py
+7
-1
7 additions, 1 deletion
read_cifar.py
with
43 additions
and
1 deletion
knn.py
0 → 100644
View file @
69c44ac4
import
numpy
as
np
def
distance_matrix
(
mat1
,
mat2
):
dists
=
np
.
sqrt
(
np
.
matmul
(
mat1
,
mat1
)
+
np
.
matmul
(
mat2
,
mat2
)
-
2
*
np
.
matmul
(
mat1
,
mat2
))
return
dists
def
knn_predict
(
dists
,
labels_train
,
k
):
return
predicted_labels
mat1
=
np
.
array
([[
1
,
2
],
[
3
,
4
]])
mat2
=
np
.
array
([[
5
,
6
],
[
7
,
8
]])
A
=
np
.
matmul
(
mat1
,
mat1
)
print
(
A
)
B
=
np
.
matmul
(
mat2
,
mat2
)
print
(
B
)
C
=
2
*
np
.
matmul
(
mat1
,
mat2
)
print
(
C
)
print
(
A
+
B
-
C
)
mat
=
distance_matrix
(
mat1
,
mat2
)
print
(
mat
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
read_cifar.py
View file @
69c44ac4
import
pickle
import
numpy
as
np
def
unpickle
(
file
):
with
open
(
file
,
'
rb
'
)
as
fo
:
batch
=
pickle
.
load
(
fo
,
encoding
=
'
bytes
'
)
...
...
@@ -19,6 +20,11 @@ def read_cifar(folder_path):
labels
=
np
.
concatenate
((
labels
,
read_cifar_batch
(
folder_path
+
"
/data_batch_
"
+
str
(
i
))[
1
]))
return
data
,
labels
def
split_dataset
(
data
,
labels
,
split
):
index
=
int
(
split
*
len
(
data
))
data_train
,
data_test
=
np
.
split
(
data
,
index
)
labels_train
,
labels_test
=
np
.
split
(
labels
,
index
)
return
data_train
,
labels_train
,
data_test
,
labels_test
...
...
This diff is collapsed.
Click to expand it.