2x1=10

because numbers are people, too
Persönliches
Fotografie
Programmierung
    • Getting an image into and out of TensorFlow

      Let’s assume you already have an image in numpy’s ndarray for­mat, e.g. because you loaded it with OpenCV’s imread() func­tion, and you want to con­vert it to TensorFlow’s Ten­sor for­mat and lat­er back to ndarray.

      That’s essen­tial­ly three calls to Ten­sor­Flow:

      import cv2
      import tensorflow as tf
      import numpy as np
      
      # normalize the pixel values to 0..1 range and convert them 
      # to a single-precision tensor
      image_in = cv2.imread('image.png') / 255.
      t = tf.convert_to_tensor(image_in, dtype=tf.float32)
      assert isinstance(t, tf.Tensor)
      
      # in order to convert the tensor back to an array, we need
      # to evaluate it; for this, we need a session
      with tf.Session() as sess:
          image_out = sess.run(fetches=t)
          assert isinstance(image_out, np.ndarray)
      
      # for imshow to work, the image needs to be in 0..1 range
      # whenever it is a float; that's why we normalized it.
      cv2.imshow('Image', image_out)
      cv2.readKey(0)
      

      Note that instead of using sess.run(t) we could also have used

      with tf.Session() as sess:
          image_out = t.eval(sess)
      

      which essen­tial­ly per­forms the same action. A ben­e­fit of using sess.run() direct­ly is that we can fetch more than one ten­sor in the same pass through the (sub-)graph (say, tuple = sess.run(fetches=[t1, t2, t3])), where­as call­ing tensor.eval() always results in one sep­a­rate pass per call.

      Dezember 12th, 2016 GMT +1 von
      Markus
      2016-12-12T15:59:54+01:00 2016-12-12T15:59:54+01:00 · 0 Kommentare
      OpenCV Python tensorflow
      Image Processing TensorFlow Neural Networks

      Hinterlasse einen Kommentar

      Hier klicken, um das Antworten abzubrechen.

    1. « newer
    2. 1
    3. 2
    4. 3
    5. 4
    6. 5
    7. 6
    8. 7
    9. 8
    10. “Compiler crashed with code 1” on Mono">9
    11. …
    12. 43
    13. older »
    • Kategorien

      • .NET
        • ASP.NET
        • Core
        • DNX
      • Allgemein
      • Android
      • Data Science
      • Embedded
      • FPGA
      • Humor
      • Image Processing
      • Kalman Filter
      • Machine Learning
        • Caffe
        • Hidden Markov Models
        • ML Summarized
        • Neural Networks
        • TensorFlow
      • Mapping
      • MATLAB
      • Robotik
      • Rust
      • Signal Processing
      • Tutorial
      • Version Control
    • Neueste Beiträge

      • Summarized: The E-Dimension — Why Machine Learning Doesn’t Work Well for Some Problems?
      • Use your conda environment in Jupyter Notebooks
      • Building OpenCV for Anaconda Python 3
      • Using TensorFlow’s Supervisor with TensorBoard summary groups
      • Getting an image into and out of TensorFlow
    • Kategorien

      .NET Allgemein Android ASP.NET Caffe Core Data Science DNX Embedded FPGA Hidden Markov Models Humor Image Processing Kalman Filter Machine Learning Mapping MATLAB ML Summarized Neural Networks Robotik Rust Signal Processing TensorFlow Tutorial Version Control
    • Tags

      .NET Accelerometer Anaconda Bitmap Bug Canvas CLR docker FPGA FRDM-KL25Z FRDM-KL26Z Freescale git Gyroscope Integration Drift Intent J-Link Linear Programming Linux Magnetometer Matlab Mono Naismith OpenCV Open Intents OpenSDA Optimization Pipistrello Player/Stage PWM Python Sensor Fusion Simulink Spartan 6 svn tensorflow Tilt Compensation TRIAD ubuntu Windows Xilinx Xilinx SDK ZedBoard ZYBO Zynq
    • Letzte Kommetare

      • Lecke Mio bei Frequency-variable PWM generator in Simulink
      • Vaibhav bei Use your conda environment in Jupyter Notebooks
      • newbee bei Frequency-variable PWM generator in Simulink
      • Markus bei Using TensorFlow’s Supervisor with TensorBoard summary groups
      • Toke bei Using TensorFlow’s Supervisor with TensorBoard summary groups
    • Blog durchsuchen

    • Dezember 2016
      M D M D F S S
      « Sep   Jan »
       1234
      567891011
      12131415161718
      19202122232425
      262728293031  
    • Self

      • Find me on GitHub
      • Google+
      • Me on Stack­Ex­change
      • Ye olde blog
    • Meta

      • Anmelden
      • Beitrags-Feed (RSS)
      • Kommentare als RSS
      • WordPress.org
    (Generiert in 0,258 Sekunden)

    Zurück nach oben.