Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
d24a9230
Commit
d24a9230
authored
Feb 07, 2019
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only use the mean of training set (fix #1072)
parent
497f25b1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
13 deletions
+30
-13
examples/ResNet/cifar10-resnet.py
examples/ResNet/cifar10-resnet.py
+1
-1
tensorpack/dataflow/dataset/cifar.py
tensorpack/dataflow/dataset/cifar.py
+20
-6
tensorpack/dataflow/dataset/svhn.py
tensorpack/dataflow/dataset/svhn.py
+9
-6
No files found.
examples/ResNet/cifar10-resnet.py
View file @
d24a9230
...
...
@@ -118,7 +118,7 @@ class Model(ModelDesc):
def
get_data
(
train_or_test
):
isTrain
=
train_or_test
==
'train'
ds
=
dataset
.
Cifar10
(
train_or_test
)
pp_mean
=
ds
.
get_per_pixel_mean
()
pp_mean
=
ds
.
get_per_pixel_mean
(
(
'train'
,)
)
if
isTrain
:
augmentors
=
[
imgaug
.
CenterPaste
((
40
,
40
)),
...
...
tensorpack/dataflow/dataset/cifar.py
View file @
d24a9230
...
...
@@ -132,13 +132,23 @@ class CifarBase(RNGDataFlow):
# since cifar is quite small, just do it for safety
yield
self
.
data
[
k
]
def
get_per_pixel_mean
(
self
):
def
get_per_pixel_mean
(
self
,
names
=
(
'train'
,
'test'
)
):
"""
Args:
names (tuple[str]): the names ('train' or 'test') of the datasets
Returns:
a mean image of all
(train and test) images of
size 32x32x3
a mean image of all
images in the given datasets, with
size 32x32x3
"""
for
name
in
names
:
assert
name
in
[
'train'
,
'test'
],
name
train_files
,
test_files
,
_
=
get_filenames
(
self
.
dir
,
self
.
cifar_classnum
)
all_imgs
=
[
x
[
0
]
for
x
in
read_cifar
(
train_files
+
test_files
,
self
.
cifar_classnum
)]
all_files
=
[]
if
'train'
in
names
:
all_files
.
extend
(
train_files
)
if
'test'
in
names
:
all_files
.
extend
(
test_files
)
all_imgs
=
[
x
[
0
]
for
x
in
read_cifar
(
all_files
,
self
.
cifar_classnum
)]
arr
=
np
.
array
(
all_imgs
,
dtype
=
'float32'
)
mean
=
np
.
mean
(
arr
,
axis
=
0
)
return
mean
...
...
@@ -150,11 +160,15 @@ class CifarBase(RNGDataFlow):
"""
return
self
.
_label_names
def
get_per_channel_mean
(
self
):
def
get_per_channel_mean
(
self
,
names
=
(
'train'
,
'test'
)
):
"""
return three values as mean of each channel
Args:
names (tuple[str]): the names ('train' or 'test') of the datasets
Returns:
An array of three values as mean of each channel, for all images in the given datasets.
"""
mean
=
self
.
get_per_pixel_mean
()
mean
=
self
.
get_per_pixel_mean
(
names
)
return
np
.
mean
(
mean
,
axis
=
(
0
,
1
))
...
...
tensorpack/dataflow/dataset/svhn.py
View file @
d24a9230
...
...
@@ -62,15 +62,18 @@ class SVHNDigit(RNGDataFlow):
yield
[
self
.
X
[
k
],
self
.
Y
[
k
]]
@
staticmethod
def
get_per_pixel_mean
():
def
get_per_pixel_mean
(
names
=
(
'train'
,
'test'
,
'extra'
)
):
"""
Args:
names (tuple[str]): names of the dataset split
Returns:
a 32x32x3 image
a 32x32x3 image
, the mean of all images in the given datasets
"""
a
=
SVHNDigit
(
'train'
)
b
=
SVHNDigit
(
'test'
)
c
=
SVHNDigit
(
'extra'
)
return
np
.
concatenate
(
(
a
.
X
,
b
.
X
,
c
.
X
))
.
mean
(
axis
=
0
)
for
name
in
names
:
assert
name
in
[
'train'
,
'test'
,
'extra'
],
name
images
=
[
SVHNDigit
(
x
)
.
X
for
x
in
names
]
return
np
.
concatenate
(
tuple
(
images
))
.
mean
(
axis
=
0
)
try
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment