MCPcopy Create free account
hub / github.com/pytorch/pytorch / create_db

Function create_db

caffe2/python/examples/lmdb_create_example.py:24–62  ·  view source on GitHub ↗
(output_file)

Source from the content-addressed store, hash-verified

22
23
24def create_db(output_file):
25 print(">>> Write database...")
26 LMDB_MAP_SIZE = 1 << 40 # MODIFY
27 env = lmdb.open(output_file, map_size=LMDB_MAP_SIZE)
28
29 checksum = 0
30 with env.begin(write=True) as txn:
31 for j in range(0, 128):
32 # MODIFY: add your own data reader / creator
33 label = j % 10
34 width = 64
35 height = 32
36
37 img_data = np.random.rand(3, width, height)
38 # ...
39
40 # Create TensorProtos
41 tensor_protos = caffe2_pb2.TensorProtos()
42 img_tensor = tensor_protos.protos.add()
43 img_tensor.dims.extend(img_data.shape)
44 img_tensor.data_type = 1
45
46 flatten_img = img_data.reshape(np.prod(img_data.shape))
47 img_tensor.float_data.extend(flatten_img)
48
49 label_tensor = tensor_protos.protos.add()
50 label_tensor.data_type = 2
51 label_tensor.int32_data.append(label)
52 txn.put(
53 '{}'.format(j).encode('ascii'),
54 tensor_protos.SerializeToString()
55 )
56
57 checksum += np.sum(img_data) * label
58 if (j % 16 == 0):
59 print("Inserted {} rows".format(j))
60
61 print("Checksum/write: {}".format(int(checksum)))
62 return checksum
63
64
65def read_db_with_caffe2(db_file, expected_checksum):

Callers 1

mainFunction · 0.85

Calls 13

beginMethod · 0.80
encodeMethod · 0.80
rangeFunction · 0.50
openMethod · 0.45
randMethod · 0.45
addMethod · 0.45
extendMethod · 0.45
reshapeMethod · 0.45
prodMethod · 0.45
appendMethod · 0.45
putMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…