Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default to lmdb for database storage #1128

Merged
merged 2 commits into from
Sep 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/cifar10/create_cifar10.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ rm -rf $EXAMPLE/cifar10_train_leveldb $EXAMPLE/cifar10_test_leveldb
echo "Computing image mean..."

./build/tools/compute_image_mean $EXAMPLE/cifar10_train_leveldb \
$EXAMPLE/mean.binaryproto
$EXAMPLE/mean.binaryproto leveldb

echo "Done."
10 changes: 5 additions & 5 deletions examples/imagenet/create_imagenet.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
# Create the imagenet leveldb inputs
# Create the imagenet lmdb inputs
# N.B. set the path to the imagenet train + val data dirs

EXAMPLE=examples/imagenet
Expand Down Expand Up @@ -34,24 +34,24 @@ if [ ! -d "$VAL_DATA_ROOT" ]; then
exit 1
fi

echo "Creating train leveldb..."
echo "Creating train lmdb..."

GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$TRAIN_DATA_ROOT \
$DATA/train.txt \
$EXAMPLE/ilsvrc12_train_leveldb
$EXAMPLE/ilsvrc12_train_lmdb

echo "Creating val leveldb..."
echo "Creating val lmdb..."

GLOG_logtostderr=1 $TOOLS/convert_imageset \
--resize_height=$RESIZE_HEIGHT \
--resize_width=$RESIZE_WIDTH \
--shuffle \
$VAL_DATA_ROOT \
$DATA/val.txt \
$EXAMPLE/ilsvrc12_val_leveldb
$EXAMPLE/ilsvrc12_val_lmdb

echo "Done."
7 changes: 3 additions & 4 deletions examples/mnist/convert_mnist_data.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//
// This script converts the MNIST dataset to the leveldb format used
// by caffe to perform classification.
// This script converts the MNIST dataset to a lmdb (default) or
// leveldb (--backend=leveldb) format used by caffe to load data.
// Usage:
// convert_mnist_data [FLAGS] input_image_file input_label_file
// output_db_file
Expand Down Expand Up @@ -176,7 +175,7 @@ int main(int argc, char** argv) {
#endif

gflags::SetUsageMessage("This script converts the MNIST dataset to\n"
"the leveldb/lmdb format used by Caffe to perform classification.\n"
"the lmdb/leveldb format used by Caffe to load data.\n"
"Usage:\n"
" convert_mnist_data [FLAGS] input_image_file input_label_file "
"output_db_file\n"
Expand Down
2 changes: 1 addition & 1 deletion examples/mnist/create_mnist.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
# This script converts the mnist data into leveldb/lmdb format,
# This script converts the mnist data into lmdb/leveldb format,
# depending on the value assigned to $BACKEND.

EXAMPLE=examples/mnist
Expand Down
9 changes: 5 additions & 4 deletions examples/mnist/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ You will first need to download and convert the data format from the MNIST websi
cd $CAFFE_ROOT/examples/mnist
./create_mnist.sh

If it complains that `wget` or `gunzip` are not installed, you need to install them respectively. After running the script there should be two datasets, `mnist-train-leveldb`, and `mnist-test-leveldb`.
If it complains that `wget` or `gunzip` are not installed, you need to install them respectively. After running the script there should be two datasets, `mnist_train_lmdb`, and `mnist_test_lmdb`.

## LeNet: the MNIST Classification Model

Expand All @@ -37,21 +37,22 @@ Specifically, we will write a `caffe::NetParameter` (or in python, `caffe.proto.

### Writing the Data Layer

Currently, we will read the MNIST data from the leveldb we created earlier in the demo. This is defined by a data layer:
Currently, we will read the MNIST data from the lmdb we created earlier in the demo. This is defined by a data layer:

layers {
name: "mnist"
type: DATA
data_param {
source: "mnist-train-leveldb"
source: "mnist_train_lmdb"
backend: LMDB
batch_size: 64
scale: 0.00390625
}
top: "data"
top: "label"
}

Specifically, this layer has name `mnist`, type `data`, and it reads the data from the given leveldb source. We will use a batch size of 64, and scale the incoming pixels so that they are in the range \[0,1\). Why 0.00390625? It is 1 divided by 256. And finally, this layer produces two blobs, one is the `data` blob, and one is the `label` blob.
Specifically, this layer has name `mnist`, type `data`, and it reads the data from the given lmdb source. We will use a batch size of 64, and scale the incoming pixels so that they are in the range \[0,1\). Why 0.00390625? It is 1 divided by 256. And finally, this layer produces two blobs, one is the `data` blob, and one is the `label` blob.

### Writing the Convolution Layer

Expand Down
6 changes: 4 additions & 2 deletions models/bvlc_alexnet/train_val.prototxt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ layers {
top: "data"
top: "label"
data_param {
source: "examples/imagenet/ilsvrc12_train_leveldb"
source: "examples/imagenet/ilsvrc12_train_lmdb"
backend: LMDB
batch_size: 256
}
transform_param {
Expand All @@ -21,7 +22,8 @@ layers {
top: "data"
top: "label"
data_param {
source: "examples/imagenet/ilsvrc12_val_leveldb"
source: "examples/imagenet/ilsvrc12_val_lmdb"
backend: LMDB
batch_size: 50
}
transform_param {
Expand Down
6 changes: 4 additions & 2 deletions models/bvlc_reference_caffenet/train_val.prototxt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ layers {
top: "data"
top: "label"
data_param {
source: "examples/imagenet/ilsvrc12_train_leveldb"
source: "examples/imagenet/ilsvrc12_train_lmdb"
backend: LMDB
batch_size: 256
}
transform_param {
Expand All @@ -21,7 +22,8 @@ layers {
top: "data"
top: "label"
data_param {
source: "examples/imagenet/ilsvrc12_val_leveldb"
source: "examples/imagenet/ilsvrc12_val_lmdb"
backend: LMDB
batch_size: 50
}
transform_param {
Expand Down
4 changes: 2 additions & 2 deletions tools/compute_image_mean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ using std::max;
int main(int argc, char** argv) {
::google::InitGoogleLogging(argv[0]);
if (argc < 3 || argc > 4) {
LOG(ERROR) << "Usage: compute_image_mean input_leveldb output_file"
LOG(ERROR) << "Usage: compute_image_mean input_db output_file"
<< " db_backend[leveldb or lmdb]";
return 1;
}

string db_backend = "leveldb";
string db_backend = "lmdb";
if (argc == 4) {
db_backend = string(argv[3]);
}
Expand Down
15 changes: 5 additions & 10 deletions tools/convert_imageset.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
// This program converts a set of images to a leveldb by storing them as Datum
// proto buffers.
// This program converts a set of images to a lmdb/leveldb by storing them
// as Datum proto buffers.
// Usage:
// convert_imageset [-g] ROOTFOLDER/ LISTFILE DB_NAME RANDOM_SHUFFLE[0 or 1]
// [resize_height] [resize_width]
// 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
// ....
// if RANDOM_SHUFFLE is 1, a random shuffle will be carried out before we
// process the file lines.
// Optional flag -g indicates the images should be read as
// single-channel grayscale. If omitted, grayscale images will be
// converted to color.

#include <gflags/gflags.h>
#include <glog/logging.h>
Expand All @@ -38,7 +33,7 @@ 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, "leveldb", "The backend for storing the result");
DEFINE_string(backend, "lmdb", "The backend for storing the result");
DEFINE_int32(resize_width, 0, "Width images are resized to");
DEFINE_int32(resize_height, 0, "Height images are resized to");

Expand Down