永續(xù)合約及合約交易系統(tǒng)開(kāi)發(fā)需求項(xiàng)目丨永續(xù)合約/合約交易所源碼程序
web3.js是一個(gè)JavaScript API庫(kù)。要讓DApp在以太坊上運(yùn)行,我們可以使用web3.js庫(kù)提供的web3對(duì)象。web3.js通過(guò)RPC調(diào)用與本地節(jié)點(diǎn)通信,它可以與任何公開(kāi)RPC層的以太坊節(jié)點(diǎn)一起使用。web3包含eth對(duì)象-web3.eth(用于與以太坊區(qū)塊鏈交互)和shh對(duì)象-web3.shh(用于與Whisper交互)
class PFLD::Impl {
public:
? ? Impl() {
? ? ? ? device_ = 0;
? ? ? ? precision_ = 0;
? ? ? ? power_ = 0;
? ? ? ? memory_ = 0;
? ? ? ??
? ? ? ? initialized_ = false;
? ? }
? ? ~Impl() {
? ? ? ? landmarker_->releaseModel();
? ? ? ? landmarker_->releaseSession(session_);
? ? }
?
? ? int LoadModel(const char* root_path);
? ? int ExtractKeypoints(const cv::Mat& img_face, std::vector<cv::Point2f>* keypoints);? ??
?
? ? std::shared_ptr<MNN::Interpreter> landmarker_;
? ? const int inputSize_ = 96;
? ??
? ? int device_;
? ? int precision_;
? ? int power_;
? ? int memory_;
?
? ? MNN::Session* session_ = nullptr;
? ? MNN::Tensor* input_tensor_ = nullptr;
? ? bool initialized_;
};
int PFLD::Impl::LoadModel(const char* root_path) {
? ? std::string model_file = std::string(root_path) + "/pfld-lite.mnn";
? ? landmarker_ = std::shared_ptr<MNN::Interpreter>(MNN::Interpreter::createFromFile(model_file.c_str()));
? ??
? ? MNN::ScheduleConfig config;
? ? config.numThread = 1;
? ? config.type? ? ? = static_cast<MNNForwardType>(device_);
?
? ? MNN::BackendConfig backendConfig;
? ? backendConfig.precision = (MNN::BackendConfig::PrecisionMode)precision_;
? ? backendConfig.power = (MNN::BackendConfig::PowerMode) power_;
? ? backendConfig.memory = (MNN::BackendConfig::MemoryMode) memory_;
? ? config.backendConfig = &backendConfig;
? ? session_ = landmarker_->createSession(config);
?
? ? // nhwc to nchw
? ? std::vector<int> dims{1, inputSize_, inputSize_, 3};
? ? input_tensor_ = MNN::Tensor::create<float>(dims, NULL, MNN::Tensor::TENSORFLOW);
?
? ? initialized_ = true;
?
? ? return 0;
}