日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
python如何使用caffe

Caffe是一個(gè)深度學(xué)習(xí)框架,它由伯克利的BVLC(Berkeley Vision and Learning Center)實(shí)驗(yàn)室開發(fā),Caffe使用C++編寫,支持多種編程語言,如Python、MATLAB等,在Python中使用Caffe,需要通過Python接口進(jìn)行操作,本文將詳細(xì)介紹如何在Python中使用Caffe。

創(chuàng)新互聯(lián)建站從2013年成立,先為溫州等服務(wù)建站,溫州等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為溫州企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

1、安裝依賴庫

在使用Caffe之前,需要安裝一些依賴庫,在Ubuntu系統(tǒng)中,可以通過以下命令安裝:

sudo aptget install libprotobufdev libleveldbdev libsnappydev libopencvdev libhdf5serialdev protobufcompiler
sudo aptget install noinstallrecommends libboostalldev
sudo aptget install libopenblasdev liblapackdev libatlasbasedev gfortran

對(duì)于Windows系統(tǒng),可以從Caffe的GitHub倉庫(https://github.com/BVLC/caffe/releases)下載預(yù)編譯的二進(jìn)制文件。

2、克隆Caffe倉庫

從Caffe的GitHub倉庫克隆源代碼:

git clone https://github.com/BVLC/caffe.git
cd caffe

3、編譯Caffe

在Ubuntu系統(tǒng)中,可以使用以下命令編譯Caffe:

cp Makefile.config.example Makefile.config
make all
make test
make runtest

對(duì)于Windows系統(tǒng),可以運(yùn)行build_win.bat腳本來編譯Caffe。

4、安裝Python接口

安裝Python開發(fā)環(huán)境:

sudo aptget install pythondev pythonpip numpy scipy cython pillow h5py matplotlib

從GitHub倉庫克隆Python接口源代碼:

git clone https://github.com/BVLC/caffe/tree/master/python
cd python

接下來,使用pip安裝依賴庫:

pip install r requirements.txt

5、編寫Python代碼

創(chuàng)建一個(gè)名為example.py的文件,編寫以下代碼:

import caffe as cf
import numpy as np
from PIL import Image
import os, sys, time, copy, shutil, random, math, bisect, heapq, string, collections, itertools, queue, threading, re, datetime, functools, urllib, binascii, getopt, grep, hashlib, subprocess, multiprocessing, json, base64, zipfile, glob, tarfile, gzip, bz2, lzma, bottleneck, socket, select, errno, fcntl, termios, struct, timeit, pdb, signal, traceback, argparse, readline, atexit, codecs, stat, io, ossaudiodev, contextlib, tempfile, warnings, weakref, operator as op, keyword as kwd
from scipy import misc
from scipy import ndimage as ndi    # for smooth filters only the first dimension is supported in C++ currently (e.g. convolution) so we use this to apply the same operation on the second dimension of the input image if necessary (e.g. when using "spatial" data format). For more info see: http://www.scipy.org/Cookbook/SignalSmoothing#head7d980a1b6f30479cb1d980a1b6f30479cb1d980a1b6f30479cb1d980a1b6f30479c or http://stackoverflow.com/questions/18752322/howtoapplyafilterwithscipyndimageconvolveintwodimensionsienotjustt#answer23765355 for alternative methods to apply filters in two dimensions with C++ filters. This workaround is not needed anymore since Caffe now supports multiple dimensions in its filters (commit: https://github.com/BVLC/caffe/commit/f285f4e7e87d3ec2b4e9b9e5a682d564d786a5a0). The code above can be removed once you have updated your Caffe installation to include the commit mentioned above. # noqa: F401 # pylint: disable=W0611 # pylint: disable=W0223 # pylint: disable=W0201 # pylint: disable=W0613 # pylint: disable=R0201 # pylint: disable=R0205 # pylint: disable=R0801 # pylint: disable=R0803 # pylint: disable=R0914 # pylint: disable=R0915 # pylint: disable=R0916 # pylint: disable=R0917 # pylint: disable=R0912 # pylint: disable=R0913 # pylint: disable=R0711 # pylint: disable=R0232 # pylint: disable=R0823 # pylint: disable=R0805 # pylint: disable=R0710 # pylint: disable=R0612 # pylint: disable=R0911 # noqa: F401 # pylint: disable=W0611 # pylint: disable=W0223 # pylint: disable=W0201 # pylint: disable=W0613 # pylint: disable=R0201 # pylint: disable=R0205 # pylint: disable=R0801 # pylint: disable=R0803 # pylint: disable=R0914 # pylint: disable=R0915 # pylint: disable=R0916 # pylint: disable=R0917 # pylint: disable=R0912 # pylint: disable=R0913 # pylint: disable=R0711 # pylint: disable=R0232 # pylint: disable=R0823 # pylint: disable=R0805 # pylint: disable=R0710 # pylint: disable=R0612 # noqa: F401 # pylint: enable=F0401 # noqa: F401 # pylint: enable=F0401 from __future__ import print_function from __future__ import division from __future__ import absolute_import from future import standard_library from future import division from future import print_function from future import absolute_import from future import standard_library from builtins import range from past.utils import old_div from past.utils import old_round from past.utils import iteritems from past.utils import lru_cache from past.utils import basestring from past.utils import filterfalse from past.utils import cmp_to_key from past.utils import unicode as str  Import any other modules you need here...  ...then define your class and main function below this line...  If you want to use Caffe's Python API in another module (e.g. in a script), then don't forget to add the following lines at the beginning of that file (replace "mymodule" with the name of your module): try: sys.path.remove('/path/to/caffe') except ValueError: pass sys.path.insert(0, '/path/to/caffe') import caffe as cf def main(): pass if __name__ == '__main__': main()  End of file; do not edit directly! *coding: utf8 *```
在代碼中,我們首先導(dǎo)入了所需的庫,然后定義了一個(gè)名為main的函數(shù),在if __name__ == '__main__':語句下,調(diào)用main函數(shù),在main函數(shù)中,我們可以編寫使用Caffe的代碼,加載預(yù)訓(xùn)練模型、處理圖像數(shù)據(jù)等。
6、運(yùn)行Python代碼
在終端中,運(yùn)行以下命令:

python example.py [args] [optional arguments] [positional arguments] [command options] [other options] …

[args] [optional arguments] [positional arguments] [command options] [other options] ...表示傳遞給Python腳本的參數(shù),具體參數(shù)可以參考Caffe的官方文檔。

分享名稱:python如何使用caffe
轉(zhuǎn)載來源:http://www.5511xx.com/article/dhgheji.html