예제 #1
0
def main():
    lab = Lab(os.getcwd())
    parser = argparse.ArgumentParser(description='Run TensorBoard')
    parser.add_argument("-l",
                        action='store_true',
                        dest='list',
                        help='List all available experiments')
    parser.add_argument('-e',
                        required=False,
                        type=str,
                        nargs='+',
                        dest='experiments',
                        help='List of experiments')

    args = parser.parse_args()

    logger = Logger()

    if args.list:
        utils.list_experiments(lab, logger)
    elif args.experiments:
        # List out the experiments.
        # This will fail if experiments are missing.
        runs = utils.get_last_trials(lab, args.experiments)
        utils.list_trials(runs, logger)

        # Invoke Tensorboard
        cmd = utils.get_tensorboard_cmd(lab, args.experiments)
        logger.log("Starting TensorBoard", color=colors.Style.bold)
        os.system(cmd)
    else:
        parser.print_usage()
예제 #2
0
파일: __init__.py 프로젝트: bourbakis/lab
    def __init__(self, *, name: str, python_file: str, comment: str,
                 check_repo_dirty: Optional[bool],
                 is_log_python_file: Optional[bool]):
        """
        ### Create the experiment

        :param name: name of the experiment
        :param python_file: `__file__` that invokes this. This is stored in
         the experiments list.
        :param comment: a short description of the experiment
        :param check_repo_dirty: whether not to start the experiment if
         there are uncommitted changes.

        The experiments log keeps track of `python_file`, `name`, `comment` as
         well as the git commit.

        Experiment maintains the locations of checkpoints, logs, etc.
        """

        self.lab = Lab(python_file)

        if check_repo_dirty is None:
            check_repo_dirty = self.lab.check_repo_dirty
        if is_log_python_file is None:
            is_log_python_file = self.lab.is_log_python_file

        self.info = ExperimentInfo(self.lab, name)

        self.check_repo_dirty = check_repo_dirty

        experiment_path = pathlib.Path(self.info.experiment_path)
        if not experiment_path.exists():
            experiment_path.mkdir(parents=True)

        self.trial = Trial.new_trial(python_file=python_file,
                                     trial_time=time.localtime(),
                                     comment=comment)

        repo = git.Repo(self.lab.path)

        self.trial.commit = repo.head.commit.hexsha
        self.trial.commit_message = repo.head.commit.message.strip()
        self.trial.is_dirty = repo.is_dirty()
        self.trial.diff = repo.git.diff()
        self.__progress_saver = _ExperimentProgressSaver(
            trial=self.trial,
            trials_log_file=self.info.trials_log_file,
            is_log_python_file=is_log_python_file)

        checkpoint_saver = self._create_checkpoint_saver()
        self.logger = Logger(progress_saver=self.__progress_saver,
                             checkpoint_saver=checkpoint_saver)
예제 #3
0
def list_experiments(lab: Lab, logger: Logger):
    experiments = lab.get_experiments()
    names = [e.name for e in experiments]
    names.sort()
    logger.info(names)
예제 #4
0
    def __init__(self, *,
                 name: Optional[str],
                 python_file: Optional[str],
                 comment: Optional[str],
                 writers: Set[str] = None):
        """
        ### Create the experiment

        :param name: name of the experiment
        :param python_file: `__file__` that invokes this. This is stored in
         the experiments list.
        :param comment: a short description of the experiment

        The experiments log keeps track of `python_file`, `name`, `comment` as
         well as the git commit.

        Experiment maintains the locations of checkpoints, logs, etc.
        """

        if python_file is None:
            python_file = self.__get_caller_file()

        if python_file.startswith('<ipython'):
            assert is_ipynb()
            if name is None:
                raise ValueError("You must specify python_file or experiment name"
                                 " when creating an experiment from a python notebook.")
            self.lab = Lab(os.getcwd())
            python_file = 'notebook.ipynb'
        else:
            self.lab = Lab(python_file)

            if name is None:
                file_path = pathlib.PurePath(python_file)
                name = file_path.stem

        logger.internal().set_data_path(self.lab.data_path)

        if comment is None:
            comment = ''

        self.name = name
        self.experiment_path = self.lab.experiments / name

        self.check_repo_dirty = self.lab.check_repo_dirty

        self.configs_processor = None

        experiment_path = pathlib.Path(self.experiment_path)
        if not experiment_path.exists():
            experiment_path.mkdir(parents=True)

        self.run = Run.create(
            experiment_path=self.experiment_path,
            python_file=python_file,
            trial_time=time.localtime(),
            comment=comment)

        repo = git.Repo(self.lab.path)

        self.run.commit = repo.head.commit.hexsha
        self.run.commit_message = repo.head.commit.message.strip()
        self.run.is_dirty = repo.is_dirty()
        self.run.diff = repo.git.diff()

        checkpoint_saver = self._create_checkpoint_saver()
        logger.internal().set_checkpoint_saver(checkpoint_saver)

        if writers is None:
            writers = {'sqlite', 'tensorboard'}

        if 'sqlite' in writers:
            logger.internal().add_writer(sqlite.Writer(self.run.sqlite_path))
        if 'tensorboard' in writers:
            logger.internal().add_writer(tensorboard.Writer(self.run.tensorboard_log_path))

        logger.internal().set_numpy_path(self.run.numpy_path)
예제 #5
0
 def __get_lab():
     return Lab(os.getcwd())
    from sys import path

    path.append(dir(path[0]))
    __package__ = 'lista4'

from lab.experiments import Experiment
from lab.lab import Lab

from lista4.conv import ConvMNIST

if __name__ == "__main__":
    REPS = 10

    lab = Lab(
        ConvMNIST,
        REPS,
        'lista4/wyniki',
    )

    # Kernel size
    ker = Experiment(
        title='kernel',
        f_name='kernel',
        test_parameter=(
            'kernel_size',
            [
                3,
                5,
                7,
            ],
        ),
예제 #7
0
def experiments() -> None:
    REPS = 10

    lab = Lab(
        MNISTMLP,
        REPS,
        'lista2/wyniki',
        hidden_size=128,
        batch_size=32,
        weights_range=(-0.5, 0.5),
        alpha=0.01,
        activation_name='relu',
    )

    # Hidden size
    h_size = Experiment(
        title='h_size',
        f_name='h_size_1024',
        test_parameter=(
            'hidden_size',
            [
                16,
                128,
                512,
                2048,
            ],
        ),
    )
    lab.add_experiment(h_size)
    # Alpha
    alpha = Experiment(
        title='alpha',
        f_name='alpha_1024',
        test_parameter=(
            'alpha',
            [
                0.0001,
                0.001,
                0.01,
                0.1,
                1.0,
            ],
        ),
    )
    lab.add_experiment(alpha)
    # Weight range
    w_range = Experiment(
        title='w_range',
        f_name='w_range_1024',
        test_parameter=(
            'weights_range',
            [
                (0.0, 0.0),
                (-0.1, 0.1),
                (-0.5, 0.5),
                (-2.0, 2.0),
            ],
        ),
    )
    lab.add_experiment(w_range)
    # Batch
    batch_size = Experiment(
        title='batch_size',
        f_name='batch_size_1024',
        test_parameter=(
            'batch_size',
            [
                1,
                8,
                32,
                128,
                1024,
            ],
        ),
    )
    lab.add_experiment(batch_size)
    # ReLU
    activation = Experiment(
        title='activation',
        f_name='activation_1024',
        test_parameter=(
            'activation_name',
            [
                'sigmoid',
                'relu',
            ],
        ),
    )
    lab.add_experiment(activation)

    lab.run()
예제 #8
0
from pathlib import PurePath

from lab.lab import Lab

# Create a lab with the path of the project
lab = Lab(path=PurePath(__file__).parent)
    path.append(dir(path[0]))
    __package__ = 'lista3'

from lab.experiments import Experiment
from lab.lab import Lab

from lista3.optim_mlp import OptimMNISTMLP

if __name__ == "__main__":
    REPS = 10

    lab = Lab(
        OptimMNISTMLP,
        REPS,
        'lista3/wyniki',
        activation_name='relu',
        optimizer_name='sgd',
        initializer_name='range',
        alpha=0.01,
    )

    # Base
    base = Experiment(
        title='base',
        f_name='base',
        test_parameter=(
            'activation_name',
            [
                'relu',
                'sigmoid',
            ],
def experiments() -> None:
    REPS = 10

    ## PERCEPTRON
    perceptron_lab = Lab(
        ANDPerceptron,
        REPS,
        '/lista1/wyniki',
        bipolar=False,
        theta=0,
        bias=True,
        weight_range=(-0.5, 0.5),
        alpha=0.01,
    )

    # Theta
    perceptron_theta_uni = Experiment(
        title='Perceptron, uni, theta',
        f_name='per_theta_uni',
        test_parameter=('theta',
                        [-1.0, -0.8, -0.5, -0.2, 0.0, 0.2, 0.5, 0.8, 1.0]),
        bias=False,
    )
    perceptron_lab.add_experiment(perceptron_theta_uni)

    perceptron_theta_bi = Experiment(
        title='Perceptron, bi, theta',
        f_name='per_theta_bi',
        test_parameter=('theta',
                        [-1.0, -0.8, -0.5, -0.2, 0.0, 0.2, 0.5, 0.8, 1.0]),
        bias=False,
    )
    perceptron_lab.add_experiment(perceptron_theta_bi)

    # Weight range
    perceptron_w_uni = Experiment(
        title='Perceptron, uni, w',
        f_name='per_w_uni',
        test_parameter=(
            'weight_range',
            [
                (0.0, 0.0),
                (-0.1, 0.1),
                (-0.2, 0.2),
                (-0.5, 0.5),
                (-0.8, 0.8),
                (-1.0, 1.0),
            ],
        ),
    )
    perceptron_lab.add_experiment(perceptron_w_uni)

    perceptron_w_bi = Experiment(
        title='Perceptron, bi, theta',
        f_name='per_w_bi',
        test_parameter=(
            'weight_range',
            [
                (0.0, 0.0),
                (-0.1, 0.1),
                (-0.2, 0.2),
                (-0.5, 0.5),
                (-0.8, 0.8),
                (-1.0, 1.0),
            ],
        ),
    )
    perceptron_lab.add_experiment(perceptron_w_bi)

    # Alpha
    perceptron_alpha_uni = Experiment(
        title='Perceptron, uni, alpha',
        f_name='per_alpha_uni',
        test_parameter=('alpha', [0.0001, 0.001, 0.01, 0.1, 1.0]),
    )
    perceptron_lab.add_experiment(perceptron_alpha_uni)

    perceptron_alpha_bi = Experiment(
        title='Perceptron, bi, alpha',
        f_name='per_alpha_bi',
        test_parameter=('alpha', [0.0001, 0.001, 0.01, 0.1, 1.0]),
    )
    perceptron_lab.add_experiment(perceptron_alpha_bi)

    ## ADALINE
    adaline_lab = Lab(
        ANDAdaline,
        REPS,
        '/lista1/wyniki',
        theta=0,
        bias=True,
        weight_range=(-0.5, 0.5),
        alpha=0.01,
    )

    # Weight range
    adaline_w = Experiment(
        title='Adaline, w',
        f_name='ada_w',
        test_parameter=(
            'weight_range',
            [
                (0.0, 0.0),
                (-0.1, 0.1),
                (-0.2, 0.2),
                (-0.5, 0.5),
                (-0.8, 0.8),
                (-1.0, 1.0),
            ],
        ),
    )
    adaline_lab.add_experiment(adaline_w)

    # Alpha
    adaline_alpha = Experiment(
        title='Adaline, alpha',
        f_name='ada_alpha',
        test_parameter=('alpha', [0.0001, 0.001, 0.01, 0.1, 1.0]),
    )
    adaline_lab.add_experiment(adaline_alpha)

    # Epsilon
    adaline_epsilon = Experiment(
        title='Adaline, epsilon',
        f_name='ada_epsilon',
        test_parameter=('epsilon', [0]),
    )
    adaline_lab.add_experiment(adaline_epsilon)

    perceptron_lab.run()
    adaline_lab.run()