Exemplo n.º 1
0
def get_inspection_units(logdir="", event_file="", tag=""):
    """Returns a list of InspectionUnit objects given either logdir or event_file.

  If logdir is given, the number of InspectionUnits should equal the
  number of directories or subdirectories that contain event files.

  If event_file is given, the number of InspectionUnits should be 1.

  Args:
    logdir: A log directory that contains event files.
    event_file: Or, a particular event file path.
    tag: An optional tag name to query for.

  Returns:
    A list of InspectionUnit objects.
  """
    if logdir:
        subdirs = io_wrapper.GetLogdirSubdirectories(logdir)
        inspection_units = []
        for subdir in subdirs:
            generator = itertools.chain(
                *[
                    generator_from_event_file(os.path.join(subdir, f))
                    for f in tf.io.gfile.listdir(subdir)
                    if io_wrapper.IsTensorFlowEventsFile(os.path.join(subdir, f))
                ]
            )
            inspection_units.append(
                InspectionUnit(
                    name=subdir,
                    generator=generator,
                    field_to_obs=get_field_to_observations_map(generator, tag),
                )
            )
        if inspection_units:
            print(
                "Found event files in:\n{}\n".format(
                    "\n".join([u.name for u in inspection_units])
                )
            )
        elif io_wrapper.IsTensorFlowEventsFile(logdir):
            print(
                "It seems that {} may be an event file instead of a logdir. If this "
                "is the case, use --event_file instead of --logdir to pass "
                "it in.".format(logdir)
            )
        else:
            print("No event files found within logdir {}".format(logdir))
        return inspection_units
    elif event_file:
        generator = generator_from_event_file(event_file)
        return [
            InspectionUnit(
                name=event_file,
                generator=generator,
                field_to_obs=get_field_to_observations_map(generator, tag),
            )
        ]
    return []
Exemplo n.º 2
0
def generators_from_logdir(logdir):
    """Returns a list of event generators for subdirectories with event files.

  The number of generators returned should equal the number of directories
  within logdir that contain event files. If only logdir contains event files,
  returns a list of length one.

  Args:
    logdir: A log directory that contains event files.

  Returns:
    List of event generators for each subdirectory with event files.
  """
    subdirs = io_wrapper.GetLogdirSubdirectories(logdir)
    generators = [
        itertools.chain(
            *[
                generator_from_event_file(os.path.join(subdir, f))
                for f in tf.io.gfile.listdir(subdir)
                if io_wrapper.IsTensorFlowEventsFile(os.path.join(subdir, f))
            ]
        )
        for subdir in subdirs
    ]
    return generators
Exemplo n.º 3
0
def _GeneratorFromPath(path):
    """Create an event generator for file or directory at given path string."""
    if not path:
        raise ValueError('path must be a valid string')
    if io_wrapper.IsTensorFlowEventsFile(path):
        return event_file_loader.EventFileLoader(path)
    else:
        return directory_watcher.DirectoryWatcher(
            path, event_file_loader.EventFileLoader,
            io_wrapper.IsTensorFlowEventsFile)
Exemplo n.º 4
0
def _GeneratorFromPath(path, event_file_active_filter=None):
    """Create an event generator for file or directory at given path string."""
    if not path:
        raise ValueError("path must be a valid string")
    if io_wrapper.IsTensorFlowEventsFile(path):
        return event_file_loader.EventFileLoader(path)
    elif event_file_active_filter:
        return directory_loader.DirectoryLoader(
            path,
            event_file_loader.TimestampedEventFileLoader,
            path_filter=io_wrapper.IsTensorFlowEventsFile,
            active_filter=event_file_active_filter,
        )
    else:
        return directory_watcher.DirectoryWatcher(
            path, event_file_loader.EventFileLoader,
            io_wrapper.IsTensorFlowEventsFile)
Exemplo n.º 5
0
 def testIsIsTensorFlowEventsFileWithEmptyInput(self):
     with six.assertRaisesRegex(self, ValueError,
                                r'Path must be a nonempty string'):
         io_wrapper.IsTensorFlowEventsFile('')
Exemplo n.º 6
0
 def testIsIsTensorFlowEventsFileFalse(self):
     self.assertFalse(
         io_wrapper.IsTensorFlowEventsFile('/logdir/model.ckpt'))
Exemplo n.º 7
0
 def testIsIsTensorFlowEventsFileTrue(self):
     self.assertTrue(
         io_wrapper.IsTensorFlowEventsFile(
             '/logdir/events.out.tfevents.1473720042.com'))
Exemplo n.º 8
0
 def testIsTensorFlowEventsFilesReturnsTrueForProfileEmptyEventsFiles(self):
     self.assertTrue(
         io_wrapper.IsTensorFlowEventsFile(
             "/logdir/events.out.tfevents.1473720042.alice.profile-empty"))
Exemplo n.º 9
0
 def testIsIsTensorFlowEventsFileWithEmptyInput(self):
     with self.assertRaisesRegex(
         ValueError, r"Path must be a nonempty string"
     ):
         io_wrapper.IsTensorFlowEventsFile("")