Giter Club home page Giter Club logo

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

miniflow's Issues

Error happen when running smoke_tests.py: object has no attribute 'name'

Sorry maybe a naive question/ false issue since I touch miniflow the first time and try to study it and wants to help contribute.
Tried to run smoke_tests.py under the tests folder but encountered below issue. Is this due to running it in incorrect way? Or the op ".name"is not supported by miniflow currently.

Hello, MiniFlow!
42
42.0
Traceback (most recent call last):
File "smoke_tests.py", line 43, in
main()
File "smoke_tests.py", line 38, in main
print(sess.run(c, feed_dict={a.name: 10.0}))
AttributeError: 'PlaceholderOp' object has no attribute 'name'

README doesn't communicate the project very well

Hey,

Just read through this repo's README and I have little idea what this project is or does. It says it's "the minimal Implementation" of TF, but this isn't clear to me. From the examples miniflow looks just like tensorflow but with some methods renamed, so it probably isn't a TF wrapper library.

Looking at the source code it becomes clearer that this is a barebones rewrite of Tensorflow. In this case I think more of the README should be devoted to pointing this out and not so much on code examples.

Maybe details more about the implementation; it's structure, your learnings, and the project's gaps.


Nice work btw. I'll be checking back on this to learn more about TF.

doubts in grad function of DivideOp

I found that in grad func of MultipleOp, op1 or op2 may be different types, so the implementation of grad func should take them into consideration. So why grad func of DivideOp just use:
self._op1.grad(partial_derivative_opname) / self._op2.grad(partial_derivative_opname)

miniflow only supports python 2 instead of python 3

hi tobe,

today I experienced miniflow first time, I found the following issue:

import miniflow as tf
Traceback (most recent call last):
File "", line 1, in
File "C:\Users***\AppData\Local\Programs\Python\Python35\lib\site-packages\miniflow_init_.py", line 37, in
import graph
ImportError: No module named 'graph'

'graph' module is located in miniflow directory, and miniflow_init.py simply uses 'import graph' to import graph.
if I do not first change directory to site-packages\miniflow or PYTHONPATH does not set to the site-packages\miniflow, I will get the above issue.

use 'from miniflow import graph' or 'from . import graph' can solve the issue, that is, we can import miniflow from any directory or not set PYTHONPATH.
we need to replace ALL similar 'import graph'.

After I can successfully import miniflow by first change to site-packages\miniflow, but dir(tf) show almost nothing. seems all imports in init.py are NOT executed.

dir(tf)
['builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'spec']

when I execute import tensorflow as tf, it can successfully import as expected.
I think there are some jobs to be done to make it import easily as tensorflow.

note: I am not very familiar with python. maybe the issue is not an issue, or maybe you have good solution. anyway, I just create the issue for your notice.

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.