| 263 | } |
| 264 | |
| 265 | void CreateIntTensorConst(const string& name, const std::vector<int32>& data, |
| 266 | const std::vector<int32>& shape, |
| 267 | GraphDef* tensorflow_graph) { |
| 268 | if (HasAlreadyExportedConst(name, *tensorflow_graph)) { |
| 269 | return; |
| 270 | } |
| 271 | tensorflow::NodeDef* const_op = tensorflow_graph->add_node(); |
| 272 | const_op->set_op("Const"); |
| 273 | const_op->set_name(name); |
| 274 | (*const_op->mutable_attr())["dtype"].set_type(DT_INT32); |
| 275 | auto* tensor = (*const_op->mutable_attr())["value"].mutable_tensor(); |
| 276 | tensor->set_dtype(DT_INT32); |
| 277 | for (auto index : data) { |
| 278 | tensor->add_int_val(index); |
| 279 | } |
| 280 | auto* tensor_shape = tensor->mutable_tensor_shape(); |
| 281 | int num_elements = 1; |
| 282 | for (int size : shape) { |
| 283 | tensor_shape->add_dim()->set_size(size); |
| 284 | num_elements *= size; |
| 285 | } |
| 286 | CHECK_EQ(num_elements, data.size()); |
| 287 | } |
| 288 | |
| 289 | void ConvertComplex64TensorConst(const Model& model, const string& name, |
| 290 | GraphDef* tensorflow_graph) { |