Unable to compile VGG16 from keras.applications

I have ran example from keras tutorial with resnet50 and it worked great. But after that I decided to try different model from keras and it failed. The minimal snippet to reproduce the error:

import keras
import nnvm
import tvm
model = keras.applications.vgg16.VGG16(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)
sym, params = nnvm.frontend.from_keras(model)
target = 'cuda'
shape_dict = {model.layers[0].name: (1, 3, 224, 224)}

with nnvm.compiler.build_config(opt_level=0):
    graph, lib, params = nnvm.compiler.build(sym, target, params=params)

The error I get:

Traceback (most recent call last):
  File "test.py", line 10, in <module>
    graph, lib, params = nnvm.compiler.build(sym, target, params=params)
  File "/Users/lechenko/Development/tvm/nnvm/python/nnvm/compiler/build_module.py", line 294, in build
    graph = graph.apply("GraphFusePartition").apply("GraphFuseCompile")
  File "/Users/lechenko/Development/tvm/nnvm/python/nnvm/graph.py", line 234, in apply
    check_call(_LIB.NNGraphApplyPasses(self.handle, npass, cpass, ctypes.byref(ghandle)))
  File "/Users/lechenko/Development/tvm/nnvm/python/nnvm/_base.py", line 75, in check_call
    raise NNVMError(py_str(_LIB.NNGetLastError()))
nnvm._base.NNVMError: [13:13:32] /Users/lechenko/Development/tvm/nnvm/src/top/nn/nn.cc:612: Check failed: pad_width.ndim() == inputs[0]->shape.size() && pad_width[0].ndim() == 2 Illegal pad_width

Stack trace returned 10 entries:
[bt] (0) 0   libnnvm_compiler.dylib              0x000000011ad77470 dmlc::StackTrace() + 288
[bt] (1) 1   libnnvm_compiler.dylib              0x000000011ad7720f dmlc::LogMessageFatal::~LogMessageFatal() + 47
[bt] (2) 2   libnnvm_compiler.dylib              0x000000011aea176d std::__1::__function::__func<nnvm::top::$_18, std::__1::allocator<nnvm::top::$_18>, tvm::Array<tvm::Tensor, void> (nnvm::NodeAttrs const&, tvm::Array<tvm::Tensor, void> const&, tvm::Array<tvm::Tensor, void> const&)>::operator()(nnvm::NodeAttrs const&, tvm::Array<tvm::Tensor, void> const&, tvm::Array<tvm::Tensor, void> const&) + 525
[bt] (3) 3   libnnvm_compiler.dylib              0x000000011adf857e nnvm::compiler::CompileEngine::GetScheduleArgs(nnvm::Graph, tvm::Array<tvm::Tensor, void> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, tvm::Array<tvm::Tensor, void>*) + 6190
[bt] (4) 4   libnnvm_compiler.dylib              0x000000011adf60f4 nnvm::compiler::CompileEngine::DoLower(nnvm::Graph, tvm::Array<tvm::Tensor, void> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) + 644
[bt] (5) 5   libnnvm_compiler.dylib              0x000000011adf5573 nnvm::compiler::CompileEngine::Lower(nnvm::Graph, tvm::Array<tvm::Tensor, void> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) + 627
[bt] (6) 6   libnnvm_compiler.dylib              0x000000011adf524d nnvm::compiler::GraphLower(nnvm::Graph, tvm::Array<tvm::Tensor, void> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int) + 333
[bt] (7) 7   libnnvm_compiler.dylib              0x000000011ae184d3 nnvm::compiler::GraphFuseCompile(nnvm::Graph) + 8835
[bt] (8) 8   libnnvm_compiler.dylib              0x000000011adab921 nnvm::Graph std::__1::__invoke_void_return_wrapper<nnvm::Graph>::__call<nnvm::Graph (*&)(nnvm::Graph), nnvm::Graph>(nnvm::Graph (*&&&)(nnvm::Graph), nnvm::Graph&&) + 209
[bt] (9) 9   libnnvm_compiler.dylib              0x000000011adab812 std::__1::__function::__func<nnvm::Graph (*)(nnvm::Graph), std::__1::allocator<nnvm::Graph (*)(nnvm::Graph)>, nnvm::Graph (nnvm::Graph)>::operator()(nnvm::Graph&&) + 18

My environment:
absl-py==0.2.2
astor==0.7.1
decorator==4.3.0
gast==0.2.0
grpcio==1.13.0
h5py==2.8.0
Keras==2.2.0
Keras-Applications==1.0.2
Keras-Preprocessing==1.0.1
Markdown==2.6.11
nnvm==0.8.0
numpy==1.14.5
protobuf==3.6.0
PyYAML==3.13
scipy==1.1.0
six==1.11.0
tensorboard==1.9.0
tensorflow==1.9.0
termcolor==1.1.0
topi==0.4.0
tvm==0.4.0
Werkzeug==0.14.1

My python is Python 3.6.3 :: Anaconda, Inc.

I tried latest master. Has any ideas why I get this error?

Looks like you forgot to pass shape_dict to nnvm.compiler.build.

graph, lib, params = nnvm.compiler.build(sym, target, shape_dict, params=params)

I think this should work.

1 Like

Thank you, my bad. it works now.

1 Like