TODO(yunluli): Support more tensor types when needed.
| 138 | |
| 139 | // TODO(yunluli): Support more tensor types when needed. |
| 140 | TfLiteStatus InputGenerator::GenerateInput(const string& distribution) { |
| 141 | auto input_tensor_ids = interpreter_->inputs(); |
| 142 | for (auto id : input_tensor_ids) { |
| 143 | auto* tensor = interpreter_->tensor(id); |
| 144 | if (distribution == "UNIFORM") { |
| 145 | switch (tensor->type) { |
| 146 | case kTfLiteInt8: { |
| 147 | auto data = GenerateUniform<int8_t>( |
| 148 | tensor->dims, std::numeric_limits<int8_t>::min(), |
| 149 | std::numeric_limits<int8_t>::max()); |
| 150 | inputs_.push_back(Join(data.data(), data.size(), ",")); |
| 151 | break; |
| 152 | } |
| 153 | case kTfLiteUInt8: { |
| 154 | auto data = GenerateUniform<uint8_t>( |
| 155 | tensor->dims, std::numeric_limits<uint8_t>::min(), |
| 156 | std::numeric_limits<uint8_t>::max()); |
| 157 | inputs_.push_back(Join(data.data(), data.size(), ",")); |
| 158 | break; |
| 159 | } |
| 160 | case kTfLiteFloat32: { |
| 161 | auto data = GenerateUniform<float>(tensor->dims, -1, 1); |
| 162 | inputs_.push_back(JoinDefault(data.data(), data.size(), ",")); |
| 163 | break; |
| 164 | } |
| 165 | default: |
| 166 | fprintf(stderr, "Unsupported input tensor type %s.", |
| 167 | TfLiteTypeGetName(tensor->type)); |
| 168 | break; |
| 169 | } |
| 170 | } else if (distribution == "GAUSSIAN") { |
| 171 | switch (tensor->type) { |
| 172 | case kTfLiteInt8: { |
| 173 | auto data = GenerateGaussian<int8_t>( |
| 174 | tensor->dims, std::numeric_limits<int8_t>::min(), |
| 175 | std::numeric_limits<int8_t>::max()); |
| 176 | inputs_.push_back(Join(data.data(), data.size(), ",")); |
| 177 | break; |
| 178 | } |
| 179 | case kTfLiteUInt8: { |
| 180 | auto data = GenerateGaussian<uint8_t>( |
| 181 | tensor->dims, std::numeric_limits<uint8_t>::min(), |
| 182 | std::numeric_limits<uint8_t>::max()); |
| 183 | inputs_.push_back(Join(data.data(), data.size(), ",")); |
| 184 | break; |
| 185 | } |
| 186 | case kTfLiteFloat32: { |
| 187 | auto data = GenerateGaussian<float>(tensor->dims, -1, 1); |
| 188 | inputs_.push_back(JoinDefault(data.data(), data.size(), ",")); |
| 189 | break; |
| 190 | } |
| 191 | default: |
| 192 | fprintf(stderr, "Unsupported input tensor type %s.", |
| 193 | TfLiteTypeGetName(tensor->type)); |
| 194 | break; |
| 195 | } |
| 196 | } else { |
| 197 | fprintf(stderr, "Unsupported distribution %s.", distribution.c_str()); |