Exemple #1
0
    def testDistributedReplicatedSavableVars(self):
        test_util.monkey_patch_base_cluster_manager()
        params = benchmark_cnn.make_params(
            variable_update='distributed_replicated',
            model='inception4',
            data_name='imagenet',
            data_dir=os.path.join(platforms_util.get_test_data_dir(),
                                  'fake_tf_record_data'),
            job_name='worker',
            worker_hosts='w1,w2,w3,w4',
            ps_hosts='p1')

        bench = benchmark_cnn.BenchmarkCNN(params)
        with tf.Graph().as_default():
            bench._build_model()
            savable_vars = bench.variable_mgr.savable_variables()
            # Assert all global variables are in savable_vars
            for v in tf.global_variables():
                if not v.name.startswith(
                        variable_mgr_util.PS_SHADOW_VAR_PREFIX + '/v0'):
                    self.assertEqual(v.name, 'global_step:0')
                name = bench.variable_mgr._strip_port(v.name)
                if name.startswith(variable_mgr_util.PS_SHADOW_VAR_PREFIX):
                    name = name[len(variable_mgr_util.PS_SHADOW_VAR_PREFIX +
                                    '/'):]
                self.assertIn(name, savable_vars)
                self.assertIn(savable_vars[name], tf.global_variables())
            # Assert all local variables on the first tower are in savable_vars
            for v in tf.local_variables():
                if v.name.startswith('v0/'):
                    name = bench.variable_mgr._strip_port(v.name)
                    self.assertIn(name, savable_vars)
Exemple #2
0
 def testPreprocessingTrain(self):
     test_data_dir = os.path.join(platforms_util.get_test_data_dir(),
                                  'images')
     black_file = os.path.join(test_data_dir, 'black_image.jpg')
     with open(black_file, 'r') as f:
         black_jpg_buffer = f.read()
     white_file = os.path.join(test_data_dir, 'white_image.jpg')
     with open(white_file, 'r') as f:
         white_jpg_buffer = f.read()
     bbox = tf.zeros((1, 0, 4), dtype=tf.float32)
     batch_position = 0
     # Each size config is (output_height, output_width, resize_method)
     size_configs = [(100, 100, 'round_robin'), (150, 10, 'bilinear'),
                     (10, 150, 'nearest')]
     # Each image config is (image_buf, image_color)
     image_configs = [(white_jpg_buffer, 255), (black_jpg_buffer, 0)]
     for (image_buf, image_color) in image_configs:
         for output_height, output_width, resize_method in size_configs:
             for distortions in [True, False]:
                 for summary_verbosity in [0, 2]:
                     for fuse_decode_and_crop in [True, False]:
                         self._test_preprocessing_traing(
                             image_buf, image_color, output_height,
                             output_width, bbox, batch_position,
                             resize_method, distortions, summary_verbosity,
                             fuse_decode_and_crop)
Exemple #3
0
 def testImagenetPreprocessorNoDistortions(self):
     imagenet_dir = os.path.join(platforms_util.get_test_data_dir(),
                                 'fake_tf_record_data')
     params = test_util.get_params(
         'testImagenetPreprocessorNoDistortions')._replace(
             data_dir=imagenet_dir, data_name='imagenet', distortions=False)
     self._train_and_eval_local(params, use_test_preprocessor=False)
 def testReplicatedRealData(self):
     test_name = 'testReplicatedRealData'
     imagenet_dir = os.path.join(platforms_util.get_test_data_dir(),
                                 'fake_tf_record_data')
     params = test_util.get_params(test_name)._replace(
         variable_update='distributed_replicated',
         data_dir=imagenet_dir,
         data_name='imagenet')
     self._test_distributed(test_name, 2, 2, params)
Exemple #5
0
    def __init__(self, output_dir=None):
        # Load default values if the benchmark is not run with absl.app.run()
        if not flags.FLAGS.is_parsed():
            flags.FLAGS.mark_as_parsed()

        self.fake_data_dir = os.path.join(platforms_util.get_test_data_dir(),
                                          'fake_tf_record_data')
        self.data_dir = ('/readahead/200M/placer/prod/home/distbelief/'
                         'imagenet-tensorflow/imagenet-2012-tfrecord')
        self.output_dir = output_dir
Exemple #6
0
 def testOfficialImagenetPreprocessorFp16(self):
   imagenet_dir = os.path.join(platforms_util.get_test_data_dir(),
                               'fake_tf_record_data')
   params = test_util.get_params(
       'testOfficialImagenetPreprocessorFp16')._replace(
           data_dir=imagenet_dir,
           data_name='imagenet',
           input_preprocessor='official_models_imagenet',
           use_fp16=True)
   self._train_and_eval_local(params, use_test_preprocessor=False)
Exemple #7
0
 def testShiftRatio(self):
   test_util.monkey_patch_base_cluster_manager()
   params = benchmark_cnn.make_params(
       data_name='imagenet',
       data_dir=os.path.join(platforms_util.get_test_data_dir(),
                             'fake_tf_record_data'),
       job_name='worker',
       worker_hosts='w1,w2,w3,w4',
       ps_hosts='p1',
       task_index=0)
   self.assertEqual(
       benchmark_cnn.BenchmarkCNN(params).image_preprocessor.shift_ratio, 0.0)
   params = params._replace(task_index=3)
   self.assertEqual(
       benchmark_cnn.BenchmarkCNN(params).image_preprocessor.shift_ratio, 0.75)
Exemple #8
0
    def __init__(self, output_dir=None, root_data_dir=None):
        """Base class for all benchmarks in this file.

    Args:
      output_dir: directory where to output e.g. log files
      root_data_dir: directory under which to look for dataset
    """

        # Load default values if the benchmark is not run with absl.app.run()
        if not flags.FLAGS.is_parsed():
            flags.FLAGS.mark_as_parsed()

        self.fake_data_dir = os.path.join(platforms_util.get_test_data_dir(),
                                          'fake_tf_record_data')

        if root_data_dir is None:
            self.data_dir = ('/readahead/200M/placer/prod/home/distbelief/'
                             'imagenet-tensorflow/imagenet-2012-tfrecord')
        else:
            self.data_dir = os.path.join(root_data_dir, 'imagenet')
        self.output_dir = output_dir
Exemple #9
0
    def __init__(self, output_dir=None, root_data_dir=None, **kwargs):
        """Base class for all benchmarks in this file.

    Args:
      output_dir: directory where to output e.g. log files
      root_data_dir: directory under which to look for dataset
      **kwargs: arbitrary named arguments. This is needed to make the
                constructor forward compatible in case PerfZero provides more
                named arguments before updating the constructor.
    """

        # Load default values if the benchmark is not run with absl.app.run()
        if not flags.FLAGS.is_parsed():
            flags.FLAGS.mark_as_parsed()

        self.fake_data_dir = os.path.join(platforms_util.get_test_data_dir(),
                                          'fake_tf_record_data')
        self.output_dir = output_dir
        if root_data_dir is None:
            self.data_dir = ('/readahead/200M/placer/prod/home/distbelief/'
                             'imagenet-tensorflow/imagenet-2012-tfrecord')
        else:
            self.data_dir = os.path.join(root_data_dir, 'imagenet')