Skip to content

Instantly share code, notes, and snippets.

@hiwonjoon
Last active February 14, 2017 10:59

Revisions

  1. hiwonjoon revised this gist May 9, 2015. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions converter
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,14 @@ db = leveldb.LevelDB('./cifar_test',block_size=40 * (2 << 20) )

    import struct

    def unpickle(file):
    import cPickle
    fo = open(file,'rb')
    dict = cPickle.load(fo)
    fo.close()
    return dict

    obj = unpickle('./test.pkl')

    batch = leveldb.WriteBatch()
    print 'Start Reading...'
  2. hiwonjoon renamed this gist May 9, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. hiwonjoon created this gist May 9, 2015.
    36 changes: 36 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    import caffe_pb2 as proto
    import leveldb
    import sys

    db = leveldb.LevelDB('./cifar_test',block_size=40 * (2 << 20) )

    import struct



    batch = leveldb.WriteBatch()
    print 'Start Reading...'
    length = len(obj.get_data())

    for i, label_data in enumerate(zip(obj.get_data()[1],obj.get_data()[0])):
    datum = proto.Datum()
    datum.channels = 3
    datum.height = 32
    datum.width = 32
    datum.label = int(label_data[0][0])

    for data in label_data[1]:
    datum.float_data.append(data);

    key = '%05d' % i
    out = datum.SerializeToString()

    batch.Put(key,out)

    print 'End Reading...'
    print 'Strat Writing DB...'
    db.Write(batch,sync=True)
    print 'End Writing DB...'
    print 'Done'

    db = None