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
27134e15
Commit
27134e15
authored
Jan 02, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update imgaug
parent
78ce3a96
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
9 deletions
+33
-9
tensorpack/dataflow/common.py
tensorpack/dataflow/common.py
+0
-1
tensorpack/dataflow/imgaug/_test.py
tensorpack/dataflow/imgaug/_test.py
+18
-0
tensorpack/dataflow/imgaug/base.py
tensorpack/dataflow/imgaug/base.py
+1
-1
tensorpack/dataflow/imgaug/imgproc.py
tensorpack/dataflow/imgaug/imgproc.py
+10
-5
tensorpack/dataflow/imgaug/noname.py
tensorpack/dataflow/imgaug/noname.py
+1
-0
tensorpack/train.py
tensorpack/train.py
+3
-2
No files found.
tensorpack/dataflow/common.py
View file @
27134e15
...
...
@@ -100,7 +100,6 @@ class MapData(DataFlow):
def
get_data
(
self
):
for
dp
in
self
.
ds
.
get_data
():
d
=
list
(
dp
)
dp
[
self
.
index
]
=
self
.
func
(
dp
[
self
.
index
])
yield
dp
...
...
tensorpack/dataflow/imgaug/_test.py
0 → 100644
View file @
27134e15
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# File: _test.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
import
cv2
from
.
import
*
augmentors
=
AugmentorList
([
Contrast
((
0.2
,
1.8
)),
Flip
(
horiz
=
True
)
])
img
=
cv2
.
imread
(
'cat.jpg'
)
img
=
Image
(
img
)
augmentors
.
augment
(
img
)
cv2
.
imshow
(
" "
,
img
.
arr
)
cv2
.
waitKey
()
tensorpack/dataflow/imgaug/base.py
View file @
27134e15
...
...
@@ -61,6 +61,6 @@ class AugmentorList(ImageAugmentor):
def
_augment
(
self
,
img
):
assert
img
.
arr
.
ndim
in
[
2
,
3
]
img
.
arr
=
img
.
arr
.
astype
(
'float32'
)
/
255.0
img
.
arr
=
img
.
arr
.
astype
(
'float32'
)
for
aug
in
self
.
augs
:
aug
.
augment
(
img
)
tensorpack/dataflow/imgaug/imgproc.py
View file @
27134e15
...
...
@@ -19,7 +19,7 @@ class BrightnessAdd(ImageAugmentor):
def
_augment
(
self
,
img
):
v
=
self
.
_rand_range
(
-
self
.
delta
,
self
.
delta
)
img
.
arr
+=
v
img
.
arr
=
np
.
clip
(
img
.
arr
,
0
,
1
)
img
.
arr
=
np
.
clip
(
img
.
arr
,
0
,
255
)
class
Contrast
(
ImageAugmentor
):
"""
...
...
@@ -33,7 +33,7 @@ class Contrast(ImageAugmentor):
r
=
self
.
_rand_range
(
*
self
.
factor_range
)
mean
=
np
.
mean
(
arr
,
axis
=
(
0
,
1
),
keepdims
=
True
)
img
.
arr
=
(
arr
-
mean
)
*
r
+
mean
img
.
arr
=
np
.
clip
(
img
.
arr
,
0
,
1
)
img
.
arr
=
np
.
clip
(
img
.
arr
,
0
,
255
)
class
PerImageWhitening
(
ImageAugmentor
):
"""
...
...
@@ -41,11 +41,16 @@ class PerImageWhitening(ImageAugmentor):
x = (x - mean) / adjusted_stddev
where adjusted_stddev = max(stddev, 1.0/sqrt(num_pixels * channels))
"""
def
__init__
(
self
):
def
__init__
(
self
,
all_channel
=
True
):
self
.
all_channel
=
all_channel
pass
def
_augment
(
self
,
img
):
mean
=
np
.
mean
(
img
.
arr
,
axis
=
(
0
,
1
),
keepdims
=
True
)
std
=
np
.
std
(
img
.
arr
,
axis
=
(
0
,
1
),
keepdims
=
True
)
if
self
.
all_channel
:
mean
=
np
.
mean
(
img
.
arr
)
std
=
np
.
std
(
img
.
arr
)
else
:
mean
=
np
.
mean
(
img
.
arr
,
axis
=
(
0
,
1
),
keepdims
=
True
)
std
=
np
.
std
(
img
.
arr
,
axis
=
(
0
,
1
),
keepdims
=
True
)
std
=
np
.
maximum
(
std
,
1.0
/
np
.
sqrt
(
np
.
prod
(
img
.
arr
.
shape
)))
img
.
arr
=
(
img
.
arr
-
mean
)
/
std
tensorpack/dataflow/imgaug/noname.py
View file @
27134e15
...
...
@@ -28,6 +28,7 @@ class Flip(ImageAugmentor):
self
.
_init
()
def
_augment
(
self
,
img
):
# TODO XXX prob is wrong for both mode
if
self
.
_rand_range
()
<
self
.
prob
:
img
.
arr
=
cv2
.
flip
(
img
.
arr
,
self
.
code
)
if
img
.
coords
:
...
...
tensorpack/train.py
View file @
27134e15
...
...
@@ -161,8 +161,9 @@ def start_train(config):
summary_grads
(
grads
)
avg_maintain_op
=
summary_moving_average
(
cost_var
)
with
tf
.
control_dependencies
([
avg_maintain_op
]):
train_op
=
config
.
optimizer
.
apply_gradients
(
grads
,
get_global_step_var
())
train_op
=
tf
.
group
(
config
.
optimizer
.
apply_gradients
(
grads
,
get_global_step_var
()),
avg_maintain_op
)
describe_model
()
sess
=
tf
.
Session
(
config
=
config
.
session_config
)
...
...
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