opencv使用的版本是默认安装的4.2版本
python使用的是anaconda的3.8版本,刚开始使用3.7,遇到一些问题
conda create -n torch2caffe python=3.8
千万不要命名环境为caffe
还遇到
Fatal Python error: init_sys_streams: can't initialize sys standard streams
Python runtime state: core initialized
Traceback (most recent call last):
File "/caffe-ssd/python/caffe/io.py", line 1, in <module>
ModuleNotFoundError: No module named 'numpy
numpy error
numpy error_menglanzeng的博客-CSDN博客
ModuleNotFoundError: No module named 'numpy.testing.nosetester'
numpy 1.19.5
import sys
sys.path.append("/home/20220526_pytorch2caffe/caffe-ssd/python/")
sys.path.append("/home/20220526_pytorch2caffe/caffe-ssd/python/caffe")
boost使用的默认安装的1.7版本
boost默认安装的版本是对于python3.8的
但是弄完后,我还是遇到这个问题
我查了一下,应该是Makefile文件的问题
参考如下:
How to install caffe for python3 in ubuntu
python - How to install caffe for python3 in ubuntu - Stack Overflow
Solve the problem: "cannot find -lboost_python3" when using Python3 Ubuntu16.04
https://github.com/BVLC/caffe/issues/4843
PyCaffe build fails, lboost_python not found
python - PyCaffe build fails, lboost_python not found - Stack Overflow
Ubuntu18.04上 Caffe 环境安装
Ubuntu18.04上 Caffe 环境安装-云社区-华为云
#PYTHON_LIBRARIES ?= boost_python python2.7
PYTHON_LIBRARIES ?=boost_python38 python3.8
WARNINGS := -Wall -Wno-sign-compare
这里需要注意,有的版本是python3.7m
你如果安装不同的版本,可能要做不同的修改
apt opencv默认版本如下
apt boost-python默认版本如下
如果不是python3.8,又使用默认boost
会遇到错误
AR -o .build_release/lib/libcaffe.a
LD -o .build_release/lib/libcaffe.so.1.0.0-rc3
/usr/bin/ld: 找不到 -lboost_python
准备好这些后,参考这几个博客:
【手把手AI项目】二、深度学习框架caffe以及CUDA、Cudnn等超细致安装教程 (超超细致)
【手把手AI项目】二、深度学习框架caffe以及CUDA、Cudnn等超细致安装教程 (超超细致) - 知乎
基于python3在ubuntu20.04上安装caffe和opencv4.40
技术改变生活其他深度学习本文主要是讲解基于python3在ubuntu上安装caffe和opencv4.4对于原版caffe目前支持的是python2,很多基于python2的软件包在python3时就不在更新,但是安装caffe时就需要这 ...基于python3在ubuntu20.04上安装caffe和opencv4.4
cuDNN
cudnn版本8已经丢弃了caffe所依赖的一些接口,编译的过程中会出现"CUDNN_CONVOLUTION_FWD_SPECIFY_WORKSPACE_LIMIT was not declared in this scope". 其中两个接口cudnnGetConvolutionForwardAlgorithm, cudnnGetConvolutionBackwardDataAlgorithm被其他的接口替代,并且cudnnGetConvolutionBackwardFilterAlgorithm接口没有找到合适的替代。
这里安装cudnn你有三个选择:
1.将版本降到7.6,这个是不建议的,会导致其他依赖出现问题
2.使用没有cudnn进行编译caffe,保留cuda进行编译caffe,这样也是可以使用的
3.使用上面修改过的caffe,这里我们将cudnnGetConvolutionBackwardFilterAlgorithm算法设置为一个常量, CUDNN_CONVOLUTION_BWD_FILTER_ALGO_0 这个可能不是最优的选择,但是是可以使用的,当然这个修改只适用于cudnn8,对于其他的版本是不适用的。
有一个百度网盘地址,里面有改好的opencv4的caffe版本
链接:https://pan.baidu.com/s/1bJgbIWfCdB9ZOGyuXItuWA
提取码:mcel
fatal error: opencv2/core.hpp: No such file or directory Ubuntu and Visual Studio Code
Ubuntu 20.04搭建OpenCV 4.5.0 & C++环境
Ubuntu 20.04搭建OpenCV 4.5.0 & C++环境_tiffiny10的博客-CSDN博客
Caffe - 与 opencv4 相关问题解决
Caffe - 与 opencv4 相关问题解决 - AI备忘录
caffe编译安装,关于opencv4的问题
caffe编译安装,关于opencv4的问题_一洛玉壶冰的博客-CSDN博客
boost编译出错,找不到pyconfig.h
安装cuda11成功后,编译算例报错:nvcc fatal : Unsupported gpu architecture ‘compute_80‘
安装cuda11成功后,编译算例报错:nvcc fatal : Unsupported gpu architecture ‘compute_80‘_ruixia.chen的博客-CSDN博客
我的最终Makefile.config
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!
# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1
# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1
# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1
# Uncomment if you're using OpenCV 3 or 4
OPENCV_VERSION := 4
USE_PKG_CONFIG := 1
# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++
# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr
# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the lines after *_35 for compatibility.
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_70,code=sm_70
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
# BLAS := atlas
BLAS := open
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas
# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib
# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
# PYTHON_INCLUDE := /usr/include/python2.7 \
# /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
#yangninghua
ANACONDA_HOME := /home/ninghua/environment/mmlab_point3d_open3d/envs/torch2caffe
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python3.8 \
$(ANACONDA_HOME)/lib/python3.8/site-packages/numpy/core/include \
# Uncomment to use Python 3 (default is Python 2)
#yangninghua
#PYTHON_LIBRARIES := boost_python38 python3.8
#PYTHON_INCLUDE := /usr/include/python3.8 \
# /usr/lib/python3/dist-packages/numpy/core/include
# We need to be able to find libpythonX.X.so or .dylib.
#yangninghua
#PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib
# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib
# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1
# Whatever else you find you need goes here.
#INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/local/include/opencv4 /usr/include/hdf5/serial
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/opencv4 /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial
# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib
# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1
# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0
# enable pretty build (comment to see full commands)
Q ?= @
vim ~/.bashrc
source ~/.bashrc
export PYTHONPATH=/home/***/caffe-ssd/python/caffe:$PYTHONPATH