ONNX.jl icon indicating copy to clipboard operation
ONNX.jl copied to clipboard

Can't load yolov3 onnx (v1.5) model: KeyError: key :Pad not found

Open IanButterworth opened this issue 5 years ago • 10 comments

I'm trying to load in the YOLOv3 ONNX (v1.5) model from: https://github.com/onnx/models/tree/master/vision/object_detection_segmentation/yolov3

with:

using Flux, ONNX                
ONNX.load_model("yolov3.onnx")      
weights = ONNX.load_weights("weights.bson")
model = include("model.jl")  

But during load_model() after weights.bson has started to populate, I hit:

ERROR: LoadError: KeyError: key :Pad not found
Stacktrace:
 [1] getindex(::Dict{Symbol,Any}, ::Symbol) at ./dict.jl:478
 [2] _graph(::ONNX.Types.Graph) at /Users/ian/.julia/packages/ONNX/SYcQV/src/graph/graph.jl:0
 [3] graph(::ONNX.Types.Graph) at /Users/ian/.julia/packages/ONNX/SYcQV/src/graph/graph.jl:92
 [4] code(::ONNX.Types.Graph) at /Users/ian/.julia/packages/ONNX/SYcQV/src/graph/graph.jl:100
 [5] write_julia_file(::String) at /Users/ian/.julia/packages/ONNX/SYcQV/src/convert.jl:235
 [6] load_model(::String) at /Users/ian/.julia/packages/ONNX/SYcQV/src/convert.jl:250
 [7] top-level scope at none:0
in expression starting at /Users/ian/Documents/GitHub/YOLO.jl/WIP_tests/try_onnx.jl:5

cc. @staticfloat

IanButterworth avatar Jul 15 '19 02:07 IanButterworth

Looks like we need to implement the Pad ONNX v2 operator: https://github.com/onnx/onnx/blob/master/docs/Operators.md#Pad

This should probably just be a straightforward addition to src/graph/ops.jl

staticfloat avatar Jul 15 '19 02:07 staticfloat

Pad and Gather are the two new ops we need. @dhairyagandhi96 Are you still interested in looking into these?

ayush-1506 avatar Jul 15 '19 06:07 ayush-1506

Yup, I was wondering though that if we need some very specific ops defined to get the models running, would it not be okay to also carry those ops as function definitions (or a "ONNXops.jl" dependency) in the model file?

DhairyaLGandhi avatar Jul 15 '19 06:07 DhairyaLGandhi

@dhairyagandhi96 Yes, if the ops involve specific operations (that cannot be written with Base/Flux functions), it'd be better to write them out as functions to the model.jl file.

ayush-1506 avatar Jul 15 '19 08:07 ayush-1506

Definitely, these ops can be written in base, the only overhead is defining the functions such that they are available to the model when it is run.

DhairyaLGandhi avatar Jul 15 '19 08:07 DhairyaLGandhi

Are you interested in a new package that just contains the bigger ops functions? That'd make it easier to define and update ops in the future.

ayush-1506 avatar Jul 15 '19 08:07 ayush-1506

I'm not sure if I'm the right person to help implement this, as I'm pretty naive to Flux and ONNX inner workings.. but I am keen to get this working, so happy to help if I can get some direction!

IanButterworth avatar Jul 16 '19 21:07 IanButterworth

I'm having a similar problem loading a onnx (v1.5) model.

ONNX.load_model("model.onnx")
ERROR: KeyError: key :ConvTranspose not found
Stacktrace:
 [1] getindex(::Dict{Symbol,Any}, ::Symbol) at ./dict.jl:478
 [2] _graph(::ONNX.Types.Graph) at /home/timclements/.julia/packages/ONNX/iz0dL/src/graph/graph.jl:0
 [3] graph(::ONNX.Types.Graph) at /home/timclements/.julia/packages/ONNX/iz0dL/src/graph/graph.jl:92
 [4] code(::ONNX.Types.Graph) at /home/timclements/.julia/packages/ONNX/iz0dL/src/graph/graph.jl:100
 [5] write_julia_file(::String) at /home/timclements/.julia/packages/ONNX/iz0dL/src/convert.jl:235
 [6] load_model(::String) at /home/timclements/.julia/packages/ONNX/iz0dL/src/convert.jl:250
 [7] top-level scope at none:0

It looks like the ConvTranspose operator needs to be added https://github.com/onnx/onnx/blob/master/docs/Operators.md#ConvTranspose

tclements avatar Aug 14 '19 13:08 tclements

@tclements can you file an issue with a title like "Implement ConvTranspose operator"? These key errors are just missing operators that need to be implemented (onnx apparently keeps adding lots of them), so filing an issue for each one will make it easier to track which are missing.

jpsamaroo avatar Aug 14 '19 14:08 jpsamaroo

@jpsamaroo will do!

tclements avatar Aug 14 '19 14:08 tclements