How to migrate NumPy preprocessing into a TensorFlow graph? - python

I'm using TensorFlow for machine learning on Ogg and MIDI data, but a lot of preprocessing is done in NumPy (with feed_dict:s), and I'd like to migrate as much of it as possible into the computational graph in order to simplify production deployment (Google Cloud ML, or maybe self-hosted TensorFlow Serving). How would I go about this? Are there ways of converting NumPy to TensorFlow operations automatically?

Most of the Numpy functions have their TensorFlow equivalent documented in array_ops.
For the more mathematical operations, have a look at math_ops.
Finally, if you have more specific queries or are unable to convert some Numpy code to TensorFlow, you should always try to search StackOverflow Q/A or ask a question here. (Have a look at this for a good example of such a question).
Unrelated - If you face difficulties carrying out some matrix manipulation, try to look at the existing Numpy Q/A on StackOverflow. They can easily be applied to TensorFlow using the APIs above.

Related

Numpy np.interp in tensorlflow

I'm looking for function for linear interpolation in tensorflow similar to np.interp(..)
I'm aware that tensorflow is able to receive any numpy function and apply it on tensors but
np.interp is only activated on single object and as far as I checked couldn't be broadcasted.
so is there any efficient way to apply it using tensoflow ?
Thank you
I know this is a late answer, but google brought me here, so my answer might be useful for others.
You can use the interp_regular_1d_grid from tensorflow probability.
It works in a similar fashion as numpy.interp(), but consult the documentation for exact functionality.

What's an easy way to test out Numpy operators?

I have Numpy installed. I'm trying to import it on Sublime so that I can test it out and see how it works. I'm trying to learn how to build an image classifier. I'm very new to Numpy and it's pretty confusing to me. Are there basic Numpy operators I can run on Python so I can start getting an idea on how it works?
The question is very generic. Numpy has several features. You can play with numpy to carry out several mathematical operation. Please refer NumPy documentation for more information on NumPy. https://numpy.org/doc/1.17/reference/index.html
What do you mean by "numpy operators"? Does it mean the library functions or just numerical operations that apply on every entry of the array?
My suggestion is to start with researching on ndarray, the most important data structure of numpy. See what it is and what operations it offers.

How Can I Approach Machine Learning in Python, Simply?

I am a web developer and tools creator professionally. The way that I learn things is by making the smallest possible product that is still functional and useful, and then adding complexity / refactoring as needed. I am trying to learn data science and pick up machine learning skills. When I look at the "small" projects in Machine Learning they assume a knowledge of Numpy, Pandas, and Seaborn in addition to being well versed in Python.
How can I make the machine learning equivalent of an index.html with Hello World inside of an <h1> tag?
If this is not possible, what sorts of projects can I do to incrementally "master" the underlying libraries. i.e. What is a "useful" project that one can do with only Numpy, only Numpy + Pandas, only Numpy + Pandas + Seaborn etc?
Apologies for open ended-ness. Not sure where else to post a question like this.
In response to the latter question
"What is a "useful" project that one can do with only Numpy, only Numpy + Pandas, only Numpy + Pandas + Seaborn etc?"
Numpy Projects in Isolation:
http://www.labri.fr/perso/nrougier/teaching/numpy.100/index.html
Projects here start very minimally and move into more and more complex problem spaces using on numpy as the only tool.
Numpy and Pandas Projects in Isolation:
https://www.hackerearth.com/practice/machine-learning/data-manipulation-visualisation-r-python/tutorial-data-manipulation-numpy-pandas-python/tutorial/
This link contains a short introduction to numpy and then spends the bulk of its resources discussing data frames.
Both links have the user solve increasingly complex data frame manipulations and were awesome resources to me and gave me lots of ideas on way I could expand and add additional complexity.

OpenGL matrix math utilities for Python?

Before I do it myself, are there any Python libraries available for OpenGL-specific/compatible matrix math on 4x4 matrices? Basically, I need about the feature set offered by Android's android.opengl.Matrix class.
I created the library Pyrr to provide all the maths features you need for Core OpenGL.
It features matrices, vectors and quaternions and basic support for other primitives (rectangles, rays, lines, etc).
It has both a procedural API and, more recently, an Object Oriented API which is very powerful.
It's available on PyPi pip install pyrr and from the github link above.
Feedback, issues and new features are welcome!
You can use numpy to generate data that is compatible with OpenGL. Many of the PyOpenGL calls can take numpy data structures directly (assuming it's the correct type). Additionally, numpy arrays are typically well arranged in memory, and so you can do what you want with the data (and it's easy to check how they are arranged).
PyGLM might be something to look at as well. The author claims to be 2x to 10x as fast as numpy.
It is based on the popular OpenGL Mathematics, C++ header only, library.
If you already know what you want in OpenGL, why not use PyOpenGL? I believe all the functionality you want should be there, and here are some docs on doing matrix transformations and interfacing with NumPy.

Python GPU programming [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am currently working on a project in python, and I would like to make use of the GPU for some calculations.
At first glance it seems like there are many tools available; at second glance, I feel like im missing something.
Copperhead looks awesome but has not yet been released. It would appear that im limited to writing low-level CUDA or openCL kernels; no thrust, no cudpp. If id like to have something sorted, im going to have to do it myself.
That doesnt seem quite right to me. Am I indeed missing something? Or is this GPU-scripting not quite living up to the hype yet?
Edit: GPULIB seems like it might be what I need. Documentation is rudimentary, and the python bindings are mentioned only in passing, but im applying for a download link right now. Anyone has experience with that, or links to similar free-for-academic-use GPU libraries? ReEdit: ok, python bindings are infact nonexistant.
Edit2: So I guess my best bet is to write something in C/CUDA and call that from python?
PyCUDA provides very good integration with CUDA and has several helper interfaces to make writing CUDA code easier than in the straight C api. Here is an example from the Wiki which does a 2D FFT without needing any C code at all.
I will publish here some information that I read on reddit. It will be useful for people who are coming without a clear idea of what different packages do and how they connect cuda with Python:
From:
Reddit
There's a lot of confusion in this thread about what various projects aim to do and how ready they are. There is no "GPU backend for NumPy" (much less for any of SciPy's functionality). There are a few ways to write CUDA code inside of Python and some GPU array-like objects which support subsets of NumPy's ndarray methods (but not the rest of NumPy, like linalg, fft, etc..)
PyCUDA and PyOpenCL come closest. They eliminate a lot of the plumbing surrounding launching GPU kernels (simplified array creation & memory transfer, no need for manual deallocation, etc...). For the most part, however, you're still stuck writing CUDA kernels manually, they just happen to be inside your Python file as a triple-quoted string. PyCUDA's GPUarray does include some limited NumPy-like functionality, so if you're doing something very simple you might get away without writing any kernels yourself.
NumbaPro includes a "cuda.jit" decorator which lets you write CUDA kernels using Python syntax. It's not actually much of an advance over what PyCUDA does (quoted kernel source), it's just your code now looks more Pythonic. It definitely doesn't, however, automatically run existing NumPy code on the GPU.
Theano let you construct symbolic expression trees and then compiles them to run on the GPU. It's not NumPy and only has equivalents for a small subset of NumPy's functionality.
gnumpy is a thinly documented wrapper around CudaMat. The only supported element type is float32 and only a small subset of NumPy is implemented.
I know that this thread is old, but I think I can bring some relevant information that answers to the question asked.
Continuum Analytics has a package that contains libraries that resolves the CUDA computing for you. Basically you instrument your code that needs to be parallelized (within a function) with a decorator and you need to import a library. Thus, you don't need any knowledge about CUDA instructions.
Information can be found on NVIDIA page
https://developer.nvidia.com/anaconda-accelerate
or you can go directly to the Continuum Analytics' page
https://store.continuum.io/cshop/anaconda/
There is a 30 day trial period and a free licence for academics.
I use this extensively and accelerates my code between 10 to 50 times.
Theano looks like it might be what you're looking for. From what I understand, it is very capable of doing some heavy mathematical lifting with the GPU and appears to be actively maintained.
Good luck!
Check this page for a open source library distributed with Anaconda
https://www.anaconda.com/blog/developer-blog/open-sourcing-anaconda-accelerate/
" Today, we are releasing a two new Numba sub-projects called pyculib and pyculib_sorting, which contain the NVIDIA GPU library Python wrappers and sorting functions from Accelerate. These wrappers work with NumPy arrays and Numba GPU device arrays to provide access to accelerated functions from:
cuBLAS: Linear algebra
cuFFT: Fast Fourier Transform
cuSparse: Sparse matrix operations
cuRand: Random number generation (host functions only)
Sorting: Fast sorting algorithms ported from CUB and ModernGPU
Going forward, the Numba project will take stewardship of pyculib and pyculib_sorting, releasing updates as needed when new Numba releases come out. These projects are BSD-licensed, just like Numba "
Have you taken a look at PyGPU?
http://fileadmin.cs.lth.se/cs/Personal/Calle_Lejdfors/pygpu/
I can recommend scikits.cuda . but for that you need to download CULA full version(free for students.) . Another is CUV .
If you are looking for something better and ready to pay for that,you can also take a look at array fire.Write now I am using scikits and quite satisfy so far.

Categories

Resources