• [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

  • 相关阅读:
    hdu 3335 Divisibility
    最小点覆盖,最小路径覆盖
    hdu 4109 Instrction Arrangement
    sjtu 1077 加分二叉树
    hdu 1542 Atlantis
    多线程中互斥体
    在子页面中,javascript让模板页中添加的用户控件中的控件选中focus
    模板页中用javascript判断是否为空
    控件包含代码块(即 <% ... %>),因此无法修改控件集合 asp.net
    lambda从指定集合中去除指定数据 asp.net
  • 原文地址:https://www.cnblogs.com/TonyYPZhang/p/6368960.html
Copyright © 2020-2023  润新知