Skip to content

KailunChuang/matlab-lmdb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matlab LMDB

Matlab LMDB wrapper for UNIX environment.

See also matlab-leveldb.

The package does not contain any data serialization. Use char for storing keys and values. Those using Caffe might want to use a Datum converter in the caffe-extension branch also.

Build

Specify the MATLABDIR path.

make MATLABDIR=/usr/local/MATLAB/R2015a
make test

Edit Makefile to customize the build process.

In the caffe-extension branch, also specify the path to caffe.

make MATLABDIR=/usr/local/MATLAB/R2015a CAFFEDIR=../caffe

Example

% Open and close.
database = lmdb.DB('./db', 'MAPSIZE', 1024^3);
clear database;
readonly_database = lmdb.DB('./db', 'RDONLY', true, 'NOLOCK', true);
clear readonly_database;

% Read and write.
database.put('key1', 'value1');
database.put('key2', 'value2');
value1 = database.get('key1');
database.remove('key1');

% Iterator.
database.each(@(key, value) disp([key, ': ', value]));
count = database.reduce(@(key, value, count) count + 1, 0);

% Cursor.
cursor = database.cursor('RDONLY', true);
while cursor.next()
  key = cursor.key;
  value = cursor.value;
end
clear cursor;

% Transaction.
transaction = database.begin();
try
  transaction.put('key1', 'value1');
  transaction.put('key2', 'value2');
  transaction.commit();
catch exception
  transaction.abort();
end
clear transaction;

% Dump.
keys = database.keys();
values = database.values();

See help documentation of each function, or visit LMDB documentation to understand the flags.

Caffe extension

The caffe-extension branch includes utilities to convert Datum protocol buffer.

% Make plain datum.
image = imread('peppers.png');
label = 1;
datum = caffe_pb.toDatum(image, label);

% Make encoded datum.
fid = fopen('peppers.png', 'r');
png_image = fread(fid, inf, 'uint8=>uint8');
fclose(fid);
label = 1;
datum = caffe_pb.toEncodedDatum(png_image, label);

% Read datum.
[png_image, label] = caffe_pb.fromDatum(datum);

TODO

  • Finer transaction API.

About

Matlab LMDB wrapper

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 77.0%
  • C++ 18.2%
  • MATLAB 2.6%
  • Roff 1.5%
  • Makefile 0.7%