「TensorFlowSharp」の版間の差分
imported>Administrator 編集の要約なし |
|||
| (同じ利用者による、間の3版が非表示) | |||
| 14行目: | 14行目: | ||
ln -s /usr/local/lib/libtensorflow.so /usr/local/lib/libtensorflow.dylib | ln -s /usr/local/lib/libtensorflow.so /usr/local/lib/libtensorflow.dylib | ||
== 公式サンプルを動かしてみる == | |||
TensorFlowSharpの[[ソースコード]](サンプル含む)を落としてくる。 | TensorFlowSharpの[[ソースコード]](サンプル含む)を落としてくる。 | ||
git clone https://github.com/migueldeicaza/TensorFlowSharp.git | git clone https://github.com/migueldeicaza/TensorFlowSharp.git | ||
| 27行目: | 28行目: | ||
TFWhileParams result = TF_NewWhile (handle, inputs, inputs.Length, cstatus.handle); | TFWhileParams result = TF_NewWhile (handle, inputs, inputs.Length, cstatus.handle); | ||
== | == プロジェクトを作ってみる == | ||
* プラットフォーム:x64 ←これ重要 | * プラットフォーム:x64 ←これ重要 | ||
*: Xamarin Studioで「コンソールアプリケーション」を作るとデフォルトで「x86」となっているので変更する。libtensorflowが64ビット必須であるため「x86」にしたままビルドすると実行時に落ちる。必ずx64でビルドする必要がある。 | *: Xamarin Studioで「コンソールアプリケーション」を作るとデフォルトで「x86」となっているので変更する。libtensorflowが64ビット必須であるため「x86」にしたままビルドすると実行時に落ちる。必ずx64でビルドする必要がある。 | ||
| 38行目: | 39行目: | ||
== サンプル == | == サンプル == | ||
< | === 足し算 === | ||
とりあえず「c = a + b」という式をTensorFlowに投げて実行してみる。<syntaxhighlight> | |||
using System; | using System; | ||
using System.Collections.Generic; | using System.Collections.Generic; | ||
| 67行目: | 68行目: | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> | ||
=== 保存と読込 === | |||
1年前はできなかった保存と読込ができるようになったぞ。トレーニングも捗るな。<syntaxhighlight> | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using TensorFlow; | |||
namespace tensor1 | |||
{ | |||
class MainClass | |||
{ | |||
public static void Main(string[] args) | |||
{ | |||
using (var graph = new TFGraph()) | |||
{ | |||
Console.WriteLine("-- save --"); | |||
using (var session = new TFSession(graph)) | |||
{ | |||
// 数値を作る | |||
var a = session.Graph.Const(30, "a"); | |||
var b = session.Graph.Const(12, "b"); | |||
// 足し算 | |||
var multiplyResults = session.GetRunner().Run(session.Graph.Add(a, b)); | |||
var multiplyResultValue = multiplyResults.GetValue(); | |||
Console.WriteLine("a + b = {0}", multiplyResultValue); | |||
// 保存 | |||
session.SaveTensors("saved.tsf", ("a", a), ("b", b)); | |||
} | |||
Console.WriteLine("-- load --"); | |||
using (var session = new TFSession()) | |||
{ | |||
// 読込 | |||
var a = session.RestoreTensor("saved.tsf", "a", TFDataType.Int32); | |||
var b = session.RestoreTensor("saved.tsf", "b", TFDataType.Int32); | |||
// 足し算 | |||
var multiplyResults = session.GetRunner().Run(session.Graph.Add(a, b)); | |||
var multiplyResultValue = multiplyResults.GetValue(); | |||
Console.WriteLine("a + b = {0}", multiplyResultValue); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
</syntaxhighlight> | |||
== 関連項目 == | == 関連項目 == | ||