本文主要在windows下编译caffe源码,得到caffe环境
本人在测试中查询了网络上各资料,资料内容如下:
参考网址:
网址:
https://blog.csdn.net/chris_zhangrx/article/details/79096015
https://blog.csdn.net/jfsufeng/article/details/80092468
https://blog.csdn.net/tiaxia1/article/details/81065666
https://blog.csdn.net/vitor_lxy/article/details/89735702
注意:必须python2.7或者python3.5 而且先安装numpy 同时git
1、下载源码:cmd
git clone https://github.com/BVLC/caffe.git
2、修改build_win.cmd文件
在caffe/scripts/build_win.cmd
1)72行:if NOT DEFINED MSVC_VERSION set MSVC_VERSION=15
2)74行:if NOT DEFINED WITH_NINJA set WITH_NINJA=0
3)76行:if NOT DEFINED CPU_ONLY set CPU_ONLY=1
4)81行:if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Debug
5)87行:if NOT DEFINED PYTHON_VERSION set PYTHON_VERSION=3
6)99行:if NOT DEFINED RUN_INSTALL set RUN_INSTALL=1
3、插入:
1)106行:
if "%MSVC_VERSION%"=="15" (
set CMAKE_GENERATOR=Visual Studio 15 2017 Win64
)
4、修改文件:caffe\cmake\WindowsDownloadPrebuiltDependencies.cmake
1)39行插入:set(MSVC_VERSION 1900)
5、运行build_win.cmd
成功会在caffe\caffe\scripts\目录下生成build目录,build目录下会生产"Caffe.sln
如果是Release版本:
只需要修改 文件caffe/scripts/build_win.cmd
1)11行:if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
2)81行:if NOT DEFINED CMAKE_CONFIG set CMAKE_CONFIG=Release
参考网址:
网址:https://blog.csdn.net/guoyk1990/article/details/52909864
数据集:http://yann.lecun.com/exdb/mnist/
具体步骤
1、下载数据文件在:/Release/mnist_data/
2、解压数据文件
3、编辑lenet_solver.prototxt lenet_train_test.prototxt 这些事网络结构
4、编写convert-mnist-data-test-leveldb.bat
convert-mnist-data-test-lmdb.bat
convert-mnist-data-train-leveldb.bat
convert-mnist-data-train-lmdb.bat
5、双击运行bat文件解析数据格式为caffe能识别的
6、编写run_train.bat
run_test.bat
7、双击运行:run_train.bat / run_test.bat 即可
参考网址:
网址:https://www.cnblogs.com/denny402/p/4989514.html
具体步骤
1、下载:https://github.com/google/protobuf
官网:http://code.google.com/p/protobuf/ 需
2、管理员打开VS的命令提示行:
3、cd C:\Users\Katrinali\Desktop\caffeTest\protobuf-master\cmake
4、mkdir build & cd build
Debug版本:
1、cd C:\Users\Katrinali\Desktop\caffeTest\protobuf-master\cmake\build
2、mkdir debug & cd debug
3、cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../../../install ../..
4、nmake
5、nmake install
Release版本:
1、cd C:\Users\Katrinali\Desktop\caffeTest\protobuf-master\cmake\build
2、mkdir release & cd release
3、cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=../../../install ../..
4、nmake
5、nmake install
#最终生成的在:
C:\Users\Katrinali\Desktop\caffeTest\protobuf-master\install
参考网址:
网址:https://blog.csdn.net/maweifei/article/details/80925668
具体步骤:
1、下载:https://github.com/gflags/gflags
https://cmake.org/download/
2、Visual Studio命令提示,输入cmake-gui.exe路径打开
3、输入源代码地址和编译生成工程路径:
:C:/Users/Katrinali/Desktop/caffeTest/gflags/gflags-master
:C:/Users/Katrinali/Desktop/caffeTest/gflags/MyBuild
注:在Cmake过程中,是否添加:CMAKE_INSTALL_PREFIX设置为::/GitCode/Caffe/src/thirdparty/GFlags/install -------------未测试,不过现在是没有使用这个的
4、点击configure,点击generate
5、vs2017打开:
C:\Users\Katrinali\Desktop\caffeTest\gflags\MyBuild\gflags.sln
6、右键ALL_BUILD生成,右键INSTALL生成
7、库目录在:
C:\Users\Katrinali\Desktop\caffeTest\gflags\MyBuild\include
C:\Users\Katrinali\Desktop\caffeTest\gflags\MyBuild\lib
参考网址:
网址:https://www.jianshu.com/p/26fb34206475
具体步骤:
1、下载glog:https://github.com/google/glog
2、编译cmake:
:C:/Users/Katrinali/Desktop/caffeTest/glog-master
:C:/Users/Katrinali/Desktop/caffeTest/glog-master/MyBuild
直接默认编译
3、管理员权限打开vs2017
4、ALL_BUILD、INSTALL
使用:
1、将glog.lib及glog源码\src\windows\glog文件夹拷贝到需要引用的项目中
2、项目添加lib及.h文件
3、添加预处理器定义 GLOG_NO_ABBREVIATED_SEVERITIES
GOOGLE_GLOG_DLL_DECL=
4、#include "glog/logging.h"
using namespace goole;
参考网址:
网址:https://www.cnblogs.com/haiyang21/p/10052691.html
具体步骤:
1、下载OpenBLAS
2、VS2017 打开cmd,执行
1)Debug版本
:mkdir build_debug & cd build_debug
:cmake -G "Visual Studio 15 Win64" -DCMAKE_BUILD_TYPE=Debug ..
2)Release版本
:mkdir build_debug & cd build_release
:cmake -G "Visual Studio 15 Win64" -DCMAKE_BUILD_TYPE=Release ..
3、VS2017管理员权限打开:OpenBLAS.sln
ALL_BUILD INSTALL
参考网址:
python使用网址:https://blog.csdn.net/weixin_41874599/article/details/86631186
c++使用问题汇总:https://blog.csdn.net/maweifei/article/details/80956256
编译教程网址:http://www.voidcn.com/article/p-muaqzduf-cc.html
具体步骤:
编译过程:
1、解压lmdb-mdb.master.zip
2、编写:CMakeLists.txt
3、下载库:https://github.com/barrysteyn/scrypt-windows/tree/master/win
4、从库中找出3个文件分别为:include/unistd.h 、 include/getopt.h 、 getopt.c
5、命令提示符(管理员):cmake -G "Visual Studio 15 Win64" ..
6、管理员打开VS2017 ,ALL_BUILD & INSTALL
使用:
1、把源代码拷入到工程中
2、把编译的库放入
参考网址:
网址:https://github.com/google/leveldb
具体步骤:
1、mkdir build
2、cd build
3、cmake -G "Visual Studio 15 Win64" ..
1、VS2017 打开Debug all_build 再Install
使用:
网址教程:https://www.jianshu.com/p/59a38b80b7af
--在配置属性 -> C/C++ -> 常规 -> 附加包含目录添加leveldb根目录 leveldb/include,boost根目录
--在配置属性 -> C/C++ -> 预处理器-> 预处理器定义中添加LEVELDB_PLATFORM_WINDOWS; OS_WIN两个宏,并将_WINDOWS改成_CONSOLE
--从项目中删除
port/port_android.cc
port/port_posix.cc
util/env_posix.cc
doc/db_bench_tree_db.cc
doc/db_bench_sqlite3.cc
db/c_test.c
*_test.cc
*_bench.cc
--修改port/port.h文件
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#ifndef STORAGE_LEVELDB_PORT_PORT_H_
#define STORAGE_LEVELDB_PORT_PORT_H_
#include
// Include the appropriate platform specific file below. If you are
// porting to a new platform, see "port_example.h" for documentation
// of what the new port_.h file must provide.
#if defined(LEVELDB_PLATFORM_POSIX)
# include "port/port_posix.h"
#elif defined(LEVELDB_PLATFORM_CHROMIUM)
# include "port/port_chromium.h"
#elif defined(LEVELDB_PLATFORM_ANDROID)
# include "port/port_android.h"
#elif defined(LEVELDB_PLATFORM_WINDOWS)
#include "port/port_win.h"
#endif
#endif // STORAGE_LEVELDB_PORT_PORT_H_
--添加unistd.h
#pragma once
/** This file is part of the Mingw32 package.
* unistd.h maps (roughly) to io.h
*/
#ifndef _UNISTD_H
#define _UNISTD_H
#include
#include
#endif /* _UNISTD_H */
--将port_win.h中的(如下代码)注掉
#define snprintf _snprintf
--编写一个测试用例
#include "leveldb/db.h"
#include "db/db_impl.h"
#include "db/filename.h"
#include "db/version_set.h"
#include "db/write_batch_internal.h"
#include "leveldb/cache.h"
#include "leveldb/env.h"
#include "leveldb/table.h"
#include "port/port.h"
#include "util/hash.h"
#include "util/logging.h"
#include "util/mutexlock.h"
#include "util/testharness.h"
#include "util/testutil.h"
#include
#include
int main() {
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, "lev", &db);
//std::cout << "connect status : " << status.ok() << std::endl;
db->Put(leveldb::WriteOptions(), "say", "hello leveldb");
std::string val = "";
db->Get(leveldb::ReadOptions(), "say", &val);
std::cout << val << std::endl;
}
具体步骤:
1、下载opencv源码包以及扩展包
2、cmake-gui
3、显示源码包的编译,然后勾选world,再添加扩展模板模块
4、生成工程
5、编译
参考网址:
网址:https://blog.csdn.net/cjh_jinduoxia/article/details/88268134
具体步骤:
1、解压 SZip.tar.gz 和 ZLib.tar.gz
2、命令行中进入解压后的文件夹(.bat所在文件夹)
3、在命令行中执行 build-VS2017-64.bat
4、多了一个build文件夹和一个HDF5-1.10.5-win64.zip文件
5、解压HDF5-1.10.5-win64.zip文件,可得到如下图的文件夹,所有的头文件和依赖库都在里面
使用:
1、E:\software_install\hdf5\1.10.5\CMake-hdf5-1.10.5\HDF5-1.10.5-win64\bin中的dll
2、在附加包含目录中添加E:\software_install\hdf5\1.10.5\CMake-hdf5-1.10.5\HDF5-1.10.5-win64\include
3、在附加库目录中添加E:\software_install\hdf5\1.10.5\CMake-hdf5-1.10.5\HDF5-1.10.5-win64\lib
--.动态链接方式: 在附加依赖项加入szip.lib;zlib.lib;hdf5.lib;hdf5_cpp.lib
在[通用属性]->[C/C++]->[预处理器]中添加H5_BUILT_AS_DYNAMIC_LIB
--.静态链接方式: 在附加依赖项加入libszip.lib;libzlib.lib;libhdf5.lib;libhdf5_cpp.lib
千万不要再在[通用属性]->[C/C++]->[预处理器]中添加H5_BUILT_AS_DYNAMIC_LIB
参考网址:
网址:https://github.com/google/snappy
具体步骤:
编译:
1、cmake -G "Visual Studio 15 Win64" ..
2、管理员打开vs2017 并ALL_BUILD & INSTALL
本人使用的资料下载,解压密码:0611ctu0611ctu
00SDK库的安装及其他依赖
00Caffe工具的资源下载
01caffe-深度学习框架
02protobuf-内存与非易失存储介质交换的协议接口
04GFLAGS-命令行参数解析的作用
05GLOG-记录应用程序日志的实用库
06OpenBLAS-矩阵计算库
07HDF5-保存格式
08Opencv-视觉开发库
09LMDB-闪电般的内存映射型数据库管理器
10Leveldb-数据存储,类似数据库
11Snappy-压缩工具
测试工程