FluxML / ONNX.jl

Read ONNX graphs in Julia
Other
139 stars 26 forks source link

ONNX doesn't seem to be able to load ONNX models #22

Open BrianGun opened 5 years ago

BrianGun commented 5 years ago

I tried loading 6 different ONNX models from this website https://github.com/onnx/models. None of them loaded correctly. Here is my Julia version info:

Julia Version 1.1.0 Commit 80516ca202 (2019-01-21 21:24 UTC) Platform Info: OS: Windows (x86_64-w64-mingw32) CPU: Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-6.0.1 (ORCJIT, broadwell) Environment: JULIA_EDITOR = "C:\Program Files\Microsoft VS Code\Code.exe"

Here are the error messages when attempting to load the models:

julia> ONNX.load_model("/users/bguenter/Documents/allfiles/Projects/synthetics/ONNX/tiny_Yolov2/model.onnx") ERROR: KeyError: key "convolution.W" not found Stacktrace: [1] getindex at .\dict.jl:478 [inlined] [2] (::getfield(ONNX, Symbol("##118#120")){Dict{String,IVertex}})(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:61 [3] iterate at .\generator.jl:47 [inlined] [4] collect_to!(::Array{IVertex,1}, ::Base.Generator{Array{AbstractString,1},getfield(ONNX, Symbol("##118#120")){Dict{String,IVertex}}}, ::Int64, ::Int64) at .\array.jl:651 [5] collect_to_with_first! at .\array.jl:630 [inlined] [6] _collect(::Array{AbstractString,1}, ::Base.Generator{Array{AbstractString,1},getfield(ONNX, Symbol("##118#120")){Dict{String,IVertex}}}, ::Base.EltypeUnknown, ::Base.HasShape{1}) at .\array.jl:624 [7] collect_similar(::Array{AbstractString,1}, ::Base.Generator{Array{AbstractString,1},getfield(ONNX, Symbol("##118#120")){Dict{String,IVertex}}}) at .\array.jl:548 [8] map(::Function, ::Array{AbstractString,1}) at .\abstractarray.jl:2018 [9] _graph(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:61 [10] graph(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:96 [11] code(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:104 [12] write_julia_file(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:221 [13] load_model(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:237 [14] top-level scope at none:0

julia> ONNX.load_model("/users/bguenter/Documents/allfiles/Projects/synthetics/ONNX/mnist/model.onnx") ERROR: ArgumentError: Dict(kv): kv needs to be an iterator of tuples or pairs Stacktrace: [1] Dict(::Base.Generator{Array{ONNX.Proto.AttributeProto,1},typeof(ONNX.convert_model)}) at .\dict.jl:132 [2] convert_array at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:17 [inlined] [3] convert(::ONNX.Proto.NodeProto) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:162 [4] convert(::ONNX.Proto.GraphProto) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:125 [5] write_weights(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:191 [6] load_model(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:236 [7] top-level scope at none:0

julia> ONNX.load_model("/users/bguenter/Documents/allfiles/Projects/synthetics/ONNX/ssd/model.onnx") ERROR: DimensionMismatch("new dimensions () must be consistent with array size 0") Stacktrace: [1] (::getfield(Base, Symbol("#throw_dmrsa#193")))(::Tuple{}, ::Int64) at .\reshapedarray.jl:41 [2] reshape(::Array{Float32,1}, ::Tuple{}) at .\reshapedarray.jl:45 [3] get_weights(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:14 [4] weights(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:41 [5] write_weights(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:192 [6] load_model(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:236 [7] top-level scope at none:0

julia> ONNX.load_model("/users/bguenter/Documents/allfiles/Projects/synthetics/ONNX/inception/model.onnx") ERROR: MethodError: no method matching (::getfield(ONNX, Symbol("##3#4")))(::Dict{Any,Any}, ::IVertex, ::IVertex, ::IVertex, ::IVertex) Closest candidates are:

3(::Any, ::Any, ::Any) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\ops.jl:14

Stacktrace: [1] _graph(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:61 [2] graph(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:96 [3] code(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:104 [4] write_julia_file(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:221 [5] load_model(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:237 [6] top-level scope at none:0

julia> ONNX.load_model("/users/bguenter/Documents/allfiles/Projects/synthetics/ONNX/fasterRcnnR50Fpn1x/faster_rcnn_R_50_FPN_1x.onnx") ERROR: DimensionMismatch("new dimensions (7, 7, 3, 64) must be consistent with array size 0") Stacktrace: [1] (::getfield(Base, Symbol("#throw_dmrsa#193")))(::NTuple{4,Int64}, ::Int64) at .\reshapedarray.jl:41 [2] reshape(::Array{Float32,1}, ::NTuple{4,Int64}) at .\reshapedarray.jl:45 [3] get_weights(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:14 [4] weights(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:41 [5] write_weights(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:192 [6] load_model(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:236 [7] top-level scope at none:0

julia> ONNX.load_model("/users/bguenter/Documents/allfiles/Projects/synthetics/ONNX/yolov3/yolov3.onnx") ERROR: KeyError: key :Pad not found Stacktrace: [1] getindex(::Dict{Symbol,Any}, ::Symbol) at .\dict.jl:478 [2] _graph(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:0 [3] graph(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:96 [4] code(::ONNX.Types.Graph) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\graph\graph.jl:104 [5] write_julia_file(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:221 [6] load_model(::String) at C:\Users\bguenter.julia\packages\ONNX\7ZopS\src\convert.jl:237 [7] top-level scope at none:0

ayush-1506 commented 5 years ago

@BrianGun I tried some of the models you mentioned:

model 1. It's because of an error in the onnx model itself : see https://github.com/onnx/models/issues/60.

model 2. This has been fixed. Use the master branch rather than the tagged version (]add ONNX#master)

model 4. This also has been fixed. Use the master branch (see point 2 above). Note: As discussed on slack , Flux doesn't support LRNorm right now. The generated code will have LRNorm function calls, and you'll have to manually add LRNorm definition. (I'll remove this once Flux starts supporting it : https://github.com/FluxML/Flux.jl/pull/720 you can just copy the function definition from the PR, since we need to use it only in the inference mode).

I'll get back to you with the results of the other models.

BrianGun commented 5 years ago

Ayush, Thanks for taking a look at this. I did add ONNX#master which upgraded ONNX to 0.1.1.

Some of the neural net models load now but unfortunately none of the object detection models appear to load properly: ssd, tiny_yolov2, yolov3, fasterrcnn. That's what I really need for my internal project so I'm still out of luck.

-brian