LoginSignup
10
6

More than 5 years have passed since last update.

Java で TensorFlowをする。メチャクチャ簡単だけれど。。。。

Posted at

機械学習といえば、Googleの開発したTensorFlowが有名ですよね。

実は、みんな大好きJavaでも、TensorFlowを使えるのです。しかも使い方はとても簡単。buildに1ライブラリを追加するだけです。

compile 'org.tensorflow:tensorflow:1.7.0'

build.gradleの全体はこちら

これだけでサンプルコードが動きます。

サンプル抜粋
try (Graph g = new Graph(); Session session = new Session(g)) {
    Tensor<?> t = Tensor.create("初めてのTensorFlow".getBytes());
    g.opBuilder("Const", "message").setAttr("dtype", t.dataType()).setAttr("value", t).build();
    Tensor<?> out = session.runner().fetch("message").run().get(0);
    System.out.println(new String(out.bytesValue()));
}


初めてのTensorFlow とコンソールに出力されます。

サンプルコード全体はこちら

とても簡単に機械学習の環境が整います。

ただし。。。

判定はJavaでできるものの、最初の学習はPythonやCなど、他でやる必要があります。
イチからJavaでできるようになるといいですね!

10
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
6