You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MDToDApi.cc 18 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "MDToDApi.h" //NOLINT
  17. #include <string>
  18. #include <fstream>
  19. #include <iostream>
  20. #include <memory>
  21. #include <unordered_map>
  22. #include <utility>
  23. #include <vector>
  24. #include <set>
  25. #include "album_op_android.h" //NOLINT
  26. #include "minddata/dataset/include/execute.h"
  27. #include "minddata/dataset/include/type_id.h"
  28. #include "minddata/dataset/util/path.h"
  29. #include "minddata/dataset/include/vision.h"
  30. #include "minddata/dataset/util/data_helper.h"
  31. #include "minddata/dataset/core/de_tensor.h"
  32. #include "include/api/types.h"
  33. #if defined(__ANDROID__) || defined(ANDROID)
  34. #include <android/log.h>
  35. #include <android/asset_manager.h>
  36. #endif
  37. using mindspore::dataset::Path;
  38. using mindspore::dataset::Tensor;
  39. using TensorOperation = mindspore::dataset::TensorOperation;
  40. using RotateOperation = mindspore::dataset::vision::RotateOperation;
  41. using mindspore::LogStream;
  42. using mindspore::MsLogLevel::DEBUG;
  43. using mindspore::MsLogLevel::ERROR;
  44. using mindspore::MsLogLevel::INFO;
  45. using mindspore::Status;
  46. using mindspore::dataset::BorderType;
  47. using mindspore::dataset::InterpolationMode;
  48. class MDToDApi {
  49. public:
  50. std::shared_ptr<mindspore::dataset::AlbumOp> _iter;
  51. std::vector<std::shared_ptr<TensorOperation>> _augs;
  52. std::string _storage_folder;
  53. std::string _folder_path;
  54. bool _hasBatch;
  55. int64_t _file_id;
  56. public:
  57. MDToDApi() : _iter(nullptr), _augs({}), _storage_folder(""), _file_id(-1), _hasBatch(false) {
  58. MS_LOG(INFO) << "MDToDAPI Call constructor";
  59. }
  60. ~MDToDApi() {
  61. MS_LOG(INFO) << "MDToDAPI Call destractor";
  62. // dereference dataset and iterator
  63. _augs.clear();
  64. }
  65. };
  66. std::vector<std::string> MDToDBuffToVector(MDToDBuff_t StrBuff) {
  67. std::vector<std::string> strVector;
  68. if (StrBuff.DataSize > 0) {
  69. const char *p = reinterpret_cast<char *>(StrBuff.Buff);
  70. do {
  71. strVector.push_back(std::string(p));
  72. p += strVector.back().size() + 1;
  73. } while (p < reinterpret_cast<char *>(StrBuff.Buff) + StrBuff.DataSize);
  74. }
  75. return strVector;
  76. }
  77. extern "C"
  78. int MDToDApi_pathTest(const char* path) {
  79. Path f(path);
  80. MS_LOG(INFO) << f.Exists() << f.IsDirectory() << f.ParentPath();
  81. // Print out the first few items in the directory
  82. auto dir_it = Path::DirIterator::OpenDirectory(&f);
  83. MS_LOG(INFO) << dir_it.get();
  84. int i = 0;
  85. while (dir_it->hasNext()) {
  86. Path v = dir_it->next();
  87. MS_LOG(INFO) << v.toString() << "\n";
  88. i++;
  89. if (i > 5) break;
  90. }
  91. return 0;
  92. }
  93. extern "C" MDToDApi *MDToDApi_createPipeLine(MDToDConf_t MDConf) {
  94. MS_LOG(INFO) << "Start createPipeLine";
  95. std::string folder_path(MDConf.pFolderPath);
  96. std::string schema_file(MDConf.pSchemFile);
  97. std::vector<std::string> column_names = MDToDBuffToVector(MDConf.columnsToReadBuff);
  98. if (std::find(column_names.begin(), column_names.end(), "id") == column_names.end()) {
  99. MS_LOG(INFO) << "Column id not foud adding it ";
  100. column_names.push_back("id");
  101. }
  102. std::vector<std::shared_ptr<TensorOperation>> mapOperations;
  103. if (std::find(column_names.begin(), column_names.end(), "image") != column_names.end()) {
  104. MS_LOG(INFO) << "Found column image create map with:";
  105. MS_LOG(INFO) << "resize: { " << MDConf.ResizeSizeWH[0] << ", " << MDConf.ResizeSizeWH[1] << " }";
  106. MS_LOG(INFO) << "crop: { " << MDConf.CropSizeWH[0] << ", " << MDConf.CropSizeWH[1] << " }";
  107. MS_LOG(INFO) << "MEAN: { " << MDConf.MEAN[0] << ", " << MDConf.MEAN[1] << ", " << MDConf.MEAN[2] << " }";
  108. MS_LOG(INFO) << "STD: { " << MDConf.STD[0] << ", " << MDConf.STD[1] << ", " << MDConf.STD[2] << " }";
  109. if ((MDConf.ResizeSizeWH[0] != 0) && (MDConf.ResizeSizeWH[1] != 0)) {
  110. std::shared_ptr<TensorOperation> resize_op =
  111. mindspore::dataset::vision::Resize({MDConf.ResizeSizeWH[0], MDConf.ResizeSizeWH[1]});
  112. MS_LOG(INFO) << "Push back resize";
  113. mapOperations.push_back(resize_op);
  114. }
  115. if (1 == MDConf.fixOrientation) {
  116. std::shared_ptr<TensorOperation> rotate_op = mindspore::dataset::vision::Rotate();
  117. MS_LOG(INFO) << "Push back rotate";
  118. mapOperations.push_back(rotate_op);
  119. // hasBatch = true; Batch not currently supported inMInddata-Lite
  120. }
  121. if ((MDConf.CropSizeWH[0] != 0) && (MDConf.CropSizeWH[1] != 0)) {
  122. std::vector<int> Crop(MDConf.CropSizeWH, MDConf.CropSizeWH + 2);
  123. std::shared_ptr<TensorOperation> center_crop_op = mindspore::dataset::vision::CenterCrop(Crop);
  124. MS_LOG(INFO) << "Push back crop";
  125. mapOperations.push_back(center_crop_op);
  126. // hasBatch = true; Batch not currently supported inMInddata-Lite
  127. }
  128. }
  129. MS_LOG(INFO) << "Read id=" << MDConf.fileid << " (-1) for all";
  130. std::shared_ptr<mindspore::dataset::AlbumOp> iter = nullptr;
  131. const std::set<std::string> exts = {};
  132. if (MDConf.fileid > -1) {
  133. // read specific image using SequentialSampler witn
  134. iter =
  135. std::make_shared<mindspore::dataset::AlbumOp>(folder_path, true, schema_file, column_names, exts, MDConf.fileid);
  136. } else {
  137. iter = std::make_shared<mindspore::dataset::AlbumOp>(folder_path, true, schema_file, column_names, exts);
  138. }
  139. // Create objects for the tensor ops
  140. MS_LOG(INFO) << " Create pipline parameters";
  141. MS_LOG(INFO) << "floder path: " << folder_path << " , schema json: " << schema_file;
  142. MS_LOG(INFO) << "Reading columns:";
  143. for (auto str : column_names) {
  144. MS_LOG(INFO) << str << " ";
  145. }
  146. bool hasBatch = false;
  147. MDToDApi *pMDToDApi = new MDToDApi;
  148. pMDToDApi->_iter = iter;
  149. pMDToDApi->_augs = mapOperations;
  150. pMDToDApi->_storage_folder = std::string(MDConf.pStoragePath);
  151. pMDToDApi->_folder_path = folder_path;
  152. pMDToDApi->_hasBatch = hasBatch;
  153. return pMDToDApi;
  154. }
  155. template <typename T>
  156. void MDBuffToVector(const MDToDBuff_t &MDBuff, std::vector<T> *vec) {
  157. vec->clear();
  158. if (MDBuff.DataSize > 0) {
  159. int nofElements = MDBuff.DataSize / sizeof(T);
  160. vec->assign(reinterpret_cast<T *>(MDBuff.Buff), reinterpret_cast<T *>(MDBuff.Buff) + nofElements);
  161. }
  162. }
  163. template <typename T>
  164. void GetValue(std::unordered_map<std::string, std::shared_ptr<Tensor>> row, std::string columnName, T *o) {
  165. auto column = row[columnName];
  166. if (NULL != column) {
  167. MS_LOG(INFO) << "Tensor " << columnName << " shape: " << column->shape() << " type: " << column->type()
  168. << " bytes: " << column->SizeInBytes();
  169. column->GetItemAt<T>(o, {});
  170. MS_LOG(INFO) << columnName << ": " << +*o;
  171. } else {
  172. MS_LOG(INFO) << "Tensor " << columnName << " Not found"
  173. << ".";
  174. *o = 0;
  175. }
  176. }
  177. void GetTensorToBuff(std::unordered_map<std::string, std::shared_ptr<Tensor>> row, std::string columnName,
  178. bool hasBatch, MDToDBuff_t *resBuff) {
  179. auto column = row[columnName];
  180. resBuff->TensorSize[0] = resBuff->TensorSize[1] = resBuff->TensorSize[2] = resBuff->TensorSize[3] =
  181. 0; // Mark all dims do not exist in tensor
  182. int firstDim = (hasBatch) ? 1 : 0;
  183. if (NULL != column) {
  184. MS_LOG(INFO) << "Tensor " << columnName << " shape: " << column->shape() << " type: " << column->type()
  185. << " bytes: " << column->SizeInBytes() << "nof elements: " << column->shape()[firstDim];
  186. auto tesoreShape = column->shape().AsVector();
  187. for (int ix = 0; ix < tesoreShape.size(); ix++) {
  188. MS_LOG(INFO) << "Tensor " << columnName << " shape[" << ix << "] = " << tesoreShape[ix];
  189. resBuff->TensorSize[ix] = tesoreShape[ix];
  190. }
  191. if (!hasBatch) {
  192. for (int ix = 3; ix > 0; ix--) {
  193. resBuff->TensorSize[ix] = resBuff->TensorSize[ix - 1];
  194. }
  195. resBuff->TensorSize[0] = 1;
  196. }
  197. if (column->shape()[firstDim] > 0) {
  198. if (mindspore::dataset::DataType::DE_STRING == column->type()) {
  199. std::string str;
  200. for (int ix = 0; ix < column->shape()[firstDim]; ix++) {
  201. std::string_view strView;
  202. if (hasBatch) {
  203. column->GetItemAt(&strView, {0, ix});
  204. } else {
  205. column->GetItemAt(&strView, {ix});
  206. }
  207. MS_LOG(INFO) << "string " << columnName << "[" << ix << "]:" << strView << " (size: " << strView.size()
  208. << ")";
  209. str.append(strView);
  210. str.push_back('\0');
  211. }
  212. resBuff->DataSize = str.size();
  213. errno_t ret = memcpy_s(resBuff->Buff, resBuff->MaxBuffSize, str.data(), resBuff->DataSize);
  214. if (ret != 0) {
  215. resBuff->DataSize = 0; // memcpy fail amount of data copied is 0
  216. MS_LOG(ERROR) << "memcpy_s return: " << ret;
  217. }
  218. } else {
  219. mindspore::dataset::DataHelper dh;
  220. resBuff->DataSize =
  221. dh.DumpData(column->GetBuffer(), column->SizeInBytes(), resBuff->Buff, resBuff->MaxBuffSize);
  222. }
  223. MS_LOG(INFO) << columnName << " " << resBuff->DataSize
  224. << " bytesCopyed to buff (MaxBuffSize: " << resBuff->MaxBuffSize << ") ";
  225. if (0 == resBuff->DataSize) {
  226. MS_LOG(ERROR) << "COPY FAIL!!!! " << columnName << " Too large"
  227. << "."; // memcpy failed
  228. }
  229. } else {
  230. MS_LOG(INFO) << "Tensor " << columnName << " is empty (has size 0)";
  231. }
  232. } else {
  233. MS_LOG(INFO) << "Tensor " << columnName << " was not read.";
  234. }
  235. }
  236. extern "C" int MDToDApi_GetNext(MDToDApi *pMDToDApi, MDToDResult_t *results) {
  237. MS_LOG(INFO) << "Start GetNext";
  238. if (pMDToDApi == nullptr || pMDToDApi->_iter == nullptr) {
  239. MS_LOG(ERROR) << "GetNext called with null ptr. abort";
  240. return -1;
  241. }
  242. // Set default
  243. results->fileid = -1;
  244. results->embeddingBuff.DataSize = 0;
  245. results->imageBuff.DataSize = 0;
  246. MS_LOG(INFO) << "Start GetNext [1]" << pMDToDApi;
  247. // get next row for dataset
  248. std::unordered_map<std::string, std::shared_ptr<Tensor>> row;
  249. if (pMDToDApi->_iter == nullptr) {
  250. MS_LOG(ERROR) << "GetNext called with no iteratoe. abort";
  251. return -1;
  252. }
  253. // create Execute functions, this replaces Map in Pipeline
  254. bool ret = pMDToDApi->_iter->GetNextRow(&row);
  255. uint32_t orientation = 0;
  256. if (row.size() != 0 && ret) {
  257. GetValue<uint32_t>(row, "orientation", &orientation);
  258. MS_LOG(INFO) << "get orientation from row = " << orientation;
  259. if ((pMDToDApi->_augs).size() > 0) {
  260. // String and Tensors
  261. // for each operation, run eager mode, single threaded operation, will have to memcpy
  262. // regardless
  263. for (int i = 0; i < (pMDToDApi->_augs).size(); i++) {
  264. // each Execute call will invoke a memcpy, this cannot really be optimized further
  265. // for this use case, std move is added for fail save.
  266. if (pMDToDApi->_augs[i]->Name() == "Rotate") {
  267. if (orientation > 1) {
  268. RotateOperation *p = static_cast<RotateOperation *>(pMDToDApi->_augs[i].get());
  269. p->setAngle(orientation);
  270. orientation = 0; // clear oriation filed if already performed
  271. } else {
  272. continue;
  273. }
  274. }
  275. mindspore::MSTensor image(std::make_shared<mindspore::dataset::DETensor>(row["image"]));
  276. (void)mindspore::dataset::Execute((pMDToDApi->_augs)[i])(image, &image);
  277. mindspore::dataset::Tensor::CreateFromMemory(
  278. mindspore::dataset::TensorShape(image.Shape()),
  279. mindspore::dataset::MSTypeToDEType(static_cast<mindspore::TypeId>(image.DataType())),
  280. (const uint8_t *)(image.Data().get()), &(row["image"]));
  281. if (row["image"] == nullptr) {
  282. // nullptr means that the eager mode image processing failed, we fail in this case
  283. return -1;
  284. }
  285. }
  286. }
  287. // FILE ID
  288. GetValue<int64_t>(row, "id", &results->fileid);
  289. pMDToDApi->_file_id = results->fileid; // hold current file id to enable embeddings update (no itr->getCurrent)
  290. // IS FOR TRAIN
  291. GetValue<int32_t>(row, "_isForTrain", &results->isForTrain);
  292. GetValue<int32_t>(row, "_noOfFaces", &results->noOfFaces);
  293. results->orientation = (int32_t)orientation;
  294. // String and Tensors
  295. GetTensorToBuff(row, "image_filename", pMDToDApi->_hasBatch, &results->fileNameBuff);
  296. GetTensorToBuff(row, "image", pMDToDApi->_hasBatch, &results->imageBuff);
  297. GetTensorToBuff(row, "_embedding", pMDToDApi->_hasBatch, &results->embeddingBuff);
  298. GetTensorToBuff(row, "label", pMDToDApi->_hasBatch, &results->labelBuff);
  299. GetTensorToBuff(row, "_boundingBoxes", pMDToDApi->_hasBatch, &results->boundingBoxesBuff);
  300. GetTensorToBuff(row, "_confidences", pMDToDApi->_hasBatch, &results->confidencesBuff);
  301. GetTensorToBuff(row, "_landmarks", pMDToDApi->_hasBatch, &results->landmarksBuff);
  302. GetTensorToBuff(row, "_faceFileNames", pMDToDApi->_hasBatch, &results->faceFileNamesBuff);
  303. GetTensorToBuff(row, "_imageQualities", pMDToDApi->_hasBatch, &results->imageQualitiesBuff);
  304. GetTensorToBuff(row, "_faceEmbeddings", pMDToDApi->_hasBatch, &results->faceEmbeddingsBuff);
  305. return 0;
  306. }
  307. return -1;
  308. }
  309. extern "C" int MDToDApi_Stop(MDToDApi *pMDToDApi) {
  310. // Manually terminate the pipeline
  311. MS_LOG(INFO) << "pipline stopped";
  312. return 0;
  313. }
  314. extern "C" int MDToDApi_Destroy(MDToDApi *pMDToDApi) {
  315. MS_LOG(INFO) << "pipline deleted start";
  316. delete pMDToDApi;
  317. MS_LOG(INFO) << "pipline deleted end";
  318. return 0;
  319. }
  320. int GetJsonFullFileName(const MDToDApi *pMDToDApi, std::string *filePath) {
  321. int64_t file_id = pMDToDApi->_file_id;
  322. if (file_id < 0) {
  323. MS_LOG(ERROR) << "Illegal file ID to update: " << file_id << ".";
  324. return -1;
  325. }
  326. std::string converted = std::to_string(pMDToDApi->_file_id);
  327. *filePath = pMDToDApi->_folder_path + "/" + converted + ".json";
  328. return 0;
  329. }
  330. extern "C" int MDToDApi_UpdateEmbeding(MDToDApi *pMDToDApi, const char *column, float *emmbeddings,
  331. size_t emmbeddingsSize) {
  332. auto columnName = std::string(column);
  333. MS_LOG(INFO) << "Start Update " << columnName;
  334. std::string converted = std::to_string(pMDToDApi->_file_id);
  335. std::string embedding_file_path = pMDToDApi->_storage_folder + "/" + converted + columnName + ".bin";
  336. mindspore::dataset::DataHelper dh;
  337. MS_LOG(INFO) << "Try to Save file " << embedding_file_path;
  338. std::vector<float> bin_content(emmbeddings, emmbeddings + emmbeddingsSize);
  339. Status rc = dh.template WriteBinFile<float>(embedding_file_path, bin_content);
  340. if (rc.IsError()) {
  341. MS_LOG(ERROR) << "Fail to write embedding file: " << embedding_file_path << ".";
  342. return -1;
  343. }
  344. MS_LOG(INFO) << "Saved file " << embedding_file_path;
  345. std::string file_path;
  346. if (0 != GetJsonFullFileName(pMDToDApi, &file_path)) {
  347. MS_LOG(ERROR) << "Failed to update " << columnName;
  348. return -1;
  349. }
  350. MS_LOG(INFO) << "Updating json file: " << file_path;
  351. rc = dh.UpdateValue(file_path, std::string(column), embedding_file_path);
  352. if (rc.IsError()) {
  353. MS_LOG(ERROR) << "Fail to update json: " << file_path << ".";
  354. return -1;
  355. }
  356. return 0;
  357. }
  358. extern "C" int MDToDApi_UpdateStringArray(MDToDApi *pMDToDApi, const char *column, MDToDBuff_t MDbuff) {
  359. auto columnName = std::string(column);
  360. std::string file_path;
  361. if (0 != GetJsonFullFileName(pMDToDApi, &file_path)) {
  362. MS_LOG(ERROR) << "Failed to update " << columnName;
  363. return -1;
  364. }
  365. MS_LOG(INFO) << "Start Update string Array column: " << columnName << " in file " << file_path;
  366. mindspore::dataset::DataHelper dh;
  367. std::vector<std::string> strVec;
  368. if (MDbuff.DataSize > 0) {
  369. const char *p = reinterpret_cast<char *>(MDbuff.Buff);
  370. do {
  371. strVec.push_back(std::string(p));
  372. p += strVec.back().size() + 1;
  373. } while (p < reinterpret_cast<char *>(MDbuff.Buff) + MDbuff.DataSize);
  374. }
  375. Status rc = dh.UpdateArray(file_path, columnName, strVec);
  376. if (rc.IsError()) {
  377. MS_LOG(ERROR) << "Fail to update json: " << file_path << ".";
  378. return -1;
  379. }
  380. return 0;
  381. }
  382. extern "C" int MDToDApi_UpdateFloatArray(MDToDApi *pMDToDApi, const char *column, MDToDBuff_t MDBuff) {
  383. auto columnName = std::string(column);
  384. std::string file_path;
  385. if (0 != GetJsonFullFileName(pMDToDApi, &file_path)) {
  386. MS_LOG(ERROR) << "Failed to updaet " << columnName;
  387. return -1;
  388. }
  389. MS_LOG(INFO) << "Start Update float Array column: " << columnName << " in file " << file_path;
  390. mindspore::dataset::DataHelper dh;
  391. std::vector<float> vec;
  392. MDBuffToVector<float>(MDBuff, &vec);
  393. Status rc = dh.UpdateArray<float>(file_path, columnName, vec);
  394. if (rc.IsError()) {
  395. MS_LOG(ERROR) << "Fail to update json: " << file_path << ".";
  396. return -1;
  397. }
  398. return 0;
  399. }
  400. extern "C" int MDToDApi_UpdateIsForTrain(MDToDApi *pMDToDApi, int32_t isForTrain) {
  401. int64_t file_id = pMDToDApi->_file_id;
  402. MS_LOG(INFO) << "Start Update isForTRain for id: " << file_id << " To " << isForTrain;
  403. if (file_id < 0) return -1;
  404. std::string converted = std::to_string(pMDToDApi->_file_id);
  405. std::string file_path = pMDToDApi->_folder_path + "/" + converted + ".json";
  406. mindspore::dataset::DataHelper dh;
  407. MS_LOG(INFO) << "Updating file: " << file_path;
  408. Status rc = dh.UpdateValue<int32_t>(file_path, "_isForTrain", isForTrain, "");
  409. if (rc.IsError()) {
  410. MS_LOG(ERROR) << "Fail to update json: " << file_path << ".";
  411. return -1;
  412. }
  413. return 0;
  414. }
  415. extern "C" int MDToDApi_UpdateNoOfFaces(MDToDApi *pMDToDApi, int32_t noOfFaces) {
  416. int64_t file_id = pMDToDApi->_file_id;
  417. MS_LOG(INFO) << "Start Update noOfFaces for id: " << file_id << " To " << noOfFaces;
  418. if (file_id < 0) return -1;
  419. std::string converted = std::to_string(pMDToDApi->_file_id);
  420. std::string file_path = pMDToDApi->_folder_path + "/" + converted + ".json";
  421. mindspore::dataset::DataHelper dh;
  422. MS_LOG(INFO) << "Updating file: " << file_path;
  423. Status rc = dh.UpdateValue<int32_t>(file_path, "_noOfFaces", noOfFaces, "");
  424. if (rc.IsError()) {
  425. MS_LOG(ERROR) << "Fail to update json: " << file_path << ".";
  426. return -1;
  427. }
  428. return 0;
  429. }