Code Monkey home page Code Monkey logo

gil-galad's Introduction


A deep learning project template for efficient, reproducible experiments in TensorFlow with Sacred.

from sacred import Experiment
from sacred.observers import MongoObserver

from model import ResNet
from trainer import Trainer
from utils import TFRecordSampler, n_params


URL = '127.0.0.1'
DB_NAME = 'gil-galad'
USERNAME = 'username'
PASSWORD = 'password'
AUTHSOURCE = 'gil-galad'


"""Define an experiment and a MongoDB observer."""
ex = Experiment('gil-galad')
ex.observers.append(
    MongoObserver.create(
        url=URL,
        db_name=DB_NAME,
        username=USERNAME,
        password=PASSWORD,
        authSource=AUTHSOURCE,
    )
)


"""Define the experiment configuration."""
@ex.config
def config():
    learning_rate = 0.001
    n_batches = 1000
    batch_size = 32
    n_blocks = 3
    kernel_size = 3
    residual_filters = 32
    train_dir = './data/train'
    valid_dir = './data/valid'
    test_dir = './data/test'
    data_shapes = {
        'x': (32, 32, 3),
        'y': (128, 128, 3),
    }


"""Or a specific named configuration."""
@ex.named_config
def small():
    n_blocks = 1
    residual_filters = 16


"""The main function to execute an experiment."""
@ex.automain
def main(learning_rate, n_batches, batch_size, n_blocks, kernel_size,
    residual_filters, train_dir, valid_dir, test_dir, data_shapes,
    _run, _log):
    
    """Sacred seeds NumPy and TensorFlow automatically and delivers the seed to the MongoDB."""

    _log.info("Assembling graph...")

    sampler = TFRecordSampler(
        train_path=train_dir,
        valid_path=valid_dir,
        test_path=test_dir,
        data_shapes=data_shapes,
        batch_size=batch_size,
    )

    network = ResNet(
        kernel_size=kernel_size,
        residual_filters=residual_filters,
        n_blocks=n_blocks,
    )

    trainer = Trainer(
        network=network,
        sampler=sampler,
        learning_rate=learning_rate,
        run=_run,
        log=_log,
    )

    _log.info("Graph assembled. {} trainable parameters".format(n_params()))
    
    """The train method automatically sends TensorFlow logs and the latest checkpoint to Sacred."""
    
    trainer.train(
        n_batches=n_batches,
        summary_interval=5,
        checkpoint_interval=100,
    )

gil-galad's People

Contributors

davidreiman avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.