Apollo  6.0
Open source self driving car software
util.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2018 The Apollo Authors. All Rights Reserved.
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 #pragma once
17 
18 #include <fstream>
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
26 
27 namespace apollo {
28 namespace perception {
29 namespace inference {
30 
31 template <typename T>
32 void load_data(const std::string &filename, std::vector<T> *outputs) {
33  std::ifstream ifs(filename, std::ifstream::in);
34 
35  if (ifs.good()) {
36  outputs->clear();
37  T output;
38  while (ifs >> output) {
39  outputs->push_back(output);
40  }
41  ifs.close();
42  }
43 }
44 
45 std::shared_ptr<float> load_binary_data(const std::string &filename);
46 
47 bool write_result(const std::string &out_path,
48  const std::vector<float> &results);
49 bool write_result(const std::string &out_path,
50  const std::map<std::string, std::vector<float>> &results);
51 } // namespace inference
52 } // namespace perception
53 } // namespace apollo
void load_data(const std::string &filename, std::vector< T > *outputs)
Definition: util.h:32
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
std::shared_ptr< float > load_binary_data(const std::string &filename)
bool write_result(const std::string &out_path, const std::vector< float > &results)