Giter Club home page Giter Club logo

matlab-lmdb's Introduction

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. You will need to serialize any Matlab variables to directly save in the database. For example, using num2str and str2double. There are different serialization options, such as this serialization package or JSON format. Those using Caffe might want to use a Datum converter in the caffe-extension branch.

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.

matlab-lmdb's People

Contributors

kyamagu avatar

Watchers

James Cloos avatar xwolfs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.