예제 #1
0
    def __init__(self, directory):
        config_file = os.path.join(directory, "config.yaml")
        if not os.path.isfile(config_file):
            raise WorkspaceException("Workspace not initialized")

        with open(config_file, 'r') as fp:
            self._config = yaml.load(fp, Loader=yaml.BaseLoader)

        if not "stack" in self._config:
            raise WorkspaceException(
                "Experiment stack not found in workspace configuration")

        stack_file = resolve_stack(self._config["stack"], directory)

        if stack_file is None:
            raise WorkspaceException("Experiment stack does not exist")

        with open(stack_file, 'r') as fp:
            stack_metadata = yaml.load(fp, Loader=yaml.BaseLoader)
            self._stack = Stack(self, stack_metadata)

        dataset_directory = normalize_path(
            self._config.get("sequences", "sequences"), directory)
        results_directory = normalize_path(
            self._config.get("results", "results"), directory)
        cache_directory = normalize_path("cache", directory)

        self._download(dataset_directory)

        self._dataset = VOTDataset(dataset_directory)
        self._results = results_directory
        self._cache = cache_directory

        self._root = directory
예제 #2
0
    def initialize(directory, config=dict(), download=True):
        config_file = os.path.join(directory, "config.yaml")
        if os.path.isfile(config_file):
            raise WorkspaceException("Workspace already initialized")

        os.makedirs(directory, exist_ok=True)

        with open(config_file, 'w') as fp:
            yaml.dump(config, fp)

        os.makedirs(os.path.join(directory, "sequences"), exist_ok=True)
        os.makedirs(os.path.join(directory, "results"), exist_ok=True)

        if not os.path.isfile(os.path.join(directory, "trackers.ini")):
            open(os.path.join(directory, "trackers.ini"), 'w').close()

        if download:
            # Try do retrieve dataset from stack and download it
            stack_file = resolve_stack(config["stack"], directory)
            dataset_directory = normalize_path(
                config.get("sequences", "sequences"), directory)
            if stack_file is None:
                return
            dataset = None
            with open(stack_file, 'r') as fp:
                stack_metadata = yaml.load(fp, Loader=yaml.BaseLoader)
                dataset = stack_metadata["dataset"]
            if dataset:
                Workspace.download_dataset(dataset, dataset_directory)
예제 #3
0
    def load(directory):
        directory = normalize_path(directory)
        config_file = os.path.join(directory, "config.yaml")
        if not os.path.isfile(config_file):
            raise WorkspaceException("Workspace not initialized")

        with open(config_file, 'r') as fp:
            config = yaml.load(fp, Loader=yaml.BaseLoader)

            return Workspace(directory, **config)
예제 #4
0
    def __init__(self, directory, **kwargs):
        self._directory = directory
        self._storage = LocalStorage(directory) if directory is not None else VoidStorage()
        super().__init__(**kwargs)
        dataset_directory = normalize_path(self.sequences, directory)

        if not self.stack.dataset is None:
            Workspace.download_dataset(self.stack.dataset, dataset_directory)

        self._dataset = VOTDataset(dataset_directory)
예제 #5
0
    def __init__(self, directory):
        self._root = directory
        directory = normalize_path(directory)
        config_file = os.path.join(directory, "config.yaml")
        if not os.path.isfile(config_file):
            raise WorkspaceException("Workspace not initialized")

        with open(config_file, 'r') as fp:
            self._config = yaml.load(fp, Loader=yaml.BaseLoader)

        if not "stack" in self._config:
            raise WorkspaceException(
                "Experiment stack not found in workspace configuration")

        stack_file = resolve_stack(self._config["stack"], directory)

        if stack_file is None:
            raise WorkspaceException("Experiment stack does not exist")

        self._storage = LocalStorage(directory)

        with open(stack_file, 'r') as fp:
            stack_metadata = yaml.load(fp, Loader=yaml.BaseLoader)
            self._stack = Stack(self, **stack_metadata)

        dataset_directory = normalize_path(
            self._config.get("sequences", "sequences"), directory)

        if not self._stack.dataset is None:
            Workspace.download_dataset(self._stack.dataset, dataset_directory)

        self._dataset = VOTDataset(dataset_directory)
        self._registry = [
            normalize_path(r, directory)
            for r in self._config.get("registry", [])
        ]
예제 #6
0
def normalize_paths(paths, tracker):
    root = os.path.dirname(tracker.source)
    return [normalize_path(path, root) for path in paths]
예제 #7
0
def do_test(config, logger):
    from vot.dataset.dummy import DummySequence
    from vot.dataset.vot import VOTSequence
    trackers = load_trackers(config.registry)

    if not config.tracker:
        logger.error("Unable to continue without a tracker")
        logger.error("List of available found trackers: ")
        for k, _ in trackers.items():
            logger.error(" * %s", k)
        return

    if not config.tracker in trackers:
        logger.error("Tracker does not exist")
        return

    tracker = trackers[config.tracker]

    logger.info("Generating dummy sequence")

    if config.sequence is None:
        sequence = DummySequence(50)
    else:
        sequence = VOTSequence(normalize_path(config.sequence))

    logger.info("Obtaining runtime for tracker %s", tracker.identifier)

    if config.visualize:
        import matplotlib.pylab as plt
        from vot.utilities.draw import MatplotlibDrawHandle
        figure = plt.figure()
        figure.canvas.set_window_title('VOT Test')
        axes = figure.add_subplot(1, 1, 1)
        axes.set_aspect("equal")
        handle = MatplotlibDrawHandle(axes, size=sequence.size)
        handle.style(fill=False)
        figure.show()

    runtime = None

    try:

        runtime = tracker.runtime(log=True)

        for repeat in range(1, 4):

            logger.info("Initializing tracker ({}/{})".format(repeat, 3))

            region, _, _ = runtime.initialize(sequence.frame(0),
                                              sequence.groundtruth(0))

            if config.visualize:
                axes.clear()
                handle.image(sequence.frame(0).channel())
                handle.style(color="green").region(
                    sequence.frame(0).groundtruth())
                handle.style(color="red").region(region)
                figure.canvas.draw()

            for i in range(1, sequence.length):
                logger.info("Updating on frame %d/%d", i, sequence.length - 1)
                region, _, _ = runtime.update(sequence.frame(i))

                if config.visualize:
                    axes.clear()
                    handle.image(sequence.frame(i).channel())
                    handle.style(color="green").region(
                        sequence.frame(i).groundtruth())
                    handle.style(color="red").region(region)
                    figure.canvas.draw()

            logger.info("Stopping tracker")

        runtime.stop()

        logger.info("Test concluded successfuly")

    except TrackerException as te:
        logger.error("Error during tracker execution: {}".format(te))
        if runtime:
            runtime.stop()
    except KeyboardInterrupt:
        if runtime:
            runtime.stop()
예제 #8
0
class Workspace(Attributee):

    registry = List(
        String(transformer=lambda x, ctx: normalize_path(
            x, ctx["parent"].directory)))
    stack = StackLoader()
    sequences = String(default="sequences")
    report = Nested(ReportConfiguration)

    @staticmethod
    def initialize(directory, config=None, download=False):
        config_file = os.path.join(directory, "config.yaml")
        if os.path.isfile(config_file):
            raise WorkspaceException("Workspace already initialized")

        os.makedirs(directory, exist_ok=True)

        with open(config_file, 'w') as fp:
            yaml.dump(config if config is not None else dict(), fp)

        os.makedirs(os.path.join(directory, "sequences"), exist_ok=True)
        os.makedirs(os.path.join(directory, "results"), exist_ok=True)

        if not os.path.isfile(os.path.join(directory, "trackers.ini")):
            open(os.path.join(directory, "trackers.ini"), 'w').close()
        download = False
        if download:
            # Try do retrieve dataset from stack and download it
            stack_file = resolve_stack(config["stack"], directory)
            dataset_directory = normalize_path(
                config.get("sequences", "sequences"), directory)
            if stack_file is None:
                return
            dataset = None
            with open(stack_file, 'r') as fp:
                stack_metadata = yaml.load(fp, Loader=yaml.BaseLoader)
                dataset = stack_metadata["dataset"]
            if dataset:
                Workspace.download_dataset(dataset, dataset_directory)

    @staticmethod
    def download_dataset(dataset, directory):
        if os.path.exists(os.path.join(directory, "list.txt")):
            return False

        from vot.dataset import download_dataset
        download_dataset(dataset, directory)

        logger.info("Download completed")

    @staticmethod
    def load(directory):
        directory = normalize_path(directory)
        config_file = os.path.join(directory, "config.yaml")
        if not os.path.isfile(config_file):
            raise WorkspaceException("Workspace not initialized")

        with open(config_file, 'r') as fp:
            config = yaml.load(fp, Loader=yaml.BaseLoader)

            return Workspace(directory, **config)

    def __init__(self, directory, **kwargs):
        self._directory = directory
        self._storage = LocalStorage(
            directory) if directory is not None else VoidStorage()
        super().__init__(**kwargs)
        dataset_directory = normalize_path(self.sequences, directory)

        if not self.stack.dataset is None:
            Workspace.download_dataset(self.stack.dataset, dataset_directory)

        self._dataset = VOTDataset(dataset_directory)

    @property
    def directory(self) -> str:
        return self._directory

    @property
    def dataset(self) -> Dataset:
        return self._dataset

    @property
    def storage(self) -> LocalStorage:
        return self._storage

    def cache(self, identifier) -> LocalStorage:
        if not isinstance(identifier, str):
            identifier = class_fullname(identifier)

        return self._storage.substorage("cache").substorage(identifier)

    def list_results(self, registry: "Registry"):
        references = self._storage.substorage("results").folders()
        return registry.resolve(*references)