caffe 从mnsit示例到自己创建数据集再到识别手写图片
来源:互联网 发布:倍娱网络电视 编辑:程序博客网 时间:2024/05/16 01:07
记录下使用caffe mnist数据集,训练+识别图片过程中遇到的问题。
很不详细。
- 按部就班,获取mnist数据集、创建lmdb、使用example文件训练,得到caffemodel,找了图片预测,错误率很高
原因: mnist原始图片是黑底白字,找的图片是白底黑字。。。自己来重做lmdb吧。—注意灰度图的格式
2.网络上找来mnist手写图片,白底黑字,使用脚本生成lmdb
cp create_imagenet.sh create_imagenet_my_mnist.shcat create_imagenet_my_mnist.sh#!/usr/bin/env sh# Create the imagenet lmdb inputs# N.B. set the path to the imagenet train + val data dirsEXAMPLE=examples/mnistDATA=data/mnist/mnistTOOLS=build/toolsTRAIN_DATA_ROOT=/root/caffe-0.16.3/data/mnist/mnist/train/VAL_DATA_ROOT=/root/caffe-0.16.3/data/mnist/mnist/test/# Set RESIZE=true to resize the images to 256x256. Leave as false if images have# already been resized using another tool.RESIZE=trueif $RESIZE; then RESIZE_HEIGHT=28 RESIZE_WIDTH=28else RESIZE_HEIGHT=0 RESIZE_WIDTH=0fiif [ ! -d "$TRAIN_DATA_ROOT" ]; then echo "Error: TRAIN_DATA_ROOT is not a path to a directory: $TRAIN_DATA_ROOT" echo "Set the TRAIN_DATA_ROOT variable in create_imagenet.sh to the path" \ "where the ImageNet training data is stored." exit 1fiif [ ! -d "$VAL_DATA_ROOT" ]; then echo "Error: VAL_DATA_ROOT is not a path to a directory: $VAL_DATA_ROOT" echo "Set the VAL_DATA_ROOT variable in create_imagenet.sh to the path" \ "where the ImageNet validation data is stored." exit 1fiecho "Creating train lmdb..."GLOG_logtostderr=1 $TOOLS/convert_imageset \ --resize_height=$RESIZE_HEIGHT \ --resize_width=$RESIZE_WIDTH \ --shuffle \ --gray \ $TRAIN_DATA_ROOT \ $DATA/train.txt \ ##注意如果图片就在$DATA下面,train.txt和val.txt里的路径$DATA下的路径就可以 $EXAMPLE/my_mnist_train_lmdbecho "Creating val lmdb..."GLOG_logtostderr=1 $TOOLS/convert_imageset \ --resize_height=$RESIZE_HEIGHT \ --resize_width=$RESIZE_WIDTH \ --shuffle \ --gray \ ###默认是RGB,需要加个强制灰度,否则预测依然不准 $VAL_DATA_ROOT \ $DATA/val.txt \ $EXAMPLE/my_mnist_val_lmdbecho "Done."###开始识别name: "LeNet"layer { name: "data" type: "Input" top: "data" input_param { shape: { dim: 1 dim: 1 dim: 28 dim: 28 } }}layer { name: "conv1" type: "Convolution" bottom: "data" top: "conv1" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 20 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "pool1" type: "Pooling" bottom: "conv1" top: "pool1" pooling_param { pool: MAX kernel_size: 2 stride: 2 }}layer { name: "conv2" type: "Convolution" bottom: "pool1" top: "conv2" param { lr_mult: 1 } param { lr_mult: 2 } convolution_param { num_output: 50 kernel_size: 5 stride: 1 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "pool2" type: "Pooling" bottom: "conv2" top: "pool2" pooling_param { pool: MAX kernel_size: 2 stride: 2 }}layer { name: "ip1" type: "InnerProduct" bottom: "pool2" top: "ip1" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 500 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "relu1" type: "ReLU" bottom: "ip1" top: "ip1"}layer { name: "ip2" type: "InnerProduct" bottom: "ip1" top: "ip2" param { lr_mult: 1 } param { lr_mult: 2 } inner_product_param { num_output: 10 weight_filler { type: "xavier" } bias_filler { type: "constant" } }}layer { name: "prob" type: "Softmax" bottom: "ip2" top: "prob"}[root@7ed2726e0c5a caffe-0.16.3]# ./build/examples/cpp_classification/classification.bin examples/mnist/lenet_deploy.prototxt examples/mnist/lenet_iter_10000.caffemodel examples/mnist/mean.binaryproto data/mnist/mnist/test/labels.txt /root/8.png---------- Prediction for /root/8.png ----------1.0000 - "8"0.0000 - "5"0.0000 - "3"0.0000 - "1"0.0000 - "4"##导出镜像,有空再继续
遇到的几个小坑:
1. 可能是第一次弄不太熟悉,需要保证训练集-模型-测试集,图片格式的一致
2. 注意均值文件,训练用了,预测的时候不能忘用
3. 创建lmdb时 灰度图不是默认选项,需要加参数
阅读全文
0 0
- caffe 从mnsit示例到自己创建数据集再到识别手写图片
- tensorflow 构建CNN识别自己的数据(类似于MNSIT)
- mnsit 手写数据集 python3.x的读入 以及利用softmax回归进行数字识别
- caffe中如何训练自己的手写数字识别系统?
- caffe识别手写数字
- caffe训练识别自己的图片
- 使用TensorFlow创建自己的手写识别引擎
- Caffe学习-手写数字识别
- Caffe学习-手写数字识别
- Caffe学习-手写数字识别
- Caffe学习-手写数字识别
- Caffe windows下入门级别的从编译到训练然后到分类(用python接口)测试自己的图片数据(四)
- caffe实战三:自己手写数字图片通过mnist的caffe模型进行分类
- caffe windows 训练自己的图片数据
- caffe 如何训练自己的数据图片
- Caffe训练、测试自己的图片数据
- Android车牌识别,从图片识别到扫描识别
- caffe使用lenet5识别手写数字
- Java中关于nextInt()、next()和nextLine()的理解(转)
- gsoap,openssl,onvif makefile编译,undefined reference to `soap_ssl_init',errno错误号500,401等
- 自定义控件—canvas、paint
- Http请求码
- 不存在硬盘内存
- caffe 从mnsit示例到自己创建数据集再到识别手写图片
- 响应式网站的一些方法
- 基于 zui.sexy的模态选择器
- Word2010如何设置图片的阴影效果教程
- Android View框架总结(一)
- 52数学能力测评第二阶段第一次模拟测评即将开始(上海赛区)
- 设置Mac的root密码
- 将form表单的数据统一转成json串
- linux文件