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.

data_helper.cc 9.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * Copyright 2020-2021 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 "minddata/dataset/include/dataset/data_helper.h"
  17. #include "minddata/dataset/util/json_helper.h"
  18. #include "include/api/status.h"
  19. namespace mindspore {
  20. namespace dataset {
  21. // Create a numbered json file from image folder
  22. Status DataHelper::CreateAlbumIF(const std::vector<char> &in_dir, const std::vector<char> &out_dir) {
  23. auto jh = JsonHelper();
  24. return jh.CreateAlbum(CharToString(in_dir), CharToString(out_dir));
  25. }
  26. // A print method typically used for debugging
  27. void DataHelper::Print(std::ostream &out) const {
  28. out << " Data Helper"
  29. << "\n";
  30. }
  31. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  32. const std::vector<std::vector<char>> &value, const std::vector<char> &out_file) {
  33. auto jh = JsonHelper();
  34. return jh.UpdateArray(CharToString(in_file), CharToString(key), VectorCharToString(value), CharToString(out_file));
  35. }
  36. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  37. const std::vector<bool> &value, const std::vector<char> &out_file) {
  38. auto jh = JsonHelper();
  39. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  40. }
  41. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  42. const std::vector<int8_t> &value, const std::vector<char> &out_file) {
  43. auto jh = JsonHelper();
  44. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  45. }
  46. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  47. const std::vector<uint8_t> &value, const std::vector<char> &out_file) {
  48. auto jh = JsonHelper();
  49. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  50. }
  51. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  52. const std::vector<int16_t> &value, const std::vector<char> &out_file) {
  53. auto jh = JsonHelper();
  54. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  55. }
  56. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  57. const std::vector<uint16_t> &value, const std::vector<char> &out_file) {
  58. auto jh = JsonHelper();
  59. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  60. }
  61. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  62. const std::vector<int32_t> &value, const std::vector<char> &out_file) {
  63. auto jh = JsonHelper();
  64. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  65. }
  66. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  67. const std::vector<uint32_t> &value, const std::vector<char> &out_file) {
  68. auto jh = JsonHelper();
  69. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  70. }
  71. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  72. const std::vector<int64_t> &value, const std::vector<char> &out_file) {
  73. auto jh = JsonHelper();
  74. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  75. }
  76. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  77. const std::vector<uint64_t> &value, const std::vector<char> &out_file) {
  78. auto jh = JsonHelper();
  79. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  80. }
  81. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  82. const std::vector<float> &value, const std::vector<char> &out_file) {
  83. auto jh = JsonHelper();
  84. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  85. }
  86. Status DataHelper::UpdateArrayIF(const std::vector<char> &in_file, const std::vector<char> &key,
  87. const std::vector<double> &value, const std::vector<char> &out_file) {
  88. auto jh = JsonHelper();
  89. return jh.UpdateArray(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  90. }
  91. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key,
  92. const std::vector<char> &value, const std::vector<char> &out_file) {
  93. auto jh = JsonHelper();
  94. return jh.UpdateValue(CharToString(in_file), CharToString(key), CharToString(value), CharToString(out_file));
  95. }
  96. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const bool &value,
  97. const std::vector<char> &out_file) {
  98. auto jh = JsonHelper();
  99. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  100. }
  101. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const int8_t &value,
  102. const std::vector<char> &out_file) {
  103. auto jh = JsonHelper();
  104. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  105. }
  106. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const uint8_t &value,
  107. const std::vector<char> &out_file) {
  108. auto jh = JsonHelper();
  109. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  110. }
  111. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const int16_t &value,
  112. const std::vector<char> &out_file) {
  113. auto jh = JsonHelper();
  114. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  115. }
  116. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const uint16_t &value,
  117. const std::vector<char> &out_file) {
  118. auto jh = JsonHelper();
  119. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  120. }
  121. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const int32_t &value,
  122. const std::vector<char> &out_file) {
  123. auto jh = JsonHelper();
  124. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  125. }
  126. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const uint32_t &value,
  127. const std::vector<char> &out_file) {
  128. auto jh = JsonHelper();
  129. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  130. }
  131. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const int64_t &value,
  132. const std::vector<char> &out_file) {
  133. auto jh = JsonHelper();
  134. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  135. }
  136. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const uint64_t &value,
  137. const std::vector<char> &out_file) {
  138. auto jh = JsonHelper();
  139. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  140. }
  141. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const float &value,
  142. const std::vector<char> &out_file) {
  143. auto jh = JsonHelper();
  144. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  145. }
  146. Status DataHelper::UpdateValueIF(const std::vector<char> &in_file, const std::vector<char> &key, const double &value,
  147. const std::vector<char> &out_file) {
  148. auto jh = JsonHelper();
  149. return jh.UpdateValue(CharToString(in_file), CharToString(key), value, CharToString(out_file));
  150. }
  151. Status DataHelper::RemoveKeyIF(const std::vector<char> &in_file, const std::vector<char> &key,
  152. const std::vector<char> &out_file) {
  153. auto jh = JsonHelper();
  154. return jh.RemoveKey(CharToString(in_file), CharToString(key), CharToString(out_file));
  155. }
  156. size_t DataHelper::DumpData(const unsigned char *tensor_addr, const size_t &tensor_size, void *addr,
  157. const size_t &buffer_size) {
  158. auto jh = JsonHelper();
  159. return jh.DumpData(tensor_addr, tensor_size, addr, buffer_size);
  160. }
  161. } // namespace dataset
  162. } // namespace mindspore