This is a testing function that returns whether the top label index is the one that's expected.
| 257 | // This is a testing function that returns whether the top label index is the |
| 258 | // one that's expected. |
| 259 | Status CheckTopLabel(const std::vector<Tensor>& outputs, int expected, |
| 260 | bool* is_expected) { |
| 261 | *is_expected = false; |
| 262 | Tensor indices; |
| 263 | Tensor scores; |
| 264 | const int how_many_labels = 1; |
| 265 | TF_RETURN_IF_ERROR(GetTopLabels(outputs, how_many_labels, &indices, &scores)); |
| 266 | tensorflow::TTypes<int32>::Flat indices_flat = indices.flat<int32>(); |
| 267 | if (indices_flat(0) != expected) { |
| 268 | LOG(ERROR) << "Expected label #" << expected << " but got #" |
| 269 | << indices_flat(0); |
| 270 | *is_expected = false; |
| 271 | } else { |
| 272 | *is_expected = true; |
| 273 | } |
| 274 | return Status::OK(); |
| 275 | } |
| 276 | |
| 277 | int main(int argc, char* argv[]) { |
| 278 | // These are the command-line flags the program can understand. |