Giter VIP home page Giter VIP logo

tensorgraph's Introduction

TensorGraph

纯Python对TensorFlow功能的重新实现

TensorGraph是一个模仿TensorFlow API对小的机器学习API,使用纯Python实现,没有C. 代码实现考虑的是概念上的理解,而不是考虑功能实现的效率. 所以,只适用于学习的目的. 如果你想理解像TensorFlow这样的深度学习库的工作机制,这个项目是非常适合的.

我在CSDN上写了博客 CSDN 来讲述如何开始这个项目,可以浏览。

使用方法

导入:

import TensorGraph as tg

创建计算图:

tg.Graph().as_default()

创建输入占位符:

training_features = tg.placeholder()
training_classes = tg.placeholder()

建一个神经网络结构:

weightg = tg.Variable(np.random.randn(2, 2))
biases = tg.Variable(np.random.randn(2))
model = tg.softmax(tg.add(tg.matmul(X, W), b))

创建一个优化函数或者损失函数:

loss = tg.negative(tg.reduce_sum(tg.reduce_sum(tg.multiply(training_classes, tg.log(model)), axis=1)))

选择使用优化器:

optimizer = tg.train.GradientDescentOptimizer(learning_rate=0.01).minimize(J)

向输入占位符输入数据:

feed_dict = {
	training_features: my_training_features,
	training_classes: my_training_classes
}

创建会话:

session = tg.Session()

训练:

for step in range(100):
	loss_value = session.run(loss, feed_dict)
	if step % 10 == 0:
		print("Step:", step, " Loss:", loss_value)
	session.run(optimizer, feed_dict)

检索模型参数:

weightg_value = session.run(weigths)
biases_value = session.run(biases)

更多信息,参看examples 目录下的例子.

tensorgraph's People

Contributors

enigmawxy avatar 2411148291 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.