The Python API is far more useful than C++. I've really had no difficulty
using it via PyCall for Julia. You just write
using PyCall
@pyimport tensorflow as TF
to import the whole library, and code such as
TF.placeholder("float32")
TF.train[:GradientDescentOptimizer](α)[:minimize](loss)
to invoke it. There's a bit of experimentation to determine whether you use
a "." or a ":" syntax to access a function, as it may not be clear whether
you are calling the function on a module or an object.
Additionally, you can make it more friendly towards Julia operators by
overloading the basic ones, such as
+(a::PyObject, b) = a[:__add__](b)
-(a::PyObject, b) = a[:__sub__](b)
>(a::PyObject, b) = a[:__gt__](b)
etc
With a little cleverness, you can even get the python context managers to
work:
export pycm
function pycm(f::Function, pyobj::PyObject)
pyobj[:__enter__]()
err = nothing
try
f(pyobj)
catch err2
err = err2
finally
pyobj[:__exit__](nothing, nothing, nothing)
end
if err != nothing
rethrow(err)
end
end
pycm(TF.device("/cpu:0")) do dev
...
end
There is also a new Julia package that wraps TensorFlow and basically does
all this.
https://github.com/benmoran/TensorFlow.jl
I'm not sure how well it would keep up as the TensorFlow API evolves, so I
find it easier to just call TensorFlow directly.
Regards,
James
On Tuesday, December 15, 2015 at 3:17:50 AM UTC+8, Phil Tomson wrote:
>
> TensorFlow is written in C++ and they use SWIG to generate wrappers for
> Python. There is no Julia target for SWIG, but looking at some discussions
> here seems to indicate that SWIG for Julia is kind of pointless given that
> things like Cxx.jl exist.
>
> However, Cxx.jl requires special dev versions of both Julia and LLVM so
> it's not an "out of the box" experience just yet.
>
> There was a thread on TensorFlow here a few weeks back, I'm wondering if
> anyone was was working on Julia/TensorFlow interoperability?
>
> Are there alternatives to Cxx.jl for this kind of thing? Will Cxx.jl ever
> be at the point where we can use it with a standard release of Julia?
>
> Phil
>