17
17
See the README for more information.
18
18
"""
19
19
20
- from __future__ import absolute_import
21
- from __future__ import division
22
- from __future__ import print_function
23
-
24
20
import argparse
25
21
from collections import namedtuple
26
22
import contextlib
34
30
35
31
from absl import flags as absl_flags
36
32
import numpy as np
37
-
38
- import six
39
- from six .moves import xrange # pylint: disable=redefined-builtin
40
33
import tensorflow .compat .v1 as tf
41
34
42
35
# pylint: disable=g-direct-tensorflow-import
54
47
from tensorflow .core .protobuf import rewriter_config_pb2
55
48
from tensorflow .python import debug as tf_debug
56
49
from tensorflow .python .client import timeline
57
- from tensorflow .python .framework import graph_util
50
+ from tensorflow .python .framework import convert_to_constants
58
51
from tensorflow .python .framework import graph_util_impl
59
52
from tensorflow .python .framework import importer
60
53
from tensorflow .python .ops import data_flow_ops
@@ -1526,7 +1519,7 @@ def __init__(self, params, dataset=None, model=None):
1526
1519
# compute device, and never on a parameter server device.
1527
1520
self .raw_devices = [
1528
1521
'%s/%s:%i' % (worker_prefix , self .params .device , i )
1529
- for i in xrange (self .num_gpus )
1522
+ for i in range (self .num_gpus )
1530
1523
]
1531
1524
1532
1525
subset = 'validation' if params .eval else 'train'
@@ -1747,7 +1740,7 @@ def reset_devices_for_task(self, task_num, is_local=False):
1747
1740
self .cpu_device = '%s/cpu:0' % worker_prefix
1748
1741
self .raw_devices = [
1749
1742
'%s/%s:%i' % (worker_prefix , self .params .device , i )
1750
- for i in xrange (self .num_gpus )
1743
+ for i in range (self .num_gpus )
1751
1744
]
1752
1745
self .devices = self .variable_mgr .get_devices ()
1753
1746
@@ -1759,8 +1752,8 @@ def raw_devices_across_tasks(self, is_local=False):
1759
1752
else :
1760
1753
return [
1761
1754
'job:worker/replica:0/task%s/%s:%i' % (t , self .params .device , i )
1762
- for t in xrange (self .num_workers )
1763
- for i in xrange (self .num_gpus )
1755
+ for t in range (self .num_workers )
1756
+ for i in range (self .num_gpus )
1764
1757
]
1765
1758
1766
1759
def print_info (self ):
@@ -1985,7 +1978,7 @@ def _initialize_eval_graph(self, enqueue_ops, input_producer_op,
1985
1978
self .params .use_python32_barrier )
1986
1979
image_producer .start ()
1987
1980
if enqueue_ops :
1988
- for i in xrange (len (enqueue_ops )):
1981
+ for i in range (len (enqueue_ops )):
1989
1982
sess .run (enqueue_ops [:(i + 1 )])
1990
1983
if image_producer is not None :
1991
1984
image_producer .notify_image_consumption ()
@@ -2003,7 +1996,7 @@ def _eval_once(self, sess, summary_writer, fetches, summary_op,
2003
1996
top_1_accuracy_sum = 0.0
2004
1997
top_5_accuracy_sum = 0.0
2005
1998
total_eval_count = self .num_batches * self .batch_size
2006
- for step in xrange (self .num_batches ):
1999
+ for step in range (self .num_batches ):
2007
2000
if (summary_writer and self .params .save_summaries_steps > 0 and
2008
2001
(step + 1 ) % self .params .save_summaries_steps == 0 ):
2009
2002
results , summary_str = sess .run ([fetches , summary_op ])
@@ -2339,7 +2332,7 @@ def benchmark_with_session(self, sess, supervisor, graph_info,
2339
2332
self .params .use_python32_barrier )
2340
2333
image_producer .start ()
2341
2334
if graph_info .enqueue_ops :
2342
- for i in xrange (len (graph_info .enqueue_ops )):
2335
+ for i in range (len (graph_info .enqueue_ops )):
2343
2336
sess .run (graph_info .enqueue_ops [:(i + 1 )])
2344
2337
if image_producer is not None :
2345
2338
image_producer .notify_image_consumption ()
@@ -2617,7 +2610,7 @@ def _preprocess_graph(self, graph, graph_info):
2617
2610
with tf .Session (config = create_config_proto (self .params )) as sess :
2618
2611
sess .run (tf .global_variables_initializer ())
2619
2612
sess .run (tf .local_variables_initializer ())
2620
- graphdef = graph_util .convert_variables_to_constants (
2613
+ graphdef = convert_to_constants .convert_variables_to_constants (
2621
2614
sess ,
2622
2615
graphdef ,
2623
2616
output_node_names ,
@@ -2749,7 +2742,7 @@ def _build_input_processing(self, shift_ratio=0):
2749
2742
shared_name = 'input_producer_staging_area_%d_eval_%s' %
2750
2743
(device_num , self ._doing_eval ))
2751
2744
input_producer_stages .append (staging_area )
2752
- for group_index in xrange (self .batch_group_size ):
2745
+ for group_index in range (self .batch_group_size ):
2753
2746
batch_index = group_index + device_num * self .batch_group_size
2754
2747
put_op = staging_area .put (
2755
2748
[parts [batch_index ] for parts in input_list ])
@@ -2868,7 +2861,8 @@ def _build_model(self):
2868
2861
if self .variable_mgr .supports_staged_vars ():
2869
2862
for staging_ops in self .variable_mgr .staging_vars_on_devices :
2870
2863
gpu_compute_stage_ops .extend (
2871
- [put_op for _ , (put_op , _ ) in six .iteritems (staging_ops )])
2864
+ [put_op for _ , (put_op , _ ) in staging_ops .items ()]
2865
+ )
2872
2866
enqueue_ops .append (tf .group (* gpu_compute_stage_ops ,
2873
2867
name = 'gpu_compute_stage_ops_group' ))
2874
2868
if gpu_grad_stage_ops :
0 commit comments