Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ModelZoo
ResNet50_tensorflow
Commits
3f74c7b4
Commit
3f74c7b4
authored
Mar 14, 2017
by
Neal Wu
Browse files
Convert tf.op_scope to tf.name_scope, plus a few other 1.0 upgrade changes
parent
0b8bfa84
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
29 additions
and
20 deletions
+29
-20
differential_privacy/dp_sgd/dp_optimizer/utils.py
differential_privacy/dp_sgd/dp_optimizer/utils.py
+6
-3
inception/inception/image_processing.py
inception/inception/image_processing.py
+11
-8
learning_to_remember_rare_events/memory.py
learning_to_remember_rare_events/memory.py
+4
-3
learning_to_remember_rare_events/train.py
learning_to_remember_rare_events/train.py
+1
-1
swivel/swivel.py
swivel/swivel.py
+3
-2
textsum/seq2seq_lib.py
textsum/seq2seq_lib.py
+4
-3
No files found.
differential_privacy/dp_sgd/dp_optimizer/utils.py
View file @
3f74c7b4
...
@@ -233,7 +233,8 @@ def BatchClipByL2norm(t, upper_bound, name=None):
...
@@ -233,7 +233,8 @@ def BatchClipByL2norm(t, upper_bound, name=None):
"""
"""
assert
upper_bound
>
0
assert
upper_bound
>
0
with
tf
.
op_scope
([
t
,
upper_bound
],
name
,
"batch_clip_by_l2norm"
)
as
name
:
with
tf
.
name_scope
(
values
=
[
t
,
upper_bound
],
name
=
name
,
default_name
=
"batch_clip_by_l2norm"
)
as
name
:
saved_shape
=
tf
.
shape
(
t
)
saved_shape
=
tf
.
shape
(
t
)
batch_size
=
tf
.
slice
(
saved_shape
,
[
0
],
[
1
])
batch_size
=
tf
.
slice
(
saved_shape
,
[
0
],
[
1
])
t2
=
tf
.
reshape
(
t
,
tf
.
concat
(
axis
=
0
,
values
=
[
batch_size
,
[
-
1
]]))
t2
=
tf
.
reshape
(
t
,
tf
.
concat
(
axis
=
0
,
values
=
[
batch_size
,
[
-
1
]]))
...
@@ -264,7 +265,8 @@ def SoftThreshold(t, threshold_ratio, name=None):
...
@@ -264,7 +265,8 @@ def SoftThreshold(t, threshold_ratio, name=None):
"""
"""
assert
threshold_ratio
>=
0
assert
threshold_ratio
>=
0
with
tf
.
op_scope
([
t
,
threshold_ratio
],
name
,
"soft_thresholding"
)
as
name
:
with
tf
.
name_scope
(
values
=
[
t
,
threshold_ratio
],
name
=
name
,
default_name
=
"soft_thresholding"
)
as
name
:
saved_shape
=
tf
.
shape
(
t
)
saved_shape
=
tf
.
shape
(
t
)
t2
=
tf
.
reshape
(
t
,
tf
.
concat
(
axis
=
0
,
values
=
[
tf
.
slice
(
saved_shape
,
[
0
],
[
1
]),
-
1
]))
t2
=
tf
.
reshape
(
t
,
tf
.
concat
(
axis
=
0
,
values
=
[
tf
.
slice
(
saved_shape
,
[
0
],
[
1
]),
-
1
]))
t_abs
=
tf
.
abs
(
t2
)
t_abs
=
tf
.
abs
(
t2
)
...
@@ -286,7 +288,8 @@ def AddGaussianNoise(t, sigma, name=None):
...
@@ -286,7 +288,8 @@ def AddGaussianNoise(t, sigma, name=None):
the noisy tensor.
the noisy tensor.
"""
"""
with
tf
.
op_scope
([
t
,
sigma
],
name
,
"add_gaussian_noise"
)
as
name
:
with
tf
.
name_scope
(
values
=
[
t
,
sigma
],
name
=
name
,
default_name
=
"add_gaussian_noise"
)
as
name
:
noisy_t
=
t
+
tf
.
random_normal
(
tf
.
shape
(
t
),
stddev
=
sigma
)
noisy_t
=
t
+
tf
.
random_normal
(
tf
.
shape
(
t
),
stddev
=
sigma
)
return
noisy_t
return
noisy_t
...
...
inception/inception/image_processing.py
View file @
3f74c7b4
...
@@ -142,11 +142,12 @@ def decode_jpeg(image_buffer, scope=None):
...
@@ -142,11 +142,12 @@ def decode_jpeg(image_buffer, scope=None):
Args:
Args:
image_buffer: scalar string Tensor.
image_buffer: scalar string Tensor.
scope: Optional scope for
op
_scope.
scope: Optional scope for
name
_scope.
Returns:
Returns:
3-D float Tensor with values ranging from [0, 1).
3-D float Tensor with values ranging from [0, 1).
"""
"""
with
tf
.
op_scope
([
image_buffer
],
scope
,
'decode_jpeg'
):
with
tf
.
name_scope
(
values
=
[
image_buffer
],
name
=
scope
,
default_name
=
'decode_jpeg'
):
# Decode the string as an RGB JPEG.
# Decode the string as an RGB JPEG.
# Note that the resulting image contains an unknown height and width
# Note that the resulting image contains an unknown height and width
# that is set dynamically by decode_jpeg. In other words, the height
# that is set dynamically by decode_jpeg. In other words, the height
...
@@ -171,11 +172,11 @@ def distort_color(image, thread_id=0, scope=None):
...
@@ -171,11 +172,11 @@ def distort_color(image, thread_id=0, scope=None):
Args:
Args:
image: Tensor containing single image.
image: Tensor containing single image.
thread_id: preprocessing thread ID.
thread_id: preprocessing thread ID.
scope: Optional scope for
op
_scope.
scope: Optional scope for
name
_scope.
Returns:
Returns:
color-distorted image
color-distorted image
"""
"""
with
tf
.
op
_scope
([
image
],
scope
,
'distort_color'
):
with
tf
.
name
_scope
(
values
=
[
image
],
name
=
scope
,
default_name
=
'distort_color'
):
color_ordering
=
thread_id
%
2
color_ordering
=
thread_id
%
2
if
color_ordering
==
0
:
if
color_ordering
==
0
:
...
@@ -209,11 +210,12 @@ def distort_image(image, height, width, bbox, thread_id=0, scope=None):
...
@@ -209,11 +210,12 @@ def distort_image(image, height, width, bbox, thread_id=0, scope=None):
where each coordinate is [0, 1) and the coordinates are arranged
where each coordinate is [0, 1) and the coordinates are arranged
as [ymin, xmin, ymax, xmax].
as [ymin, xmin, ymax, xmax].
thread_id: integer indicating the preprocessing thread.
thread_id: integer indicating the preprocessing thread.
scope: Optional scope for
op
_scope.
scope: Optional scope for
name
_scope.
Returns:
Returns:
3-D float Tensor of distorted image used for training.
3-D float Tensor of distorted image used for training.
"""
"""
with
tf
.
op_scope
([
image
,
height
,
width
,
bbox
],
scope
,
'distort_image'
):
with
tf
.
name_scope
(
values
=
[
image
,
height
,
width
,
bbox
],
name
=
scope
,
default_name
=
'distort_image'
):
# Each bounding box has shape [1, num_boxes, box coords] and
# Each bounding box has shape [1, num_boxes, box coords] and
# the coordinates are ordered [ymin, xmin, ymax, xmax].
# the coordinates are ordered [ymin, xmin, ymax, xmax].
...
@@ -281,11 +283,12 @@ def eval_image(image, height, width, scope=None):
...
@@ -281,11 +283,12 @@ def eval_image(image, height, width, scope=None):
image: 3-D float Tensor
image: 3-D float Tensor
height: integer
height: integer
width: integer
width: integer
scope: Optional scope for
op
_scope.
scope: Optional scope for
name
_scope.
Returns:
Returns:
3-D float Tensor of prepared image.
3-D float Tensor of prepared image.
"""
"""
with
tf
.
op_scope
([
image
,
height
,
width
],
scope
,
'eval_image'
):
with
tf
.
name_scope
(
values
=
[
image
,
height
,
width
],
name
=
scope
,
default_name
=
'eval_image'
):
# Crop the central region of the image with an area containing 87.5% of
# Crop the central region of the image with an area containing 87.5% of
# the original image.
# the original image.
image
=
tf
.
image
.
central_crop
(
image
,
central_fraction
=
0.875
)
image
=
tf
.
image
.
central_crop
(
image
,
central_fraction
=
0.875
)
...
...
learning_to_remember_rare_events/memory.py
View file @
3f74c7b4
...
@@ -151,8 +151,9 @@ class Memory(object):
...
@@ -151,8 +151,9 @@ class Memory(object):
if
output_given
and
use_recent_idx
:
# add at least one correct memory
if
output_given
and
use_recent_idx
:
# add at least one correct memory
most_recent_hint_idx
=
tf
.
gather
(
self
.
recent_idx
,
intended_output
)
most_recent_hint_idx
=
tf
.
gather
(
self
.
recent_idx
,
intended_output
)
hint_pool_idxs
=
tf
.
concat
([
hint_pool_idxs
,
hint_pool_idxs
=
tf
.
concat
(
tf
.
expand_dims
(
most_recent_hint_idx
,
1
)],
1
)
axis
=
1
,
values
=
[
hint_pool_idxs
,
tf
.
expand_dims
(
most_recent_hint_idx
,
1
)])
choose_k
=
tf
.
shape
(
hint_pool_idxs
)[
1
]
choose_k
=
tf
.
shape
(
hint_pool_idxs
)[
1
]
with
tf
.
device
(
self
.
var_cache_device
):
with
tf
.
device
(
self
.
var_cache_device
):
...
@@ -351,7 +352,7 @@ class LSHMemory(Memory):
...
@@ -351,7 +352,7 @@ class LSHMemory(Memory):
self
.
memory_size
-
1
),
0
)
self
.
memory_size
-
1
),
0
)
for
i
,
idxs
in
enumerate
(
hash_slot_idxs
)]
for
i
,
idxs
in
enumerate
(
hash_slot_idxs
)]
return
tf
.
concat
(
hint_pool_idxs
,
1
)
return
tf
.
concat
(
axis
=
1
,
values
=
hint_pool_idxs
)
def
make_update_op
(
self
,
upd_idxs
,
upd_keys
,
upd_vals
,
def
make_update_op
(
self
,
upd_idxs
,
upd_keys
,
upd_vals
,
batch_size
,
use_recent_idx
,
intended_output
):
batch_size
,
use_recent_idx
,
intended_output
):
...
...
learning_to_remember_rare_events/train.py
View file @
3f74c7b4
...
@@ -168,7 +168,7 @@ class Trainer(object):
...
@@ -168,7 +168,7 @@ class Trainer(object):
self
.
model
.
setup
()
self
.
model
.
setup
()
sess
=
tf
.
Session
()
sess
=
tf
.
Session
()
sess
.
run
(
tf
.
initialize_
al
l
_variables
())
sess
.
run
(
tf
.
glob
al_variables
_initializer
())
saver
=
tf
.
train
.
Saver
(
max_to_keep
=
10
)
saver
=
tf
.
train
.
Saver
(
max_to_keep
=
10
)
ckpt
=
None
ckpt
=
None
...
...
swivel/swivel.py
View file @
3f74c7b4
...
@@ -307,8 +307,9 @@ class SwivelModel(object):
...
@@ -307,8 +307,9 @@ class SwivelModel(object):
with
tf
.
device
(
'/cpu:0'
):
with
tf
.
device
(
'/cpu:0'
):
# ===== MERGE LOSSES =====
# ===== MERGE LOSSES =====
l2_loss
=
tf
.
reduce_mean
(
tf
.
concat
(
l2_losses
,
0
),
0
,
name
=
"l2_loss"
)
l2_loss
=
tf
.
reduce_mean
(
tf
.
concat
(
axis
=
0
,
values
=
l2_losses
),
0
,
sigmoid_loss
=
tf
.
reduce_mean
(
tf
.
concat
(
sigmoid_losses
,
0
),
0
,
name
=
"l2_loss"
)
sigmoid_loss
=
tf
.
reduce_mean
(
tf
.
concat
(
axis
=
0
,
values
=
sigmoid_losses
),
0
,
name
=
"sigmoid_loss"
)
name
=
"sigmoid_loss"
)
self
.
loss
=
l2_loss
+
sigmoid_loss
self
.
loss
=
l2_loss
+
sigmoid_loss
average
=
tf
.
train
.
ExponentialMovingAverage
(
0.8
,
self
.
global_step
)
average
=
tf
.
train
.
ExponentialMovingAverage
(
0.8
,
self
.
global_step
)
...
...
textsum/seq2seq_lib.py
View file @
3f74c7b4
...
@@ -42,8 +42,8 @@ def sequence_loss_by_example(inputs, targets, weights, loss_function,
...
@@ -42,8 +42,8 @@ def sequence_loss_by_example(inputs, targets, weights, loss_function,
if
len
(
targets
)
!=
len
(
inputs
)
or
len
(
weights
)
!=
len
(
inputs
):
if
len
(
targets
)
!=
len
(
inputs
)
or
len
(
weights
)
!=
len
(
inputs
):
raise
ValueError
(
'Lengths of logits, weights, and targets must be the same '
raise
ValueError
(
'Lengths of logits, weights, and targets must be the same '
'%d, %d, %d.'
%
(
len
(
inputs
),
len
(
weights
),
len
(
targets
)))
'%d, %d, %d.'
%
(
len
(
inputs
),
len
(
weights
),
len
(
targets
)))
with
tf
.
op
_scope
(
inputs
+
targets
+
weights
,
name
,
with
tf
.
name
_scope
(
values
=
inputs
+
targets
+
weights
,
name
=
name
,
'sequence_loss_by_example'
):
default_name
=
'sequence_loss_by_example'
):
log_perp_list
=
[]
log_perp_list
=
[]
for
inp
,
target
,
weight
in
zip
(
inputs
,
targets
,
weights
):
for
inp
,
target
,
weight
in
zip
(
inputs
,
targets
,
weights
):
crossent
=
loss_function
(
inp
,
target
)
crossent
=
loss_function
(
inp
,
target
)
...
@@ -77,7 +77,8 @@ def sampled_sequence_loss(inputs, targets, weights, loss_function,
...
@@ -77,7 +77,8 @@ def sampled_sequence_loss(inputs, targets, weights, loss_function,
Raises:
Raises:
ValueError: If len(inputs) is different from len(targets) or len(weights).
ValueError: If len(inputs) is different from len(targets) or len(weights).
"""
"""
with
tf
.
op_scope
(
inputs
+
targets
+
weights
,
name
,
'sampled_sequence_loss'
):
with
tf
.
name_scope
(
values
=
inputs
+
targets
+
weights
,
name
=
name
,
default_name
=
'sampled_sequence_loss'
):
cost
=
tf
.
reduce_sum
(
sequence_loss_by_example
(
cost
=
tf
.
reduce_sum
(
sequence_loss_by_example
(
inputs
,
targets
,
weights
,
loss_function
,
inputs
,
targets
,
weights
,
loss_function
,
average_across_timesteps
=
average_across_timesteps
))
average_across_timesteps
=
average_across_timesteps
))
...
...
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