!9848 fix nullptr error when set out shape and type

From: @liubuyu
Reviewed-by: @kisnwang
Signed-off-by:
pull/9848/MERGE
mindspore-ci-bot 4 years ago committed by Gitee
commit 8c98fd301c

@ -833,22 +833,35 @@ void AnfRuntimeAlgorithm::SetOutputInferTypeAndShape(const std::vector<TypeId> &
} else if (shapes.size() == 1) { } else if (shapes.size() == 1) {
// single output handle // single output handle
ShapeVector shape_int; ShapeVector shape_int;
auto max_shape = GetOutputMaxShape(node_ptr, 0); auto abstract_ptr = node_ptr->abstract();
auto min_shape = GetOutputMinShape(node_ptr, 0); abstract::AbstractTensorPtr abstract = nullptr;
std::transform(shapes[0].begin(), shapes[0].end(), std::back_inserter(shape_int), SizeToLong); if (abstract_ptr != nullptr) {
auto abstract = std::make_shared<AbstractTensor>( auto max_shape = GetOutputMaxShape(node_ptr, 0);
TypeIdToType(types[0]), std::make_shared<abstract::Shape>(shape_int, min_shape, max_shape)); auto min_shape = GetOutputMinShape(node_ptr, 0);
std::transform(shapes[0].begin(), shapes[0].end(), std::back_inserter(shape_int), SizeToLong);
abstract = std::make_shared<AbstractTensor>(TypeIdToType(types[0]),
std::make_shared<abstract::Shape>(shape_int, min_shape, max_shape));
} else {
abstract = std::make_shared<AbstractTensor>(TypeIdToType(types[0]), shape_int);
}
node->set_abstract(abstract); node->set_abstract(abstract);
} else { } else {
// multiple output handle // multiple output handle
std::vector<AbstractBasePtr> abstract_list; std::vector<AbstractBasePtr> abstract_list;
for (size_t i = 0; i < types.size(); ++i) { for (size_t i = 0; i < types.size(); ++i) {
ShapeVector shape_int; ShapeVector shape_int;
auto max_shape = GetOutputMaxShape(node_ptr, i); auto abstract_ptr = node_ptr->abstract();
auto min_shape = GetOutputMinShape(node_ptr, i); abstract::AbstractTensorPtr abstract = nullptr;
std::transform(shapes[i].begin(), shapes[i].end(), std::back_inserter(shape_int), SizeToLong); if (abstract_ptr != nullptr) {
auto abstract = std::make_shared<AbstractTensor>( auto max_shape = GetOutputMaxShape(node_ptr, i);
TypeIdToType(types[i]), std::make_shared<abstract::Shape>(shape_int, min_shape, max_shape)); auto min_shape = GetOutputMinShape(node_ptr, i);
std::transform(shapes[i].begin(), shapes[i].end(), std::back_inserter(shape_int), SizeToLong);
abstract = std::make_shared<AbstractTensor>(TypeIdToType(types[i]),
std::make_shared<abstract::Shape>(shape_int, min_shape, max_shape));
} else {
abstract =
std::make_shared<AbstractTensor>(TypeIdToType(types[i]), std::make_shared<abstract::Shape>(shape_int));
}
abstract_list.emplace_back(abstract); abstract_list.emplace_back(abstract);
} }
auto abstract_tuple = std::make_shared<AbstractTuple>(abstract_list); auto abstract_tuple = std::make_shared<AbstractTuple>(abstract_list);

Loading…
Cancel
Save