Skip to content

Latest commit

 

History

History
215 lines (180 loc) · 7.44 KB

ai_algorithms.md

File metadata and controls

215 lines (180 loc) · 7.44 KB

AI Algorithms


YOLO V3

git clone http://github.com/pjreddie/darknet.git
cd darknet

修改Makefile编译配置文件:

  GPU=1
  CUDNN=1
  OPENCV=1

注意: 这里要安装OpenCV-3.4.0版本,否则在编译darknet的时候提示以下错误:

./src/detector.c:30:5: error: redefinition of ‘cvRound’
int cvRound(double value) {return(ceil(value));}

安装好OpenCV-3.4.0,然后运行一下命令:

make -j8

也可以根据YOLO官方安装指导安装即可,其中若编译的时候用到opencv库的时候,遇到以下报错: 编译报错 原因是opencv没有加入到环境变量中,解决方式 用gedit打开/etc/ld.so.conf,注意要用sudo打开获得权限,不然无法修改, 如:

sudo gedit /etc/ld.so.conf

在文件中加上一行:

/usr/local/lib

/user/local是opencv安装路径 就是makefile中指定的安装路径.

再运行sudo ldconfig, 修改bash.bashrc文件:

sudo gedit /etc/bash.bashrc

在文件末尾加入:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 
export PKG_CONFIG_PATH 

运行source /etc/bash.bashrc使其生效。


Faster R-CNN

  1. Clone the Faster R-CNN repository
# Make sure to clone with --recursive
git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git

or find it in src/algorithm/py-faster-rcnn.zip and unzip it.

  1. Build the Cython modules
cd $FRCN_ROOT/lib
make
  1. Build Caffe and pycaffe 若使用的CUDA 9.0以上,需要将 /caffe-fast-rcnn/include/caffe/util/cudnn*/caffe-fast-rcnn/include/caffe/layers/cudnn*/caffe-fast-rcnn/src/caffe/util/cudnn* 以及 /caffe-fast-rcnn/src/caffe/layers/cudnn*caffe下的同名替换。
cd $FRCN_ROOT/caffe-fast-rcnn
# Now follow the Caffe installation instructions here:
#   http://caffe.berkeleyvision.org/installation.html

# or copy the following:
## 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 if you're using OpenCV 3
OPENCV_VERSION := 3
# 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 *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines 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_61,code=compute_61

# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# 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

# 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.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
		# $(ANACONDA_HOME)/include/python2.7 \
		# $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \

# We need to be able to find libpythonX.X.so or .dylib.
PYTHON_LIB := /usr/lib
# PYTHON_LIB := $(ANACONDA_HOME)/lib

# Uncomment to support layers written in Python (will link against Python libs)
# This will require an additional dependency boost_regex provided by boost.
WITH_PYTHON_LAYER := 1

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /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

# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1

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 ?= @

然后,编译安装:

make -j8 && make pycaffe
  1. Download pre-computed Faster R-CNN detectors
cd $FRCN_ROOT
./data/scripts/fetch_faster_rcnn_models.sh

Anaconda FAQ

Anaconda环境下TensorFlow和Pytorch共存问题

conda环境中同时安装TensorFlowPytorch后,在导入这两个库的时候提示以下错误:
tensorflowandpytorch1
tensorflowandpytorch2

原因是安装PytorchTensorFlow的时候安装了两遍numpy,且和numpy-base版本不同:
tensorflowandpytorch3
解决方法:

pip uninstall numpy
pip uninstall numpy # 确保所有numpy都卸载了
conda install --force-reinstall numpy # 用conda强制重新安装numpy

tensorflowandpytorch4
安装好了以后查看numpy版本:

conda list numpy

tensorflowandpytorch5

Anaconda环境下Python下导入正常Jupyter Notebook中导入莫名出错

问题描述
Anaconda环境下Python下导入正常JupyterNotebook中导入莫名出错

解决方案
出现该问题的原因是Anaconda虚拟环境中没有安装Jupyter Notebook而在虚拟环境中运行的Jupyter Notebook是调用的外部环境的Jupyter Notebook,解决方法是在虚拟环境中安装Jupyter Notebook:

source activate virtualenv
conda install jupyter notebook