深度学习之Caffe完全掌握:添加新的网络层(训练非图像纯数据)
来源:互联网 发布:淘宝双十一成交额实时 编辑:程序博客网 时间:2024/05/16 02:55
深度学习之Caffe完全掌握:添加新的网络层
什么是caffe
Caffe,全称Convolutional Architecture for Fast Feature Embedding。是一种常用的深度学习框架,在视频、图像处理方面应用较多。作者是贾扬清,加州大学伯克利的ph.D。Caffe用C++编写,但可以用python调用。
关于caffe的使用
你完全可以把python看作它的UI,并不涉及算法具体实现。
你完全可以把prototxt文件看作它的配置,只是模型和任务流程的一种文本描述。
你完全可以把.caffemodel文件视为出产物,模型实体。
(很勉强的排比修辞手法)(1分)
下载示例程序
root@master:# git clone https://github.com/cbelth/irisCaffe.gitroot@master:# cd irisCaffe/irisroot@master:# python iris_tuto.py... ...
关于配置环境
注意必须配置好关于pycaffe接口的地址,
我在iris_tuto.py中添加了:
import syssys.path.append("/download/caffe/python/")import caffe
就可以使用其接口了
我们先看看现在的网络结构
其结构文件如下:
name: "IrisNet"layer { name: "iris" type: "HDF5Data" top: "data" top: "label" include { phase: TRAIN } hdf5_data_param { source: "iris_train_data.txt" batch_size: 1 }}layer { name: "iris" type: "HDF5Data" top: "data" top: "label" include { phase: TEST } hdf5_data_param { source: "iris_test_data.txt" batch_size: 1 }}layer { name: "ip1" type: "InnerProduct" bottom: "data" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 50 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "relu1" type: "ReLU" bottom: "ip1" top: "ip1"}layer { name: "drop1" type: "Dropout" bottom: "ip1" top: "ip1" dropout_param { dropout_ratio: 0.5 }}layer { name: "ip2" type: "InnerProduct" bottom: "ip1" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 50 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "drop2" type: "Dropout" bottom: "ip2" top: "ip2" dropout_param { dropout_ratio: 0.4 }}layer { name: "ip3" type: "InnerProduct" bottom: "ip2" top: "ip3" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 3 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "drop3" type: "Dropout" bottom: "ip3" top: "ip3" dropout_param { dropout_ratio: 0.3 }}layer { name: "loss" type: "SigmoidCrossEntropyLoss" # type: "EuclideanLoss" # type: "HingeLoss" bottom: "ip3" bottom: "label" top: "loss"}
现在我想在ip1层后添加一层新的名为”newLayer”的新层,其结构和ip1一样,那么,就改写为:
name: "IrisNet"layer { name: "iris" type: "HDF5Data" top: "data" top: "label" include { phase: TRAIN } hdf5_data_param { source: "iris_train_data.txt" batch_size: 1 }}layer { name: "iris" type: "HDF5Data" top: "data" top: "label" include { phase: TEST } hdf5_data_param { source: "iris_test_data.txt" batch_size: 1 }}layer { name: "ip1" type: "InnerProduct" bottom: "data" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 50 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "relu1" type: "ReLU" bottom: "ip1" top: "ip1"}layer { name: "drop1" type: "Dropout" bottom: "ip1" top: "ip1" dropout_param { dropout_ratio: 0.5 }}layer { name: "newLayer" type: "InnerProduct" bottom: "ip1" top: "newLayer" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 50 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "relu_newLayer" type: "ReLU" bottom: "newLayer" top: "newLayer"}layer { name: "drop_newLayer" type: "Dropout" bottom: "newLayer" top: "newLayer" dropout_param { dropout_ratio: 0.5 }}layer { name: "ip2" type: "InnerProduct" bottom: "newLayer" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 50 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "drop2" type: "Dropout" bottom: "ip2" top: "ip2" dropout_param { dropout_ratio: 0.4 }}layer { name: "ip3" type: "InnerProduct" bottom: "ip2" top: "ip3" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 3 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "drop3" type: "Dropout" bottom: "ip3" top: "ip3" dropout_param { dropout_ratio: 0.3 }}layer { name: "loss" type: "SigmoidCrossEntropyLoss" # type: "EuclideanLoss" # type: "HingeLoss" bottom: "ip3" bottom: "label" top: "loss"}
网络模型结构:
然后运行:
root@master:/App/Caffe_Iris/iris# python iris_tuto.py I1217 21:32:06.172330 6814 layer_factory.hpp:77] Creating layer irisI1217 21:32:06.172345 6814 net.cpp:84] Creating Layer irisI1217 21:32:06.172353 6814 net.cpp:380] iris -> dataI1217 21:32:06.172364 6814 net.cpp:380] iris -> labelI1217 21:32:06.172392 6814 hdf5_data_layer.cpp:80] Loading list of HDF5 filenames from: iris_test_data.txtI1217 21:32:06.172417 6814 hdf5_data_layer.cpp:94] Number of HDF5 files: 1I1217 21:32:06.173000 6814 net.cpp:122] Setting up irisI1217 21:32:06.173017 6814 net.cpp:129] Top shape: 1 1 1 4 (4)I1217 21:32:06.173024 6814 net.cpp:129] Top shape: 1 3 (3)I1217 21:32:06.173028 6814 net.cpp:137] Memory required for data: 28I1217 21:32:06.173033 6814 layer_factory.hpp:77] Creating layer ip1I1217 21:32:06.173075 6814 net.cpp:84] Creating Layer ip1... ...
阅读全文
0 0
- 深度学习之Caffe完全掌握:添加新的网络层(训练非图像纯数据)
- 深度学习之Caffe完全掌握:用C++开发(自定义)网络层
- 深度学习caffe代码怎么读 & 添加新网络层
- Caffe学习——使用自己的数据(非图像)训练网络
- 深度学习-CAFFE利用CIFAR10网络模型训练自己的图像数据获得模型-1.制作自己的数据集
- 深度学习-CAFFE利用CIFAR10网络模型训练自己的图像数据获得模型-3结合caffe中的CIFAR10修改相关配置文件并训练
- 深度学习-CAFFE利用CIFAR10网络模型训练自己的图像数据获得模型-4应用生成模型进行预测
- caffe 添加新的网络层
- caffe中添加新的网络层
- 【深度学习】在caffe中添加新层(layers)
- 深度学习-CAFFE利用CIFAR10网络模型训练自己的图像数据获得模型-2生成图像库的均值文件
- 深度学习文章5:使用caffe对自己的图像数据进行训练并测试
- 深度学习_caffe (4) 基于mnist实例搭建新的神经网络&在caffe中添加层
- 深度学习之caffe的BN层
- caffe中添加新的网络层的步骤
- caffe添加新的层
- caffe 添加新的网络层 (步骤)
- 深度学习的核心:掌握训练数据的方法
- Ubuntu 下 配置 JKD 和 Tomcat
- 《C Primer Plus》
- leetcode Unique Binary Search Trees
- 阿里云入门级Windows 服务器mysql启动失败问题
- Bootstrap4(七)
- 深度学习之Caffe完全掌握:添加新的网络层(训练非图像纯数据)
- Linux下jdk,tomcat ,mysql 的安装
- JQuery call函数,用于查看JQuery的源码
- CentOS 7 安装OpenCV过程记录
- 广播接收者
- iOS路由跳转(五)之JKRouter 2.0 脱胎换骨
- 求二进制中一的个数
- Bootstrap4(八)
- 内存屏障