diff --git a/caffe2/opt/converter.cc b/caffe2/opt/converter.cc index 9e0b6463ec7ed5..17ef12654d1278 100644 --- a/caffe2/opt/converter.cc +++ b/caffe2/opt/converter.cc @@ -84,10 +84,14 @@ OperatorDef Converter::convertToOperatorDef( const nom::repr::NeuralNetOperator* nnOp) { auto* annotation = nnOp->getAnnotation(); // Default to using the stored operator. - if (isa(annotation)) { + if (annotation && isa(annotation)) { return dyn_cast(annotation)->getOperatorDef(); } - CAFFE_THROW("TODO: Cannot yet instantiate OperatorDef from nomnigraph"); + LOG(WARNING) + << "Cannot instantiate this OperatorDef from nomnigraph, falling back"; + caffe2::OperatorDef op; + op.set_type(nnOp->getName()); + return op; } std::vector getKernelShape(std::map argMap) { @@ -156,11 +160,13 @@ class ClipConverter : public Converter { float max = std::numeric_limits::max(); if (argMap.count("min")) { - min = static_cast(argMap["min"].i()); + CAFFE_ENFORCE(argMap["min"].has_f(), "Invalid 'min' argument"); + min = static_cast(argMap["min"].f()); } if (argMap.count("max")) { - max = static_cast(argMap["max"].i()); + CAFFE_ENFORCE(argMap["max"].has_f(), "Invalid 'max' argument"); + max = static_cast(argMap["max"].f()); } return util::make_unique(min, max); @@ -363,13 +369,14 @@ repr::NNModule convertToNNModule( caffe2::OperatorDef convertToOperatorDef( const repr::NNGraph::NodeRef& instrNode) { auto *nnOp = repr::nn::get(instrNode); + auto op_type = nnOp->getName(); auto *annotation = nnOp->getAnnotation(); caffe2::OperatorDef op; - if (ConverterRegistry()->Has(op.type())) { - op = ConverterRegistry()->Create(op.type())->convertToOperatorDef(nnOp); + if (ConverterRegistry()->Has(op_type)) { + op = ConverterRegistry()->Create(op_type)->convertToOperatorDef(nnOp); } else if (!annotation) { - op.set_type(nnOp->getName()); + op.set_type(op_type); } else { if (isa(annotation)) { auto c2_annotation = dyn_cast(annotation);