TensorFlow.jl
TensorFlow.jl copied to clipboard
ones and ones_like
Hi All,
I would like to implement unsorted_segment_mean as described in https://github.com/tensorflow/tensorflow/issues/7389 but I am missing ones_like function. Is it exported?
I have tried to use similar from Julia and it is not overloaded.
Thanks for help. Tomas
These operations are in python TensorFlow implemented in python, not in the C API. But they can be implemented in Julia too.
julia> using TensorFlow
julia> sess = Session(Graph())
Session(Ptr{Void} @0x00007f37bfc44b90)
julia> x = placeholder(Float32; shape=[3,-1])
<Tensor placeholder:1 shape=(3, ?) dtype=Float32>
julia> y=fill(constant(1f0), TensorFlow.shape(x))
<Tensor Fill:1 shape=unknown dtype=Float32>
Related, I think that maybe out use of Base.ones
is currently off.
I think it should match to that fill
definition, not to a constant
definition.
(Which to me would make more sense as just the user calling constant(ones(size))
, since constants are wrapped around julia types.
of course we could also overload:
ones(::Type{Tensor}, ::AbstractTensor)=fill(...
,
and ones(::Type{Tensor}, ::Any)=constant(ones(...
,
Thanks. This is nice.
+1 on the ones
function using fill and not constant.
Besides for that, what are your thoughts on ones
being overloaded such that it serves the purpose of ones
and ones_like
in TensorFlow. It seems like there's a balance to be struck here between being idiomatic with julia and accessible to TensorFlow users. I'm leaning towards only having ones
.
Let me know what you think and I can get started on this.
@malmaud thoughts?
Sorry for not getting back to you. I am undecided on this. Indeed there is a balance to be struck between idiomatic julia and accessible to TensorFlow users. In this case I lean very much towards idiomatic julia.
However, then the question becomes, what is idiomatic julia in this case?
I think ones(x::Tensor)
for ones_like
is idiomatic.
Is ones(::Type{Tensor}, x::Any)
idiomatic? Here I am unsure.
Consider the 0.6 deprecations:
julia> ones(rand(3,3))
3×3 Array{Float64,2}:
1.0 1.0 1.0
1.0 1.0 1.0
1.0 1.0 1.0
julia> ones(Int, rand(3,3))
WARNING: ones(T::Type, arr) is deprecated, use ones(T, size(arr)) instead.
Stacktrace:
[1] depwarn(::String, ::Symbol) at ./deprecated.jl:64
[2] ones(::Type{T} where T, ::Array{Float64,2}) at ./deprecated.jl:51
[3] eval(::Module, ::Any) at ./boot.jl:235
[4] eval_user_input(::Any, ::Base.REPL.REPLBackend) at ./REPL.jl:66
[5] macro expansion at ./REPL.jl:97 [inlined]
[6] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73
while loading no file, in expression starting on line 0
3×3 Array{Int64,2}:
1 1 1
1 1 1
1 1 1