| 239 | } |
| 240 | |
| 241 | void ConvertIntTensorConst(const Model& model, const string& name, |
| 242 | GraphDef* tensorflow_graph) { |
| 243 | if (HasAlreadyExportedConst(name, *tensorflow_graph)) { |
| 244 | return; |
| 245 | } |
| 246 | CHECK(model.HasArray(name)); |
| 247 | const auto& array = model.GetArray(name); |
| 248 | tensorflow::NodeDef* const_op = tensorflow_graph->add_node(); |
| 249 | const_op->set_op("Const"); |
| 250 | const_op->set_name(name); |
| 251 | (*const_op->mutable_attr())["dtype"].set_type(DT_INT32); |
| 252 | auto* tensor = (*const_op->mutable_attr())["value"].mutable_tensor(); |
| 253 | tensor->set_dtype(DT_INT32); |
| 254 | const auto& data = array.GetBuffer<ArrayDataType::kInt32>().data; |
| 255 | for (auto index : data) { |
| 256 | tensor->add_int_val(index); |
| 257 | } |
| 258 | const auto& array_shape = array.shape(); |
| 259 | auto* shape = tensor->mutable_tensor_shape(); |
| 260 | for (int i = 0; i < array_shape.dimensions_count(); i++) { |
| 261 | shape->add_dim()->set_size(array_shape.dims(i)); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | void CreateIntTensorConst(const string& name, const std::vector<int32>& data, |
| 266 | const std::vector<int32>& shape, |
no test coverage detected