mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary: Since caffe2 and torch have been consolidated, CAFFE2_API should be merged with TORCH_API. Addresses a TODO. Manually edited some references of the removed `CAFFE2_API`: * `CONTRIBUTING.md` * `caffe2/proto/CMakeLists.txt` * `cmake/ProtoBuf.cmake` * `c10/macros/Export.h` * `torch/csrc/WindowsTorchApiMacro.h` Pull Request resolved: https://github.com/pytorch/pytorch/pull/49496 Reviewed By: malfet, samestep Differential Revision: D25600726 Pulled By: janeyx99 fbshipit-source-id: 7e068d959e397ac183c097d7e9a9afeca5ddd782
72 lines
1.8 KiB
C++
72 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <unordered_set>
|
|
#include "caffe2/core/net.h"
|
|
#include "caffe2/core/tensor.h"
|
|
#include "caffe2/predictor/predictor_config.h"
|
|
|
|
namespace caffe2 {
|
|
|
|
class TORCH_API Predictor {
|
|
public:
|
|
using TensorList = std::vector<TensorCPU>;
|
|
using TensorMap = std::unordered_map<std::string, TensorCPU>;
|
|
|
|
Predictor(
|
|
const NetDef& init_net,
|
|
const NetDef& run_net,
|
|
Workspace* parent = nullptr,
|
|
bool run_init = true,
|
|
int optimization = 1);
|
|
|
|
Predictor(PredictorConfig config);
|
|
|
|
virtual ~Predictor() {}
|
|
|
|
// Executes `run_net` on the inputs.
|
|
// The first `inputs.size()` inputs from run_net::external_inputs
|
|
// are shared with the data in `inputs`.
|
|
|
|
// Precondition:
|
|
// inputs.size() <= run_net_.external_inputs.size()
|
|
|
|
// Postcondition:
|
|
// outputs->size() == run_net.external_inputs.size()
|
|
|
|
// NOTE: output is a part of thread local workspace
|
|
// and is only valid until the next predictor execution.
|
|
|
|
// Returns true on success
|
|
virtual bool operator()(const TensorList& inputs, TensorList* outputs);
|
|
|
|
// Similar to run, but consumes a map of name to tensor as input
|
|
bool operator()(const TensorMap& inputs, TensorList* outputs);
|
|
|
|
// Similar to the other run fns, except inputs and outputs are both maps of
|
|
// string name to tensor.
|
|
bool operator()(const TensorMap& inputs, TensorMap* outputs);
|
|
|
|
const NetDef& def() const {
|
|
return *config_.predict_net;
|
|
};
|
|
|
|
Workspace* ws() {
|
|
return config_.ws.get();
|
|
};
|
|
|
|
const std::vector<std::string>& input_names() const {
|
|
return config_.input_names;
|
|
}
|
|
|
|
const std::vector<std::string>& output_names() const {
|
|
return config_.output_names;
|
|
}
|
|
|
|
private:
|
|
bool run_map_workspace(const TensorMap& inputs);
|
|
|
|
protected:
|
|
PredictorConfig config_;
|
|
};
|
|
} // namespace caffe2
|