Apollo  6.0
Open source self driving car software
caffe_net.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 
17 #pragma once
18 
19 #include <map>
20 #include <memory>
21 #include <string>
22 #include <utility>
23 #include <vector>
24 
25 #include "caffe/caffe.hpp"
26 
28 
29 namespace apollo {
30 namespace perception {
31 namespace inference {
32 
33 typedef std::shared_ptr<apollo::perception::base::Blob<float>> BlobPtr;
34 
35 class CaffeNet : public Inference {
36  public:
37  CaffeNet(const std::string &net_file, const std::string &model_file,
38  const std::vector<std::string> &outputs);
39 
40  CaffeNet(const std::string &net_file, const std::string &model_file,
41  const std::vector<std::string> &outputs,
42  const std::vector<std::string> &inputs);
43 
44  virtual ~CaffeNet() {}
45 
46  bool Init(const std::map<std::string, std::vector<int>> &shapes) override;
47 
48  void Infer() override;
49  BlobPtr get_blob(const std::string &name) override;
50 
51  protected:
52  bool reshape();
53  bool shape(const std::string &name, std::vector<int> *res);
54  std::shared_ptr<caffe::Net<float>> net_ = nullptr;
55 
56  private:
57  std::string net_file_;
58  std::string model_file_;
59  std::vector<std::string> output_names_;
60  std::vector<std::string> input_names_;
61  BlobMap blobs_;
62 };
63 
64 } // namespace inference
65 } // namespace perception
66 } // namespace apollo
bool Init(const std::map< std::string, std::vector< int >> &shapes) override
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
BlobPtr get_blob(const std::string &name) override
Definition: caffe_net.h:35
virtual ~CaffeNet()
Definition: caffe_net.h:44
std::map< std::string, std::shared_ptr< apollo::perception::base::Blob< float > > > BlobMap
Definition: inference.h:34
std::shared_ptr< caffe::Net< float > > net_
Definition: caffe_net.h:54
CaffeNet(const std::string &net_file, const std::string &model_file, const std::vector< std::string > &outputs)
std::shared_ptr< apollo::perception::base::Blob< float > > BlobPtr
Definition: caffe_net.h:33
bool shape(const std::string &name, std::vector< int > *res)