【caffe2从头学】:3.caffe2的官方教程的安装与使用

本片文章是我的【caffe2从头学】系列中的一篇,如果想看其他文章,请看目录:


0.目录
1.快速开始

1.1.什么是caffe2 ?
1.2.安装caffe2

2.学习caffe2
3.caffe2官方教程的安装与使用

3.1.Blobs and Workspace, Tensors,Net 概念
3.2.Caffe2 的一些基本概念 - Workspaces&Operators & Nets & Nets 可视化
3.3.Brewing Models(快速构建模型)
3.4.Toy_Regression
3.5.Models and Datasets
3.6.Loading_Pretrained_Models
3.7.Image_Pre-Processing_Pipeline
3.8.MNIST
3.9.create_your_own_dataset

4.参考
5.API

相关代码在我的github仓库:https://github.com/JackKuo666/csdn/tree/master/caffe2


1.Caffe2 Tutorials Overview

1.1.Tutorials Installation

1.1.1下载Tutorials源代码

git clone --recursive https://github.com/caffe2/tutorials caffe2_tutorials

1.1.2.安装Tutorials依赖

官方给出的安装方式如下:

pip install -U pip setuptools
pip install \
    graphviz \
    hypothesis \
    ipython \
    jupyter \
    matplotlib \
    notebook \
    pydot \
    python-nvd3 \
    pyyaml \
    requests \
    scikit-image \
    scipy

同时官方也介绍了,可以把pip替换成conda,但是,我按照官方的方式如下:

conda install \
    graphviz \
    hypothesis \
    ipython \
    jupyter \
    matplotlib \
    notebook \
    pydot \
    python-nvd3 \
    pyyaml \
    requests \
    scikit-image \
    scipy

结果,全部安装显示,python-nvd3没有,所以,我们这样安装:

conda install graphviz
conda install hypothesis
conda install ipython 
conda install jupyter 
conda install matplotlib 
conda install notebook 
conda install pydot
conda install pyyaml
conda install requests
conda install scikit-image 
conda install scipy
conda install conda-forge python-nvd3 

安装完成之后,官方还说要安装:

For Ubuntu run : apt-get install unzip zeromq

但是我安装提示不存在,所以,这个也用conda安装:

conda install zeromq

1.1.3.安装完成之后,就是测试了:

我们在caffe2环境中

jupyter notebook

然后找到刚才下载的tutorials地址,打开Basics.ipynb,然后运行一下,没有报错表示成功!

1.2.开始学习Tutorials

如果我们安装完成之后接着往下看,会看到作者的建议你的三条路:

1.Use a pre-trained neural network off the shelf! (Easy)
2.Make my own neural network! (Intermediate)
3.Mobile first! I want to make an app that uses deep learning! (Advanced)

但是看这些建议之前,如果你没有caffe2基础,那么还是乖乖顺序依照下面的建议走吧:

1.Beginner Tutorials
2.New to Caffe2
3.Intermediate Tutorials
4.Advanced Tutorials

看了一遍我觉得caffe2的教程顺序不太容易学,所以,我重新排了一下顺序:

1.New to Caffe2
2.Beginner Tutorials
3.Intermediate Tutorials
4.Advanced Tutorials

2.1.New to Caffe2

2.1.1.Caffe to Caffe2 Translation

https://caffe2.ai/docs/caffe-migration.html
这个之前我们已经介绍过了。

2.1.2.Intro Tutorial

这个部分将会为你介绍 Caffe2的:blobs, workspace, and tensors. 它介绍了 nets 和 operators 以及如何创建一个 model 并编译它。【这部分的官网地址是:https://caffe2.ai/docs/intro-tutorial】

1.caffe2 中的一些定义与概念

blobs:
  caffe2中的数据以blob形式组织。blob是内存中的指定数据块。大多数blob包含一个张量,在Python中它们被转换为numpy数组。

Workspace存储所有的blob。下面的示例展示了如何将blob填充到Workspace并再次获取它们。当您开始使用Workspace时,它们就初始化了。

from caffe2.python import workspace, model_helper
import numpy as np
# Create random tensor of three dimensions
x = np.random.rand(4, 3, 2)
print(x)
print(x.shape)

workspace.FeedBlob("my_x", x) #存

x2 = workspace.FetchBlob("my_x")  #取
print(x2)

Nets and Operators:
blob:数据,也就是tensor,还是多维数组;
Operator:操作,这里可以理解为层;
Net :网络,由很多层组成。
下面,我们的介绍讲转入.ipynb文件,请看下篇博客:
【caffe2从头学】:4.caffe2的官方教程:(1). Blobs and Workspace, Tensors,Net 概念


以下是我另外记的笔记,不构成本部分主要内容:

Model Download Options
下载训练好的模型方法有3种:

1.使用shell下载:

python -m caffe2.python.models.download squeezenet      #下载到当前文件夹
python -m caffe2.python.models.download -i squeezenet   #下载到你的caffe2所在的model文件夹下,如下所示:
#anaconda2/envs/caffe2/lib/python2.7/site-packages/caffe2/python/models/squeezenet/predict_net.pb
 

2.Alternatively, you can clone the entire repo of models at git clone https://github.com/caffe2/models but you will need to install Git Larg File Storage to download the models themselves.

3.从别人的个人github中下载。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值