Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
IanButterworth opened this issue Jul 15, 2019 · 10 comments
Open

Comments

@IanButterworth
Copy link

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

@staticfloat
Copy link
Contributor

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

@ayush-1506
Copy link
Member

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

@DhairyaLGandhi
Copy link
Member

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?

@ayush-1506
Copy link
Member

@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.

@DhairyaLGandhi
Copy link
Member

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.

@ayush-1506
Copy link
Member

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.

@IanButterworth
Copy link
Author

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!

@tclements
Copy link

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

@jpsamaroo
Copy link

@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.

@tclements
Copy link

@jpsamaroo will do!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants