微软libcaffe封装成dll和lib!!!

Windows下利用VS使用Caffe可以为开发者提供很好的体验,但是每次编译的时候的总是十分钟的时间在改代码,剩下50分钟在编译的过程中,另外在实际图像分类开发中,很多情况下我们可能只需要一两个函数,所以怎么把caffe的classfy封装成我们需要的dll和lib,可以不依赖caffe的框架,在新建的解决方案中,可以直接调用。
本文主要封装了两个版本的caffe
1:happynear版本:https://github.com/happynear/caffe-windows
http://blog.csdn.net/sinat_30071459/article/details/51823390
以上版本主要参考了小咸鱼的博客,给我提供了很大的帮助,大家可以按照他的方法
2:微软caffe版本:
1:编译微软caffe http://blog.csdn.net/shakevincent/article/details/51694686
2:添加需要的文件:
添加classification.h

#ifndef CLASSIFICATION_H_
#define CLASSIFICATION_H_

#include <caffe/caffe.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iosfwd>
#include <memory>
#include <utility>
#include <vector>
#include <iostream>
#include <string>
#include <time.h>

using namespace caffe;
using std::string;
typedef std::pair<int, float> Prediction;

class  ClassifierImpl {
public:
    ClassifierImpl(const string& model_file,
        const string& trained_file,
        const string& mean_file
        );

    std::vector<Prediction>  Classify(const cv::Mat& img, int N = 2);
private:
    void SetMean(const string& mean_file);

    std::vector<float> Predict(const cv::Mat& img);

    void WrapInputLayer(std::vector<cv::Mat>* input_channels);

    void Preprocess(const cv::Mat& img,
        std::vector<cv::Mat>* input_channels);

private:
    shared_ptr<Net<float> > net_;
    cv::Size input_geometry_;
    int num_channels_;
    cv::Mat mean_;
};
#endif

添加classification.cpp

#include "classification.h"

ClassifierImpl::ClassifierImpl(const string& model_file,
    const string& trained_file,
    const string& mean_file) {
#ifdef CPU_ONLY
    Caffe::set_mode(Caffe::CPU);
#else
    Caffe::set_mode(Caffe::GPU);
#endif

    /* Load the network. */
    net_.reset(new Net<float>(model_file, TEST));
    net_->CopyTrainedLayersFrom(trained_file);

    CHECK_EQ(net_->num_inputs(), 1) << "Network should have exactly o
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值