| 32 | constexpr int64 InferenceContext::kUnknownDim; |
| 33 | |
| 34 | InferenceContext::InferenceContext( |
| 35 | int graph_def_version, const NodeDef* node_def, const OpDef& op_def, |
| 36 | const std::vector<TensorShapeProto>& input_shapes, |
| 37 | const std::vector<const Tensor*>& input_tensors, |
| 38 | const std::vector<TensorShapeProto>& input_tensors_as_shapes, |
| 39 | const std::vector< |
| 40 | std::unique_ptr<std::vector<std::pair<TensorShapeProto, DataType>>>>& |
| 41 | input_handle_shapes_and_types) |
| 42 | : graph_def_version_(graph_def_version), |
| 43 | node_def_(CHECK_NOTNULL(node_def)) { |
| 44 | std::vector<ShapeHandle> input_tensors_as_shape_handles; |
| 45 | input_tensors_as_shape_handles.reserve(input_tensors_as_shapes.size()); |
| 46 | for (const TensorShapeProto& p : input_tensors_as_shapes) { |
| 47 | ShapeHandle shape; |
| 48 | construction_status_.Update(MakeShapeFromShapeProto(p, &shape)); |
| 49 | if (!construction_status_.ok()) { |
| 50 | return; |
| 51 | } |
| 52 | input_tensors_as_shape_handles.push_back(shape); |
| 53 | } |
| 54 | PreInputInit(op_def, input_tensors, input_tensors_as_shape_handles); |
| 55 | if (!construction_status_.ok()) return; |
| 56 | inputs_.reserve(input_shapes.size()); |
| 57 | for (const TensorShapeProto& p : input_shapes) { |
| 58 | ShapeHandle shape; |
| 59 | construction_status_.Update(MakeShapeFromShapeProto(p, &shape)); |
| 60 | if (!construction_status_.ok()) { |
| 61 | return; |
| 62 | } |
| 63 | inputs_.push_back(shape); |
| 64 | } |
| 65 | |
| 66 | std::vector<std::unique_ptr<std::vector<ShapeAndType>>> handle_data( |
| 67 | input_shapes.size()); |
| 68 | for (int i = 0; i < input_handle_shapes_and_types.size(); ++i) { |
| 69 | const auto& v = input_handle_shapes_and_types[i]; |
| 70 | if (v == nullptr) { |
| 71 | continue; |
| 72 | } |
| 73 | handle_data[i].reset(new std::vector<ShapeAndType>(v->size())); |
| 74 | auto& new_v = *handle_data[i]; |
| 75 | for (int j = 0; j < v->size(); ++j) { |
| 76 | const auto& p = (*v)[j]; |
| 77 | construction_status_.Update( |
| 78 | MakeShapeFromShapeProto(p.first, &new_v[j].shape)); |
| 79 | if (!construction_status_.ok()) { |
| 80 | return; |
| 81 | } |
| 82 | new_v[j].dtype = p.second; |
| 83 | } |
| 84 | } |
| 85 | PostInputInit(std::move(handle_data)); |
| 86 | } |
| 87 | |
| 88 | // Same as above, but with PartialTensorShape instead of TensorShapeProto |
| 89 | InferenceContext::InferenceContext( |