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
abd38c59
You need to sign in or sign up before continuing.
Commit
abd38c59
authored
Jul 08, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
imgaug
parent
6f9f4cd9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
16 deletions
+45
-16
tensorpack/dataflow/common.py
tensorpack/dataflow/common.py
+1
-1
tensorpack/dataflow/dataset/ilsvrc.py
tensorpack/dataflow/dataset/ilsvrc.py
+2
-1
tensorpack/dataflow/imgaug/meta.py
tensorpack/dataflow/imgaug/meta.py
+5
-1
tensorpack/dataflow/imgaug/noise.py
tensorpack/dataflow/imgaug/noise.py
+35
-0
tensorpack/dataflow/imgaug/noname.py
tensorpack/dataflow/imgaug/noname.py
+2
-13
No files found.
tensorpack/dataflow/common.py
View file @
abd38c59
...
@@ -324,10 +324,10 @@ class LocallyShuffleData(ProxyDataFlow, RNGDataFlow):
...
@@ -324,10 +324,10 @@ class LocallyShuffleData(ProxyDataFlow, RNGDataFlow):
self
.
rng
.
shuffle
(
self
.
q
)
self
.
rng
.
shuffle
(
self
.
q
)
for
_
in
range
(
self
.
q
.
maxlen
):
for
_
in
range
(
self
.
q
.
maxlen
):
yield
self
.
q
.
popleft
()
yield
self
.
q
.
popleft
()
self
.
q
.
append
(
next
(
self
.
ds_itr
))
cnt
+=
1
cnt
+=
1
if
cnt
==
self
.
size
():
if
cnt
==
self
.
size
():
return
return
self
.
q
.
append
(
next
(
self
.
ds_itr
))
def
SelectComponent
(
ds
,
idxs
):
def
SelectComponent
(
ds
,
idxs
):
...
...
tensorpack/dataflow/dataset/ilsvrc.py
View file @
abd38c59
...
@@ -90,7 +90,7 @@ class ILSVRCMeta(object):
...
@@ -90,7 +90,7 @@ class ILSVRCMeta(object):
obj
=
caffepb
.
BlobProto
()
obj
=
caffepb
.
BlobProto
()
mean_file
=
os
.
path
.
join
(
self
.
dir
,
'imagenet_mean.binaryproto'
)
mean_file
=
os
.
path
.
join
(
self
.
dir
,
'imagenet_mean.binaryproto'
)
with
open
(
mean_file
)
as
f
:
with
open
(
mean_file
,
'rb'
)
as
f
:
obj
.
ParseFromString
(
f
.
read
())
obj
.
ParseFromString
(
f
.
read
())
arr
=
np
.
array
(
obj
.
data
)
.
reshape
((
3
,
256
,
256
))
.
astype
(
'float32'
)
arr
=
np
.
array
(
obj
.
data
)
.
reshape
((
3
,
256
,
256
))
.
astype
(
'float32'
)
arr
=
np
.
transpose
(
arr
,
[
1
,
2
,
0
])
arr
=
np
.
transpose
(
arr
,
[
1
,
2
,
0
])
...
@@ -105,6 +105,7 @@ class ILSVRC12(DataFlow):
...
@@ -105,6 +105,7 @@ class ILSVRC12(DataFlow):
"""
"""
assert
name
in
[
'train'
,
'test'
,
'val'
]
assert
name
in
[
'train'
,
'test'
,
'val'
]
self
.
full_dir
=
os
.
path
.
join
(
dir
,
name
)
self
.
full_dir
=
os
.
path
.
join
(
dir
,
name
)
assert
os
.
path
.
isdir
(
self
.
full_dir
),
self
.
full_dir
self
.
shuffle
=
shuffle
self
.
shuffle
=
shuffle
self
.
meta
=
ILSVRCMeta
(
meta_dir
)
self
.
meta
=
ILSVRCMeta
(
meta_dir
)
self
.
imglist
=
self
.
meta
.
get_image_list
(
name
)
self
.
imglist
=
self
.
meta
.
get_image_list
(
name
)
...
...
tensorpack/dataflow/imgaug/meta.py
View file @
abd38c59
...
@@ -6,7 +6,11 @@
...
@@ -6,7 +6,11 @@
from
.base
import
ImageAugmentor
from
.base
import
ImageAugmentor
__all__
=
[
'RandomChooseAug'
,
'MapImage'
]
__all__
=
[
'RandomChooseAug'
,
'MapImage'
,
'Identity'
]
class
Identity
(
ImageAugmentor
):
def
_augment
(
self
,
img
,
_
):
return
img
class
RandomChooseAug
(
ImageAugmentor
):
class
RandomChooseAug
(
ImageAugmentor
):
def
__init__
(
self
,
aug_lists
):
def
__init__
(
self
,
aug_lists
):
...
...
tensorpack/dataflow/imgaug/noise.py
0 → 100644
View file @
abd38c59
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: noise.py
# Author: Yuxin Wu <ppwwyyxxc@gmail.com>
from
.base
import
ImageAugmentor
import
numpy
as
np
import
cv2
__all__
=
[
'JpegNoise'
,
'GaussianNoise'
]
class
JpegNoise
(
ImageAugmentor
):
def
__init__
(
self
,
quality_range
=
(
40
,
100
)):
self
.
_init
(
locals
())
def
_get_augment_params
(
self
,
img
):
return
self
.
_rand_range
(
*
self
.
quality_range
)
def
_augment
(
self
,
img
,
q
):
return
cv2
.
imdecode
(
cv2
.
imencode
(
'.jpg'
,
img
,
[
cv2
.
IMWRITE_JPEG_QUALITY
,
q
])[
1
],
1
)
class
GaussianNoise
(
ImageAugmentor
):
def
__init__
(
self
,
scale
=
10
,
clip
=
True
):
self
.
_init
(
locals
())
def
_get_augment_params
(
self
,
img
):
return
self
.
rng
.
randn
(
img
.
shape
)
def
_augment
(
self
,
img
,
noise
):
ret
=
img
+
noise
if
self
.
clip
:
ret
=
np
.
clip
(
ret
,
0
,
255
)
return
ret
tensorpack/dataflow/imgaug/noname.py
View file @
abd38c59
...
@@ -6,7 +6,7 @@ from .base import ImageAugmentor
...
@@ -6,7 +6,7 @@ from .base import ImageAugmentor
import
numpy
as
np
import
numpy
as
np
import
cv2
import
cv2
__all__
=
[
'Flip'
,
'Resize'
,
'RandomResize'
,
'JpegNoise'
]
__all__
=
[
'Flip'
,
'Resize'
,
'RandomResize'
]
class
Flip
(
ImageAugmentor
):
class
Flip
(
ImageAugmentor
):
"""
"""
...
@@ -58,7 +58,7 @@ class Resize(ImageAugmentor):
...
@@ -58,7 +58,7 @@ class Resize(ImageAugmentor):
class
RandomResize
(
ImageAugmentor
):
class
RandomResize
(
ImageAugmentor
):
""" randomly rescale w and h of the image"""
""" randomly rescale w and h of the image"""
def
__init__
(
self
,
xrange
,
yrange
,
minimum
=
None
,
aspect_ratio_thres
=
0.2
):
def
__init__
(
self
,
xrange
,
yrange
,
minimum
=
(
0
,
0
),
aspect_ratio_thres
=
0.15
):
"""
"""
:param xrange: (min, max) scaling ratio
:param xrange: (min, max) scaling ratio
:param yrange: (min, max) scaling ratio
:param yrange: (min, max) scaling ratio
...
@@ -82,14 +82,3 @@ class RandomResize(ImageAugmentor):
...
@@ -82,14 +82,3 @@ class RandomResize(ImageAugmentor):
def
_augment
(
self
,
img
,
dsize
):
def
_augment
(
self
,
img
,
dsize
):
return
cv2
.
resize
(
img
,
dsize
,
interpolation
=
cv2
.
INTER_CUBIC
)
return
cv2
.
resize
(
img
,
dsize
,
interpolation
=
cv2
.
INTER_CUBIC
)
class
JpegNoise
(
ImageAugmentor
):
def
__init__
(
self
,
quality_range
=
(
40
,
100
)):
self
.
_init
(
locals
())
def
_get_augment_params
(
self
,
img
):
return
self
.
_rand_range
(
*
self
.
quality_range
)
def
_augment
(
self
,
img
,
q
):
return
cv2
.
imdecode
(
cv2
.
imencode
(
'.jpg'
,
img
,
[
cv2
.
IMWRITE_JPEG_QUALITY
,
q
])[
1
],
1
)
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