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.6 kB

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