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
Corbani Pierre
Image classification
Merge requests
!1
first commit
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
first commit
master
into
main
Overview
0
Commits
1
Changes
2
Merged
Corbani Pierre
requested to merge
master
into
main
1 year ago
Overview
0
Commits
1
Changes
2
Expand
0
0
Merge request reports
Compare
main
main (base)
and
latest version
latest version
6ed0414c
1 commit,
1 year ago
2 files
+
39
−
0
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
read_cifar_batch.py
0 → 100644
+
39
−
0
Options
import
pickle
import
numpy
as
np
import
glob
def
unpickle
(
file
):
with
open
(
file
,
'
rb
'
)
as
fo
:
dict
=
pickle
.
load
(
fo
,
encoding
=
'
bytes
'
)
return
dict
def
read_cifar_batch
(
path_to_batch_file
):
dict
=
unpickle
(
path_to_batch_file
)
data
=
np
.
array
(
dict
[
b
'
data
'
],
dtype
=
np
.
float32
)
/
255
labels
=
np
.
array
(
dict
[
b
'
labels
'
],
dtype
=
np
.
int64
)
return
data
,
labels
def
read_cifar
(
path_to_batches_files
):
files
=
glob
.
glob
(
path_to_batches_files
)
data
,
labels
=
read_cifar_batch
(
files
[
0
])
for
i
in
range
(
1
,
len
(
files
)):
data_temp
,
labels_temp
=
read_cifar_batch
(
files
[
i
])
data
=
np
.
concatenate
((
data
,
data_temp
),
axis
=
0
)
labels
=
np
.
concatenate
((
labels
,
labels_temp
),
axis
=
0
)
return
data
,
labels
if
__name__
==
"
__main__
"
:
path
=
"
image-classification/data/cifar-10-batches-py/data_batch_1
"
read_cifar_batch
(
path
)
#plot the 9 first image of the batch
import
matplotlib.pyplot
as
plt
data
,
labels
=
read_cifar_batch
(
path
)
fig
,
axes
=
plt
.
subplots
(
3
,
3
)
fig
.
subplots_adjust
(
hspace
=
0.6
,
wspace
=
0.3
)
for
i
,
ax
in
enumerate
(
axes
.
flat
):
ax
.
imshow
(
data
[
i
].
reshape
(
3
,
32
,
32
).
transpose
([
1
,
2
,
0
]))
ax
.
set_xticks
([])
ax
.
set_yticks
([])
ax
.
set_xlabel
(
labels
[
i
])
plt
.
show
()
Loading