怎么查找手机位置置

Windows平台基于Caffe框架的LeNet网络训练 - 博客频道 - CSDN.NET
Rolin的专栏
路在自己脚下
分类:Machine LearningC/C++
在Windows平台下使用Caffe的确不如Linux来的方便,至少人家把Shell都已经写好了。但是像我这种VS重度依赖者,还是离不开微软大腿呀…废话不多说,一步步来吧
0.&为了后续文件路径访问的便利,我们先将$CAFFE_ROOT根目录添加到操作系统环境变量PATH中,并重启使之生效。
1.&首先需要从Yann LeCun的网站 & 上下载手写数字图像库,共为四个压缩包约11MB大小,分别是train-images-idx3-ubyte.gz(训练集图像),train-labels-idx1-ubyte.gz(训练集标签),t10k-images-idx3-ubyte.gz(测试集图像)和t10k-labels-idx1-ubyte.gz(测试集标签)。并将其解压缩至Caffe目录下的$CAFFE_ROOT\data\mnist文件夹中。
2.&然后我们需要将解压缩后的四个文件转为Caffe所支持的lmdb文件,转换需要使用到编译好的convert_mnist_data.exe可执行文件。由于Windows不能执行Caffe提供的Shell文件,在此将其修改为bat批处理文件内容如下:
rd /s /q mnist_test_lmdb
rd /s /q mnist_train_lmdb
convert_mnist_data.exe data\mnist\train-images.idx3-ubyte data\mnist\train-labels.idx1-ubyte examples\mnist\mnist_train_lmdb
convert_mnist_data.exe data\mnist\t10k-images.idx3-ubyte data\mnist\t10k-labels.idx1-ubyte examples\mnist\mnist_test_lmdb
将bat文件放在$CAFFE_ROOT\examples\mnist目录下双击运行,转换成功如下图所示:
3.&这时准备工作就已经就绪,我们可以开始对数据集进行训练了。
caffe train --solver=examples/mnist/lenet_solver.prototxt
或者我们可以在Visual Studio中更改工程属性,配置调试命令参数,
执行批处理文件或直接在Visual Studio中执行调试,Caffe就运行起来了。在NVIDIA Geforce GTX970机器上,LeNet迭代10000次大约只需要1分钟就训练好了(在Ubuntu系统上训练时间更短,只需要30s左右,原因是Linux版cuDNN效率更高),结果如下图所示
排名:第19305名
(30)(19)(3)(16)2937人阅读
深度学习(16)
caffe(38)
本文转自:http://blog.csdn.net/sheng_ai/article/details/
在此十分感谢博主分享!
由于最近要用到siamese网络,大概跑了一下caffe自带的siamese网络的例程,发现例程中对于数据格式的转换仅仅局限于mnist数据集,不能直接将其他图片格式的数据集转换为需要的格式,因此,在分析了数据转化的逻辑之后,发现每一张图片的转换过程可以按照下面的步骤执行:
& & 在参考了caffe自带的convert_imageset.cpp和之后,我编写的格式转换代码如下,这个代码目前只能处理黑白的图像,后期版本会增加对于彩色图像的支持
// This program converts a set of gray images to a leveldb by storing them
// as Datum proto buffers.
convert_imageset [FLAGS] ROOTFOLDER/ LISTFILE DB_NAME
// where ROOTFOLDER is the root folder that holds all the images, and LISTFILE
// should be a list of files as well as their labels, in the format as
subfolder1/file1.JPEG 7
#include &algorithm&
#include &fstream&
// NOLINT(readability/streams)
#include &string&
#include &utility&
#include &vector&
#include &boost/scoped_ptr.hpp&
#include &gflags/gflags.h&
#include &glog/logging.h&
#include &leveldb\db.h&
#include &caffe/proto/caffe.pb.h&
#include &caffe/util/io.hpp&
#include &caffe/util/rng.hpp&
#include &opencv2\opencv.hpp&
// NOLINT(build/namespaces)
using std::
using boost::scoped_
DEFINE_bool(gray, false,
&When this option is on, treat images as grayscale ones&);
DEFINE_bool(shuffle, false,
&Randomly shuffle the order of images and their labels&);
DEFINE_string(backend, &lmdb&,
&The backend {lmdb, leveldb} for storing the result&);
DEFINE_int32(resize_width, 0, &Width images are resized to&);
DEFINE_int32(resize_height, 0, &Height images are resized to&);
DEFINE_bool(check_size, false,
&When this option is on, check that all the datum have the same size&);
DEFINE_bool(encoded, false,
&When this option is on, the encoded image will be save in datum&);
DEFINE_string(encode_type, &&,
&Optional: What type should we encode the image as ('png','jpg',...).&);
static bool ReadImageToMemory(const string& FileName, const int Height,
const int Width, char *Pixels)
// read image
cv::Mat OriginImage = cv::imread(FileName, cv::IMREAD_GRAYSCALE);
CHECK(OriginImage.data) && &Failed to read the image.\n&;
// resize the image
cv::Mat ResizeI
cv::resize(OriginImage, ResizeImage, cv::Size(Width, Height));
CHECK(ResizeImage.rows == Height) && &The heighs of Image is no equal to the input height.\n&;
CHECK(ResizeImage.cols == Width) && &The width of Image is no equal to the input width.\n&;
CHECK(ResizeImage.channels() == 1) && &The channel of Image is no equal to one.\n&;
LOG(INFO) && &The height of image is & && ResizeImage.rows && &\n&;
LOG(INFO) && &The width of image is & && ResizeImage.cols && &\n&;
LOG(INFO) && &The channels of image is & && ResizeImage.channels() && &\n&;
// copy the image data to Pixels
for (int HeightIndex = 0; HeightIndex & H ++HeightIndex)
const uchar* ptr = ResizeImage.ptr&uchar&(HeightIndex);
int img_index = 0;
for (int WidthIndex = 0; WidthIndex & W ++WidthIndex)
for (int ChannelIndex = 0; ChannelIndex & ResizeImage.channels(); ++ChannelIndex)
int datum_index = (ChannelIndex * Height + HeightIndex) * Width + WidthI
*(Pixels + datum_index) = static_cast&char&(ptr[img_index++]);
int main(int argc, char** argv)
//::google::InitGoogleLogging(argv[0]);
#ifndef GFLAGS_GFLAGS_H_
namespace gflags =
gflags::SetUsageMessage(&Convert a set of grey images to the leveldb\n&
&format used as input for Caffe.\n&
&Usage:\n&
convert_imageset [FLAGS] ROOTFOLDER/ LISTFILE DB_NAME\n&);
caffe::GlobalInit(&argc, &argv);
// 输入参数不足时报错
if (argc & 4)
gflags::ShowUsageWithFlagsRestrict(argv[0], &tools/convert_imageset&);
// 读取图像名字和标签
std::ifstream infile(argv[2]);
std::vector&std::pair&std::string, int& &
while (infile && filename && label)
lines.push_back(std::make_pair(filename, label));
// 打乱图片顺序
if (FLAGS_shuffle)
// randomly shuffle data
LOG(INFO) && &Shuffling data&;
shuffle(lines.begin(), lines.end());
LOG(INFO) && &A total of & && lines.size() && & images.&;
// 设置图像的高度和宽度
int resize_height = std::max&int&(0, FLAGS_resize_height);
int resize_width = std::max&int&(0, FLAGS_resize_width);
// 打开数据库
// Open leveldb
leveldb::DB*
leveldb::O
options.create_if_missing =
options.error_if_exists =
leveldb::Status status = leveldb::DB::Open(
options, argv[3], &db);
CHECK(status.ok()) && &Failed to open leveldb & && argv[3]
&& &. Is it already existing?&;
// 保存到leveldb
// Storing to leveldb
std::string root_folder(argv[1]);
char* Pixels = new char[2 * resize_height * resize_width];
const int kMaxKeyLength = 10;
char key[kMaxKeyLength];
datum.set_channels(2);
// one channel for each image in the pair###彩色###
datum.set_height(resize_height);
datum.set_width(resize_width);
for (int LineIndex = 0; LineIndex & lines.size(); LineIndex++)
int PairIndex = caffe::caffe_rng_rand() % lines.size();
char* FirstImagePixel = P
ReadImageToMemory(root_folder + lines[LineIndex].first, resize_height, resize_width, FirstImagePixel);
char *SecondImagePixel = Pixels + resize_width * resize_//灰度图,c=1###彩色###
ReadImageToMemory(root_folder + lines[PairIndex].first, resize_height, resize_width, SecondImagePixel);
// set image pair data
datum.set_data(Pixels, 2 * resize_height * resize_width);###彩色###
// set label
if (lines[LineIndex].second == lines[PairIndex].second)
datum.set_label(1);
datum.set_label(0);
// serialize(连续) datum to string
datum.SerializeToString(&value);
sprintf_s(key, kMaxKeyLength, &%08d&, LineIndex);
db-&Put(leveldb::WriteOptions(), std::string(key), value);
delete[] P
}上面的程序只是针对灰度图,由于我是转载而来,代码还没有读太懂,但是对于彩色图,我觉得应该修改我标记的###彩色###的几个地方,稍后做个测试,正确把彩色的弄好。
原文地址:http://blog.csdn.net/sheng_ai/article/details/
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:514279次
积分:6190
积分:6190
排名:第3850名
原创:92篇
转载:240篇
评论:213条
(7)(5)(3)(3)(17)(26)(4)(2)(8)(38)(13)(7)(18)(11)(5)(61)(56)(48)/denny402/p/5070928.html
要运行caffe,需要先创建一个模型(model),如比较常用的Lenet,Alex等, 而一个模型由多个屋(layer)构成,每一屋又由许多参数组成。所有的参数都定义在caffe.proto这个文件中。要熟练使用caffe,最重要的就是学会配置文件(prototxt)的编写。
层有很多种类型,比如Data,Convolution,Pooling等,层之间的数据流动是以Blobs的方式进行。
今天我们就先介绍一下数据层.
数据层是每个模型的最底层,是模型的入口,不仅提供数据的输入,也提供数据从Blobs转换成别的格式进行保存输出。通常数据的预处理(如减去均值, 放大缩小, 裁剪和镜像等),也在这一层设置参数实现。
数据来源可以来自高效的数据库(如LevelDB和LMDB),也可以直接来自于内存。如果不是很注重效率的话,数据也可来自磁盘的hdf5文件和图片格式文件。
所有的数据层的都具有的公用参数:先看示例
name: "cifar"
type: "Data"
top: "data"
top: "label"
phase: TRAIN
transform_param {
mean_file: "examples/cifar10/mean.binaryproto"
data_param {
source: "examples/cifar10/cifar10_train_lmdb"
batch_size: 100
backend: LMDB
name: 表示该层的名称,可随意取
type: 层类型,如果是Data,表示数据来源于LevelDB或LMDB。根据数据的来源不同,数据层的类型也不同(后面会详细阐述)。一般在练习的时候,我们都是采 用的LevelDB或LMDB数据,因此层类型设置为Data。
top或bottom: 每一层用bottom来输入数据,用top来输出数据。如果只有top没有bottom,则此层只有输出,没有输入。反之亦然。如果有多个 top或多个bottom,表示有多个blobs数据的输入和输出。
data 与 label: 在数据层中,至少有一个命名为data的top。如果有第二个top,一般命名为label。 这种(data,label)配对是分类模型所必需的。
include: 一般训练的时候和测试的时候,模型的层是不一样的。该层(layer)是属于训练阶段的层,还是属于测试阶段的层,需要用include来指定。如果没有include参数,则表示该层既在训练模型中,又在测试模型中。
Transformations: 数据的预处理,可以将数据变换到定义的范围内。如设置scale为0.,实际上就是1/255,&即将输入数据由0-255归一化到0-1之间
其它的数据预处理也在这个地方设置:
transform_param {
mean_file_size: "examples/cifar10/mean.binaryproto"
# 用一个配置文件来进行均值操作
# 1表示开启镜像,0表示关闭,也可用ture和false来表示
# 剪裁一个 227*227的图块,在训练阶段随机剪裁,在测试阶段从中间裁剪
crop_size: 227
后面的data_param部分,就是根据数据的来源不同,来进行不同的设置。
1、数据来自于数据库(如LevelDB和LMDB)
& 层类型(layer type):Data
必须设置的参数:
& source: 包含数据库的目录名称,如examples/mnist/mnist_train_lmdb
& batch_size: 每次处理的数据个数,如64
可选的参数:
& rand_skip: 在开始的时候,路过某个数据的输入。通常对异步的SGD很有用。
& backend: 选择是采用LevelDB还是LMDB, 默认是LevelDB.
name: "mnist"
type: "Data"
top: "data"
top: "label"
phase: TRAIN
transform_param {
data_param {
source: "examples/mnist/mnist_train_lmdb"
batch_size: 64
backend: LMDB
2、数据来自于内存
层类型:MemoryData
必须设置的参数:
&batch_size:每一次处理的数据个数,比如2
&channels:通道数
& height:高度
& &width: 宽度
top: "data"
top: "label"
name: "memory_data"
type: "MemoryData"
memory_data_param{
batch_size: 2
height: 100
width: 100
channels: 1
transform_param {
scale: 0.0078125
mean_file: "mean.proto"
mirror: false
3、数据来自于HDF5
层类型:HDF5Data
必须设置的参数:
source: 读取的文件名称
batch_size: 每一次处理的数据个数
name: "data"
type: "HDF5Data"
top: "data"
top: "label"
hdf5_data_param {
source: "examples/hdf5_classification/data/train.txt"
batch_size: 10
4、数据来自于图片
层类型:ImageData
必须设置的参数:
& source: 一个文本文件的名字,每一行给定一个图片文件的名称和标签(label)
& batch_size: 每一次处理的数据个数,即图片数
可选参数:
& rand_skip:&在开始的时候,路过某个数据的输入。通常对异步的SGD很有用。
& shuffle: 随机打乱顺序,默认值为false
& new_height,new_width: 如果设置,则将图片进行resize
name: "data"
type: "ImageData"
top: "data"
top: "label"
transform_param {
mirror: false
crop_size: 227
mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
image_data_param {
source: "examples/_temp/file_list.txt"
batch_size: 50
new_height: 256
new_width: 256
5、数据来源于Windows
层类型:WindowData
必须设置的参数:
& source: 一个文本文件的名字
& batch_size: 每一次处理的数据个数,即图片数
name: "data"
type: "WindowData"
top: "data"
top: "label"
phase: TRAIN
transform_param {
mirror: true
crop_size: 227
mean_file: "data/ilsvrc12/imagenet_mean.binaryproto"
window_data_param {
source: "examples/finetune_pascal_detection/window_file_2007_trainval.txt"
batch_size: 128
fg_threshold: 0.5
bg_threshold: 0.5
fg_fraction: 0.25
context_pad: 16
crop_mode: "warp"
阅读(...) 评论()你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
在训练网络时,出现网络loss缓慢下降,然后快速上升。例如经过10000次迭代,loss从4.7下降到0.9,训练集上准确率也达到0.8以上,但是在接下来的1000次迭代,loss回升到4.7附近。
我尝试改动过几个学习率,发现都存在这个问题。
这里有几个疑问。
这个现象是正常的吗?我需要保存loss低时候的模型,降低学习率finetune来解决这个问题吗?这个问题出现的原因是什么?
你的数据没有问题吗 标签有没有打错 顺序有没有打乱
楼主你的问题解决了么,我这个也出现了类似的情况。但是在一次报错后出现的,程序运行到7w+次迭代报错如下: Check failed: error == cudaSuccess (4 vs. 0)
unspecified launch failure
然后利用snapshot文件重启继续训练,出现了loss增大问题,求解
要回复问题请先或
浏览: 1744
关注: 4 人&>&&>&&>&&>&caffe训练数据打乱程序
caffe训练数据打乱程序
上传大小:508KB
可用于打乱caffe的训练数据标签,以及格式为:[filename label]的txt文件数据顺序
综合评分:0(0位用户评分)
所需积分:0
下载次数:68
审核通过送C币
创建者:zhaoyading
创建者:blackwoodcliff
创建者:csnd_ayo
课程推荐相关知识库
上传者其他资源上传者专辑
开发技术热门标签
VIP会员动态
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
android服务器底层网络模块的设计方法
所需积分:0
剩余积分:720
您当前C币:0
可兑换下载积分:0
兑换下载分:
兑换失败,您当前C币不够,请先充值C币
消耗C币:0
你当前的下载分为234。
caffe训练数据打乱程序
会员到期时间:剩余下载次数:
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:}

我要回帖

更多关于 查询手机位置 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信