-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathconvert_lmdb.py
57 lines (44 loc) · 1.92 KB
/
convert_lmdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
# Copyright (c) 2017. Vincenzo Lomonaco. All rights reserved. #
# See the accompanying LICENSE file for terms. #
# #
# Date: 28-04-2017 #
# Author: Vincenzo Lomonaco #
# E-mail: vincenzo.lomonaco@unibo.it #
# Website: vincenzolomonaco.com #
################################################################################
"""
Simple script to create the lmdb based on a directory in which
the patterns are divided in dirs (which names correspond to the int labels).
It can be run also as a standalone script.
"""
# Dependencies
import os
def from_filelist_to_lmdb(root, filelist_path, name, dst_lmdb,
compute_mean=False):
""" Method to pass from the filelist (caffe format) to the the lmdb. """
# Create lmdb
print("Creating lmdb for: " + name)
command = 'convert_imageset -encoded -shuffle -encode_type jpg ' + \
root + ' ' + filelist_path + ' ' + \
dst_lmdb + name + "_lmdb"
# Print command
os.system(command)
if compute_mean:
command = 'compute_image_mean ' + dst_lmdb + name + "_lmdb "\
+ dst_lmdb + "mean_" + name + ".binaryproto"
os.system(command)
if __name__ == "__main__":
# Parametrization example
from_filelist_to_lmdb(
# src of the images (root)
'/insert/your/path/',
# where to save the filelist
'/insert/your/path/',
# base name of the lmdb
'core50',
# where to put it
'/insert/your/path/'
)