Apollo
11.0
自动驾驶开放平台
util.cc
浏览该文件的文档.
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
17
#include "
modules/perception/common/inference/utils/util.h
"
18
#include "
cyber/common/log.h
"
19
20
namespace
apollo
{
21
namespace
perception {
22
namespace
inference {
23
24
std::shared_ptr<float>
load_binary_data
(
const
std::string &filename) {
25
std::ifstream ifs(filename, std::ifstream::binary);
26
if
(!ifs) {
27
return
nullptr
;
28
}
29
30
ifs.seekg(0, ifs.end);
31
int
length =
static_cast<
int
>
(ifs.tellg() /
sizeof
(float));
32
ifs.seekg(0, ifs.beg);
33
std::shared_ptr<float> outputs;
34
outputs.reset(
new
float
[length]);
35
ifs.read(
reinterpret_cast<
char
*
>
(outputs.get()),
sizeof
(
float
) * length);
36
ifs.close();
37
return
outputs;
38
}
39
40
bool
write_result
(
const
std::string &out_path,
41
const
std::vector<float> &results) {
42
std::ofstream outf(out_path, std::ios::binary | std::ios::out);
43
if
(!outf.is_open()) {
44
AINFO
<<
"Cannot open output file: "
<< out_path;
45
return
false
;
46
}
47
outf.write(
reinterpret_cast<
const
char
*
>
(results.data()),
48
sizeof
(
float
) * results.size());
49
outf.close();
50
return
true
;
51
}
52
53
}
// namespace inference
54
}
// namespace perception
55
}
// namespace apollo
log.h
AINFO
#define AINFO
Definition
log.h:42
util.h
apollo::perception::inference::load_binary_data
std::shared_ptr< float > load_binary_data(const std::string &filename)
Definition
util.cc:24
apollo::perception::inference::write_result
bool write_result(const std::string &out_path, const std::vector< float > &results)
Definition
util.cc:40
apollo
class register implement
Definition
arena_queue.h:37
modules
perception
common
inference
utils
util.cc