GithubHelp home page GithubHelp logo

aoguren / miniflow Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tobegit3hub/miniflow

0.0 2.0 0.0 3.47 MB

Minimal numerical computation library with TensorFlow APIs

License: Apache License 2.0

Makefile 0.09% Python 20.43% C 79.42% Shell 0.07%

miniflow's Introduction

MiniFlow

Introduction

MiniFlow is the numerical computation library which implements TensorFlow APIs.

  • Support math calculations and composited operations
  • Support automatic partial derivative and chain rule
  • Support operations in C++/Python backends with swig
  • Support platforms like Linux/MacOS/Windows/Raspbian
  • Support imperative and declarative computations
  • Support the compatiable APIs with TensorFlow

Installation

Install with pip.

pip install miniflow

Or run with docker.

docker run -it tobegit3hub/miniflow bash

Usage

MiniFlow has compatiable APIs with TensorFlow and please refer to examples for more usage.

Basic operations

Run with TensorFlow.

import tensorflow as tf

sess = tf.Session()

hello = tf.constant("Hello, TensorFlow!")
sess.run(hello)
# "Hello, TensorFlow!"

a = tf.constant(10)
b = tf.constant(32)
sess.run(a + b)
# 42

Run with MiniFlow.

import miniflow as tf

sess = tf.Session()

hello = tf.constant("Hello, MiniFlow!")
sess.run(hello)
# "Hello, MiniFlow!"

a = tf.constant(10)
b = tf.constant(32)
sess.run(a + b)
# 42

Use placeholder

Run with TensorFlow.

import tensorflow as tf

sess = tf.Session()

a = tf.placeholder(tf.float32)
b = tf.constant(32.0)
sess.run(a + b, feed_dict={a: 10})
sess.run(a + b, feed_dict={a.name: 10})
# 42.0

Run with MiniFlow.

import miniflow as tf

sess = tf.Session()

a = tf.placeholder(tf.float32)
b = tf.constant(32.0)
sess.run(a + b, feed_dict={a: 10})
sess.run(a + b, feed_dict={a.name: 10})
# 42.0

Linear model

Run with TensorFlow.

def linear_regression():
  epoch_number = 30
  learning_rate = 0.01
  train_features = [1.0, 2.0, 3.0, 4.0, 5.0]
  train_labels = [10.0, 20.0, 30.0, 40.0, 50.0]

  weights = tf.Variable(0.0)
  bias = tf.Variable(0.0)
  x = tf.placeholder(tf.float32)
  y = tf.placeholder(tf.float32)

  predict = weights * x + bias
  loss = tf.square(y - predict)
  sgd_optimizer = tf.train.GradientDescentOptimizer(learning_rate)
  train_op = sgd_optimizer.minimize(loss)

  with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())

    for epoch_index in range(epoch_number):
      # Take one sample from train dataset
      sample_number = len(train_features)
      train_feature = train_features[epoch_index % sample_number]
      train_label = train_labels[epoch_index % sample_number]

      # Update model variables and print loss
      sess.run(train_op, feed_dict={x: train_feature, y: train_label})
      loss_value = sess.run(loss, feed_dict={x: 1.0, y: 10.0})
      print("Epoch: {}, loss: {}, weight: {}, bias: {}".format(
          epoch_index, loss_value, sess.run(weights), sess.run(bias)))

Run with MiniFlow.

def linear_regression():
  epoch_number = 30
  learning_rate = 0.01
  train_features = [1.0, 2.0, 3.0, 4.0, 5.0]
  train_labels = [10.0, 20.0, 30.0, 40.0, 50.0]

  weights = tf.Variable(0.0)
  bias = tf.Variable(0.0)
  x = tf.placeholder(tf.float32)
  y = tf.placeholder(tf.float32)

  predict = weights * x + bias
  loss = tf.square(y - predict)
  sgd_optimizer = tf.train.GradientDescentOptimizer(learning_rate)
  train_op = sgd_optimizer.minimize(loss)

  with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())

    for epoch_index in range(epoch_number):
      # Take one sample from train dataset
      sample_number = len(train_features)
      train_feature = train_features[epoch_index % sample_number]
      train_label = train_labels[epoch_index % sample_number]

      # Update model variables and print loss
      sess.run(train_op, feed_dict={x: train_feature, y: train_label})
      loss_value = sess.run(loss, feed_dict={x: 1.0, y: 10.0})
      print("Epoch: {}, loss: {}, weight: {}, bias: {}".format(
          epoch_index, loss_value, sess.run(weights), sess.run(bias)))

The computed gradient and the variables of the model are accurate.

Performance

We have more performance tests in benchmark.

Contribution

GitHub issues and pull-requests are highly appreciated and feel free to make your contribution.

Release to upload the official python package of miniflow in pypi.

python setup.py sdist upload

python setup.py sdist --format=gztar
twine upload dist/miniflow-x.x.x.tar.gz

miniflow's People

Contributors

tobegit3hub avatar

Watchers

James Cloos avatar  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.