Skip to content

Instantly share code, notes, and snippets.

@ridixcr
Forked from chakkritte/dp1.txt
Last active January 24, 2018 14:24
Show Gist options
  • Save ridixcr/c3bbc803b336d732aafde227991a5b0d to your computer and use it in GitHub Desktop.
Save ridixcr/c3bbc803b336d732aafde227991a5b0d to your computer and use it in GitHub Desktop.
Installing TensorFlow

tensorflow/tensorflow#6999

1.Install python https://www.python.org/downloads/release/python-352/

2.To install the CPU-only version of TensorFlow

  • pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.1-cp35-cp35m-win_amd64.whl

  • python -m pip install --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-0.12.1-cp35-cp35m-win_amd64.whl

  • pip install --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-0.12.1-cp35-cp35m-win_amd64.whl --ignore-installed

  • pip3 install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-1.4.1-cp35-cp35m-linux_x86_64.whl

3.Test your installation

$ python
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
@ridixcr
Copy link
Author

ridixcr commented Jan 24, 2018

INSTALL WITH JAVA

TF_TYPE="cpu" # Default processor is CPU. If you want GPU, set to "gpu"
 OS=$(uname -s | tr '[:upper:]' '[:lower:]')
 mkdir -p ./jni
 curl -L \
   "https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow_jni-${TF_TYPE}-${OS}-x86_64-1.4.1.tar.gz" |
   tar -xz -C ./jni

Lib

HelloTF.java

import org.tensorflow.Graph;
import org.tensorflow.Session;
import org.tensorflow.Tensor;
import org.tensorflow.TensorFlow;

public class HelloTF {
  public static void main(String[] args) throws Exception {
    try (Graph g = new Graph()) {
      final String value = "Hello from " + TensorFlow.version();

      // Construct the computation graph with a single operation, a constant
      // named "MyConst" with a value "value".
      try (Tensor t = Tensor.create(value.getBytes("UTF-8"))) {
        // The Java API doesn't yet include convenience functions for adding operations.
        g.opBuilder("Const", "MyConst").setAttr("dtype", t.dataType()).setAttr("value", t).build();
      }

      // Execute the "MyConst" operation in a Session.
      try (Session s = new Session(g);
           Tensor output = s.runner().fetch("MyConst").run().get(0)) {
        System.out.println(new String(output.bytesValue(), "UTF-8"));
      }
    }
  }
}

javac -cp libtensorflow-1.4.1.jar HelloTF.java

java -cp libtensorflow-1.4.1.jar:. -Djava.library.path=./jni HelloTF - Linux,Mac

java -cp libtensorflow-1.4.1.jar;. -Djava.library.path=jni HelloTF - Windows

Source Inst.
Errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment