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
dc59ad5f
Commit
dc59ad5f
authored
Oct 16, 2016
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix image_sampling, and email
parent
6e080435
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
46 additions
and
44 deletions
+46
-44
examples/Atari2600/DQN.py
examples/Atari2600/DQN.py
+1
-1
examples/DisturbLabel/mnist-disturb.py
examples/DisturbLabel/mnist-disturb.py
+1
-1
examples/DisturbLabel/svhn-disturb.py
examples/DisturbLabel/svhn-disturb.py
+1
-1
examples/DoReFa-Net/svhn-digit-dorefa.py
examples/DoReFa-Net/svhn-digit-dorefa.py
+1
-1
examples/HED/hed.py
examples/HED/hed.py
+1
-1
examples/Inception/inception-bn.py
examples/Inception/inception-bn.py
+1
-1
examples/Inception/inceptionv3.py
examples/Inception/inceptionv3.py
+1
-1
examples/ResNet/cifar10-resnet.py
examples/ResNet/cifar10-resnet.py
+1
-1
examples/ResNet/svhn-resnet.py
examples/ResNet/svhn-resnet.py
+1
-1
examples/char-rnn/char-rnn.py
examples/char-rnn/char-rnn.py
+1
-1
examples/cifar-convnet.py
examples/cifar-convnet.py
+1
-1
examples/load-alexnet.py
examples/load-alexnet.py
+1
-1
examples/load-vgg16.py
examples/load-vgg16.py
+1
-2
examples/mnist-convnet.py
examples/mnist-convnet.py
+1
-1
examples/svhn-digit-convnet.py
examples/svhn-digit-convnet.py
+1
-1
tensorpack/dataflow/image.py
tensorpack/dataflow/image.py
+7
-9
tensorpack/models/image_sample.py
tensorpack/models/image_sample.py
+24
-19
No files found.
examples/Atari2600/DQN.py
View file @
dc59ad5f
#!/usr/bin/env python2
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# File: DQN.py
# File: DQN.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
numpy
as
np
import
numpy
as
np
import
tensorflow
as
tf
import
tensorflow
as
tf
...
...
examples/DisturbLabel/mnist-disturb.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# File: mnist-disturb.py
# File: mnist-disturb.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
numpy
as
np
import
numpy
as
np
import
tensorflow
as
tf
import
tensorflow
as
tf
...
...
examples/DisturbLabel/svhn-disturb.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: svhn-disturb.py
# File: svhn-disturb.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
tensorflow
as
tf
import
tensorflow
as
tf
import
argparse
import
argparse
...
...
examples/DoReFa-Net/svhn-digit-dorefa.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: svhn-digit-dorefa.py
# File: svhn-digit-dorefa.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
tensorflow
as
tf
import
tensorflow
as
tf
import
argparse
import
argparse
...
...
examples/HED/hed.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: hed.py
# File: hed.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
cv2
import
cv2
import
tensorflow
as
tf
import
tensorflow
as
tf
...
...
examples/Inception/inception-bn.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: inception-bn.py
# File: inception-bn.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
cv2
import
cv2
import
argparse
import
argparse
...
...
examples/Inception/inceptionv3.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: inceptionv3.py
# File: inceptionv3.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
cv2
import
cv2
import
argparse
import
argparse
...
...
examples/ResNet/cifar10-resnet.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: cifar10-resnet.py
# File: cifar10-resnet.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
numpy
as
np
import
numpy
as
np
import
tensorflow
as
tf
import
tensorflow
as
tf
...
...
examples/ResNet/svhn-resnet.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: svhn-resnet.py
# File: svhn-resnet.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
tensorflow
as
tf
import
tensorflow
as
tf
import
argparse
import
argparse
...
...
examples/char-rnn/char-rnn.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# File: char-rnn.py
# File: char-rnn.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
tensorflow
as
tf
import
tensorflow
as
tf
import
numpy
as
np
import
numpy
as
np
...
...
examples/cifar-convnet.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: cifar-convnet.py
# File: cifar-convnet.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
tensorflow
as
tf
import
tensorflow
as
tf
import
argparse
import
argparse
import
numpy
as
np
import
numpy
as
np
...
...
examples/load-alexnet.py
View file @
dc59ad5f
#!/usr/bin/env python2
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: load-alexnet.py
# File: load-alexnet.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
tensorflow
as
tf
import
tensorflow
as
tf
import
numpy
as
np
import
numpy
as
np
...
...
examples/load-vgg16.py
View file @
dc59ad5f
#!/usr/bin/env python2
#!/usr/bin/env python2
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: load-vgg16.py
# File: load-vgg16.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
cv2
import
cv2
import
tensorflow
as
tf
import
tensorflow
as
tf
...
@@ -72,7 +72,6 @@ class Model(ModelDesc):
...
@@ -72,7 +72,6 @@ class Model(ModelDesc):
def
run_test
(
path
,
input
):
def
run_test
(
path
,
input
):
param_dict
=
np
.
load
(
path
)
.
item
()
param_dict
=
np
.
load
(
path
)
.
item
()
pred_config
=
PredictConfig
(
pred_config
=
PredictConfig
(
model
=
Model
(),
model
=
Model
(),
input_var_names
=
[
'input'
],
input_var_names
=
[
'input'
],
...
...
examples/mnist-convnet.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
# File: mnist-convnet.py
# File: mnist-convnet.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
numpy
as
np
import
numpy
as
np
import
tensorflow
as
tf
import
tensorflow
as
tf
...
...
examples/svhn-digit-convnet.py
View file @
dc59ad5f
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# -*- coding: UTF-8 -*-
# File: svhn-digit-convnet.py
# File: svhn-digit-convnet.py
# Author: Yuxin Wu <ppwwyyxx@gmail.com>
# Author: Yuxin Wu <ppwwyyxx
c
@gmail.com>
import
tensorflow
as
tf
import
tensorflow
as
tf
import
argparse
import
argparse
...
...
tensorpack/dataflow/image.py
View file @
dc59ad5f
...
@@ -12,11 +12,12 @@ from .imgaug import AugmentorList
...
@@ -12,11 +12,12 @@ from .imgaug import AugmentorList
__all__
=
[
'ImageFromFile'
,
'AugmentImageComponent'
,
'AugmentImageComponents'
]
__all__
=
[
'ImageFromFile'
,
'AugmentImageComponent'
,
'AugmentImageComponents'
]
class
ImageFromFile
(
DataFlow
):
class
ImageFromFile
(
DataFlow
):
""" Generate rgb images from list of files """
def
__init__
(
self
,
files
,
channel
=
3
,
resize
=
None
):
def
__init__
(
self
,
files
,
channel
=
3
,
resize
=
None
):
""" :param files: list of file paths
"""
:param channel: 1 or 3 channel
Generate rgb images from list of files
:param resize: a (h, w) tuple. If given, will force a resize
:param files: list of file paths
:param channel: 1 or 3 channel
:param resize: a (h, w) tuple. If given, will force a resize
"""
"""
assert
len
(
files
)
assert
len
(
files
)
self
.
files
=
files
self
.
files
=
files
...
@@ -38,11 +39,9 @@ class ImageFromFile(DataFlow):
...
@@ -38,11 +39,9 @@ class ImageFromFile(DataFlow):
class
AugmentImageComponent
(
MapDataComponent
):
class
AugmentImageComponent
(
MapDataComponent
):
"""
Augment the image component of datapoints
"""
def
__init__
(
self
,
ds
,
augmentors
,
index
=
0
):
def
__init__
(
self
,
ds
,
augmentors
,
index
=
0
):
"""
"""
Augment the image component of datapoints
:param ds: a `DataFlow` instance.
:param ds: a `DataFlow` instance.
:param augmentors: a list of `ImageAugmentor` instance to be applied in order.
:param augmentors: a list of `ImageAugmentor` instance to be applied in order.
:param index: the index (or list of indices) of the image component in the produced datapoints by `ds`. default to be 0
:param index: the index (or list of indices) of the image component in the produced datapoints by `ds`. default to be 0
...
@@ -57,9 +56,8 @@ class AugmentImageComponent(MapDataComponent):
...
@@ -57,9 +56,8 @@ class AugmentImageComponent(MapDataComponent):
class
AugmentImageComponents
(
MapData
):
class
AugmentImageComponents
(
MapData
):
""" Augment a list of images of the same shape, with the same parameters"""
def
__init__
(
self
,
ds
,
augmentors
,
index
=
(
0
,
1
)):
def
__init__
(
self
,
ds
,
augmentors
,
index
=
(
0
,
1
)):
"""
"""
Augment a list of images of the same shape, with the same parameters
:param ds: a `DataFlow` instance.
:param ds: a `DataFlow` instance.
:param augmentors: a list of `ImageAugmentor` instance to be applied in order.
:param augmentors: a list of `ImageAugmentor` instance to be applied in order.
:param index: tuple of indices of the image components
:param index: tuple of indices of the image components
...
...
tensorpack/models/image_sample.py
View file @
dc59ad5f
...
@@ -12,7 +12,7 @@ __all__ = ['ImageSample']
...
@@ -12,7 +12,7 @@ __all__ = ['ImageSample']
# XXX TODO ugly.
# XXX TODO ugly.
# really need to fix this after tensorflow supports advanced indexing
# really need to fix this after tensorflow supports advanced indexing
# See github:tensorflow#418,#206
# See github:tensorflow#418,#206
def
sample
(
img
,
coords
,
borderMode
):
def
sample
(
img
,
coords
):
"""
"""
:param img: bxhxwxc
:param img: bxhxwxc
:param coords: bxh2xw2x2 (y, x) floating point (but is actually holding integer)
:param coords: bxh2xw2x2 (y, x) floating point (but is actually holding integer)
...
@@ -39,14 +39,6 @@ def sample(img, coords, borderMode):
...
@@ -39,14 +39,6 @@ def sample(img, coords, borderMode):
img
=
tf
.
reshape
(
img
,
[
-
1
,
shape
[
2
]])
#bhw x c
img
=
tf
.
reshape
(
img
,
[
-
1
,
shape
[
2
]])
#bhw x c
sampled
=
tf
.
gather
(
img
,
flat_coords
)
sampled
=
tf
.
gather
(
img
,
flat_coords
)
if
borderMode
==
'constant'
:
mask
=
tf
.
less_equal
(
orig_coords
,
max_coor
)
mask2
=
tf
.
greater_equal
(
orig_coords
,
0
)
mask
=
tf
.
logical_and
(
mask
,
mask2
)
#bxh2xw2x2
mask
=
tf
.
reduce_all
(
mask
,
[
3
])
# bxh2xw2 boolean
mask
=
tf
.
expand_dims
(
mask
,
3
)
sampled
=
sampled
*
tf
.
cast
(
mask
,
tf
.
float32
)
return
sampled
return
sampled
@
layer_register
()
@
layer_register
()
...
@@ -64,8 +56,12 @@ def ImageSample(inputs, borderMode='repeat'):
...
@@ -64,8 +56,12 @@ def ImageSample(inputs, borderMode='repeat'):
"""
"""
template
,
mapping
=
inputs
template
,
mapping
=
inputs
assert
template
.
get_shape
()
.
ndims
==
4
and
mapping
.
get_shape
()
.
ndims
==
4
assert
template
.
get_shape
()
.
ndims
==
4
and
mapping
.
get_shape
()
.
ndims
==
4
input_shape
=
template
.
get_shape
()
.
as_list
()[
1
:]
assert
None
not
in
input_shape
,
\
"Images in ImageSample layer must have fully-defined shape"
assert
borderMode
in
[
'repeat'
,
'constant'
]
assert
borderMode
in
[
'repeat'
,
'constant'
]
orig_mapping
=
mapping
mapping
=
tf
.
maximum
(
mapping
,
0.0
)
mapping
=
tf
.
maximum
(
mapping
,
0.0
)
lcoor
=
tf
.
floor
(
mapping
)
lcoor
=
tf
.
floor
(
mapping
)
ucoor
=
lcoor
+
1
ucoor
=
lcoor
+
1
...
@@ -86,10 +82,19 @@ def ImageSample(inputs, borderMode='repeat'):
...
@@ -86,10 +82,19 @@ def ImageSample(inputs, borderMode='repeat'):
#diff = tf.Print(diff, [tf.is_finite(tf.reduce_sum(diff)), tf.shape(prod),
#diff = tf.Print(diff, [tf.is_finite(tf.reduce_sum(diff)), tf.shape(prod),
#tf.reduce_max(diff), diff], summarize=50)
#tf.reduce_max(diff), diff], summarize=50)
return
tf
.
add_n
([
sample
(
template
,
lcoor
,
borderMode
)
*
neg_diffx
*
neg_diffy
,
ret
=
tf
.
add_n
([
sample
(
template
,
lcoor
)
*
neg_diffx
*
neg_diffy
,
sample
(
template
,
ucoor
,
borderMode
)
*
diffx
*
diffy
,
sample
(
template
,
ucoor
)
*
diffx
*
diffy
,
sample
(
template
,
lyux
,
borderMode
)
*
neg_diffy
*
diffx
,
sample
(
template
,
lyux
)
*
neg_diffy
*
diffx
,
sample
(
template
,
uylx
,
borderMode
)
*
diffy
*
neg_diffx
],
name
=
'sampled'
)
sample
(
template
,
uylx
)
*
diffy
*
neg_diffx
],
name
=
'sampled'
)
if
borderMode
==
'constant'
:
max_coor
=
tf
.
constant
([
input_shape
[
0
]
-
1
,
input_shape
[
1
]
-
1
],
dtype
=
tf
.
float32
)
mask
=
tf
.
greater_equal
(
orig_mapping
,
0.0
)
mask2
=
tf
.
less_equal
(
orig_mapping
,
max_coor
)
mask
=
tf
.
logical_and
(
mask
,
mask2
)
#bxh2xw2x2
mask
=
tf
.
reduce_all
(
mask
,
[
3
])
# bxh2xw2 boolean
mask
=
tf
.
expand_dims
(
mask
,
3
)
ret
=
ret
*
tf
.
cast
(
mask
,
tf
.
float32
)
return
ret
from
._test
import
TestModel
from
._test
import
TestModel
class
TestSample
(
TestModel
):
class
TestSample
(
TestModel
):
...
@@ -137,21 +142,21 @@ if __name__ == '__main__':
...
@@ -137,21 +142,21 @@ if __name__ == '__main__':
h
,
w
=
300
,
400
h
,
w
=
300
,
400
mapping
=
np
.
zeros
((
1
,
h
,
w
,
2
),
dtype
=
'float32'
)
mapping
=
np
.
zeros
((
1
,
h
,
w
,
2
),
dtype
=
'float32'
)
diff
=
200
0
diff
=
200
for
x
in
range
(
w
):
for
x
in
range
(
w
):
for
y
in
range
(
h
):
for
y
in
range
(
h
):
mapping
[
0
,
y
,
x
,:]
=
np
.
array
([
y
-
diff
+
0.4
,
x
-
diff
+
0.5
])
mapping
[
0
,
y
,
x
,:]
=
np
.
array
([
y
-
diff
+
0.4
,
x
-
diff
+
0.5
])
mapv
=
tf
.
Variable
(
mapping
)
mapv
=
tf
.
Variable
(
mapping
)
output
=
ImageSample
(
'sample'
,
[
imv
,
mapv
])
output
=
ImageSample
(
'sample'
,
[
imv
,
mapv
]
,
borderMode
=
'constant'
)
sess
=
tf
.
Session
()
sess
=
tf
.
Session
()
sess
.
run
(
tf
.
initialize_all_variables
())
sess
.
run
(
tf
.
initialize_all_variables
())
out
=
sess
.
run
(
tf
.
gradients
(
tf
.
reduce_sum
(
output
),
mapv
))
#
out = sess.run(tf.gradients(tf.reduce_sum(output), mapv))
#out = sess.run(output)
#out = sess.run(output)
print
(
out
[
0
]
.
min
())
#
print(out[0].min())
print
(
out
[
0
]
.
max
())
#
print(out[0].max())
print
(
out
[
0
]
.
sum
())
#
print(out[0].sum())
out
=
sess
.
run
([
output
])[
0
]
out
=
sess
.
run
([
output
])[
0
]
im
=
out
[
0
]
im
=
out
[
0
]
...
...
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