Understanding Tensorflow using Go

2022-02-14

原文:

is not a , , is a that with .它的核心是 C++,还有用于 .的 for the Go 是一个工具,不仅可以在 Go 中使用,还可以用于如何在引擎盖下使用。

, 的:

作为一个 Java 爱好者而不是 Java 爱好者,我在 Go 中是为了完成他们的任务。

开始

(by Ueda (@).下3.0)

标志。

首先要注意的是,Go API for of the 缺少:这个 API 是 for from 。这适用于 Go:

在 Go 中使用的 API。这些 API 非常适用,而且是 Go 语言。

如果我们不在 ML 中:!如果, , 你在这里是:

做一个真实的,保持它!用于 & 训练 ;您可以稍后通过 Go 加载和使用它们!

简而言之:go 可以用 and ; where , in this 表示没有,因此没有。

现在让我们开始使用 Go:让我们的第一个。

在 , I 中, the 已经准备好 Go 并且 and 在 中。

Let’s what is (keep from , the is mine):

™ 是一个开放的使用数据流。中的节点,而图形数据()它们。

我们可以把它想象成一个,有点像 SQL,在其中你想要什么,然后让 (the) 解析你的查询,检查 and , it 到 its , it 和 the : 所有这一切都给你.

,当我们使用任何 API 时,我们所做的就是对一个图:当我们将它放入图中时,图的 .

这个,让我们尝试一个图表和它。我们清楚地列出了 () &op。

正如我们所见,这两个我们需要和一个图表。

到基本的“空”之类的,是最出自C++的。

,我们想要的

A=(12−1−2),x=(10100)

我认为这是图形的想法,并且知道它们是什么以及它们是如何工作的。下面的代码是用户将创建的第一个代码。我们称之为 .go

package main
import (
	"fmt"

图片[1]-Understanding Tensorflow using Go-唐朝资源网

tf "github.com/tensorflow/tensorflow/tensorflow/go" "github.com/tensorflow/tensorflow/tensorflow/go/op" ) func main() { // Let's describe what we want: create the graph // We want to define two placeholder to fill at runtime // the first placeholder A will be a [2, 2] tensor of integers // the second placeholder x will be a [2, 1] tensor of intergers // Then we want to compute Y = Ax // Create the first node of the graph: an empty node, the root of our graph root := op.NewScope() // Define the 2 placeholders A := op.Placeholder(root, tf.Int64, op.PlaceholderShape(tf.MakeShape(2, 2))) x := op.Placeholder(root, tf.Int64, op.PlaceholderShape(tf.MakeShape(2, 1))) // Define the operation node that accepts A & x as inputs product := op.MatMul(root, A, x) // Every time we passed a `Scope` to an operation, we placed that // operation **under** that scope. // As you can see, we have an empty scope (created with NewScope): the empty scope // is the root of our graph and thus we denote it with "/".

图片[2]-Understanding Tensorflow using Go-唐朝资源网

// Now we ask tensorflow to build the graph from our definition. // The concrete graph is created from the "abstract" graph we defined // using the combination of scope and op. graph, err := root.Finalize() if err != nil { // It's useless trying to handle this error in any way: // if we defined the graph wrongly we have to manually fix the definition. // It's like a SQL query: if the query is not syntactically valid // we have to rewrite it panic(err.Error()) }

图片[3]-Understanding Tensorflow using Go-唐朝资源网

// If here: our graph is syntatically valid. // We can now place it within a Session and execute it. var sess *tf.Session sess, err = tf.NewSession(graph, &tf.SessionOptions{}) if err != nil { panic(err.Error()) } // In order to use placeholders, we have to create the Tensors // containing the values to feed into the network var matrix, column

分类:

技术要点:

相关文章:

© 版权声明
THE END
喜欢就支持一下吧
点赞13赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容