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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cavallo Alberto
Image classification
Commits
06fb753f
Commit
06fb753f
authored
1 year ago
by
MSI\alber
Browse files
Options
Downloads
Patches
Plain Diff
First commit
parent
1057ffde
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
knn.py
+16
-0
16 additions, 0 deletions
knn.py
read_cifar.py
+14
-0
14 additions, 0 deletions
read_cifar.py
with
30 additions
and
0 deletions
knn.py
+
16
−
0
View file @
06fb753f
import
numpy
as
np
def
distance_matrix
(
m1
,
m2
):
if
m1
.
shape
!=
m2
.
shape
:
raise
ValueError
(
"
Dimensions must be identical
"
)
x
=
(
m1
-
m2
)
**
2
y
=
np
.
sum
(
x
)
dist
=
np
.
sqrt
(
y
)
return
dist
def
knn_predict
(
dist
,
labels_train
,
k
,
):
return
def
evaluate_knn
(
data_train
,
labels_train
,
data_test
,
labels_test
,
k
):
return
\ No newline at end of file
This diff is collapsed.
Click to expand it.
read_cifar.py
0 → 100644
+
14
−
0
View file @
06fb753f
import
pickle
import
numpy
as
np
def
read_cifar_batch
(
batch
):
with
open
(
batch
,
'
rb
'
)
as
fo
:
dict
=
pickle
.
load
(
fo
,
encoding
=
'
bytes
'
)
data
=
dict
[
b
'
data
'
]
labels
=
dict
[
b
'
labels
'
]
return
data
.
astype
(
np
.
float32
),
np
.
array
(
labels
,
dtype
=
np
.
int64
)
batch
=
'
data/cifar-10-batches-py/data_batch_1
'
data
,
labels
=
read_cifar_batch
(
batch
)
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