zoukankan      html  css  js  c++  java
  • [TensorFlow] Basic Usage

    Install TensorFlow on mac

    Install pip 

    # Mac OS X
    $ sudo easy_install pip
    $ sudo easy_install --upgrade six

    Install tensorflow 

    # Mac OS X, CPU only, Python 2.7:
    $ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.12.1-py2-none-any.whl

    Basic Usage

    The concepts in TensorFlow

    Tensor : a typed multi-dimensional array. Only Tensor are passed between operations in the computation graph.

    Graph : a description of computation.

    op : (short for operation) the node in the graph

    Session : the context in which to execute graphs

    Devices : such as CPUs or GPUs, on which Session execute graphs

    Variable : maintain state 

    numpy ndarray : the result structure returned by Sesson.run(graph), which is produced by ops in graph and transformed from tensor

    Simple example

    import tensorflow as tf
    
    # Start with default graph.
    matrix1 = tf.constant([[3., 3.]])
    matrix2 = tf.constant([[2.],[2.]])
    product = tf.matmul(matrix1, matrix2)
    # Now the default graph has three nodes: two constant() ops and one matmul() op.
    
    # Launch the default graph in a Session
    sess = tf.Session()
    result
    = sess.run(product) print(result) sess.close()

    The call 'run(product)' causes the execution of three ops in the graph.

    Fetches : to fech the outputs of operations, execute the graph with a run() call on the Session object. E.g. sess.run(product) in above sample

    Feeds : a mechanism for patching tensors directly into operations in graph. Supply feed data as argument to a run() call. tf.placeholder is used to create "feed" operations commonly

    input1 = tf.placeholder(tf.float32)
    input2 = tf.placeholder(tf.float32)
    output = tf.mul(input1, input2)
    
    with tf.Session() as sess:
      print(sess.run([output], feed_dict={input1:[7.], input2:[2.]}))
    
    # output:
    # [array([ 14.], dtype=float32)]

    References

    Download and Setup, TensorFlow

    Basic Usage, TensorFlow

  • 相关阅读:
    查看每个核的资源情况
    什么时候使用NO_UNNEST
    走FILTER效率高的2种情况
    PL/SQL 包头和包体
    产品研发要配合好
    ElasticSearch 文档并发处理以及文档路由
    ES(ElasticSearch) 索引创建
    BaikalDB技术实现内幕(三)--代价模型实现
    腾讯位置服务地图SDK自定义地图和路况
    mysql数据库优化
  • 原文地址:https://www.cnblogs.com/TonyYPZhang/p/6368960.html
Copyright © 2011-2022 走看看