GithubHelp home page GithubHelp logo

tfs's Introduction

tfs

A small, simple library to make tensorflow easy. Meant for running on a single computer, with multiple gpus. sdfsdfsd

Usage

git clone https://github.com/geevi/tfs.git

Then add the following import line

from tfs import *

Features

  • Building Sequential Network using json representation
x = tf.placeholder(tf.float32, [1, 128,128, 1])

net = [
    ['conv', {
        'window'    : 5,
        'chan'      : 32
    }],
    ['pool'],
    ['conv', {
        'window'    : 5,
        'chan'      : 64
    }],
    ['deconv', {
        'chan'      : 64,
        'window'    : 5,
        'stride'    : 2
    }],
    ['deconv', {
        'chan'      : 32,
        'window'    : 5,
        'stride'    : 2
    }],
    ['deconv', {
        'chan'      : 10,
        'window'    : 5,
        'stride'    : 2,
        'act'       : 'sigmoid'
    }]
]

self.logits = sequential(x, net)
  • Build custom layers by defining a function
def my_lstm_layer(x, name, **kwargs):
    time_steps = kwargs.get('time_steps')
    units = kwargs.get('units')
    inputs = []
    for i in range(time_steps):
        inputs.append(x)

    inputs = tf.stack(inputs, axis=0)

    return lstm_layer(inputs, units = units, seq_lens = tf.constant(time_steps, shape=[FLAGS.B]))
    
def my_seq_softmax(x, name, **kwargs):
    time_steps = kwargs.get('time_steps')
    y = []
    for i in range(time_steps):
        y.append(tf.nn.softmax(x[i]))

    y = tf.stack(y, axis=0)
    return y

    
layers = {
    'my_lstm_layer'     : my_lstm_layer,
    'my_seq_softmax'    : my_seq_softmax
}


net = [
    ['dense', {
        'units'         : 500
    }],
    ['my_lstm_layer', {
        'units'         : 500,
        'time_steps'    : FLAGS.L
    }],
    ['seq_linear', {
        'units'         : 2,
        'len'           : FLAGS.L
    }],
    ['my_seq_softmax', {
        'time_steps'    : FLAGS.L
    }]
]

string = sequential(class_one_hot, net, defaults = defaults, layers = layers, name = 'class2str')
    
  • Set default parameters for the same type of layers, and override if needed.
defaults = {
        'dense'     : {
        'act'           : 'relu'
        }
}


net = [
        ['dense', {
            'units'         : 2000
        }],
        ['dense', {
            'units'         : 2,
            'act'           : None #default parameter overriden
        }]
]

string = sequential(class_one_hot, net, defaults = defaults, name = 'class2str')
  • All basic layers implemented with proper variable scoping so that tensorboard graph view looks nice.

  • Create summaries, and saved models, with paths customizable by project and base dir.

  • Base classes for Datasets as well Models

class Logistic(BaseModel):

    def __init__(self, dataset):

        self.dataset = dataset

        net = [
           ['dense', {
               'units'     : FLAGS.hidden,
               'act'       : 'relu'
           }],
            ['dense', {
                'units'     : dataset.num_classes,
                'act'       : 'sigmoid'
            }]
        ]

        self.logits         = sequential(dataset.mean_rgb, net, name='mlp')
        self.logits_valid   = sequential(dataset.mean_rgb_valid, net, reuse=True, name='mlp')
        self.logits_test    = sequential(dataset.mean_rgb_test, net, reuse=True, name='mlp')

        args = {
            'y'             : dataset.labels,
            'y_pred'        : self.logits,
            'y_test'        : dataset.labels_valid,
            'y_pred_test'   : self.logits_valid,
            'rate'          : FLAGS.rate,
            'loss'          : cross_entropy,
            'acc'           : hit_at_1
        }
        
        self.optimizer, train_summary, test_summary = classify(**args)
        self.train_summary_op   = tf.summary.merge(train_summary)
        self.test_summary_op    = tf.summary.merge(test_summary)
  • Training and Testing Loops, Helper functions that create session, coordinator, file writer etc. for you.
def main(_):
    init()
    dataset = yt8m.YT8M()
    model = simple.Logistic(dataset)

    ctrl = create_session(saver = True, writer = True, coord = True)

    if not FLAGS.load:
        training_loop(ctrl, model, test=True)
    else:
        testing_loop(ctrl, model, dataset)

FAQ

  • How is this different from Keras, Sonet, tflearn, slim etc?

    • This is a very small and easy to understand library compared to them (a very thin wrapper).
    • It still reduces the code one needs to write for building models in tensorflow by a large extend.
    • Adding a custom layer is simply defining a function (instead of a class).
    • The customizable default parameters (which is a nice feature from slim) is there.
    • The model definition in json form is much more readable compared to other formats (IMHO).
    • Easy to mix and match with regular tensorflow code.

Contributions are welcome

tfs's People

Contributors

geevi avatar kris314 avatar

Stargazers

Avijit Dasgupta avatar Riddhiman Dasgupta avatar Sourabh Daptardar avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

kris314

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.