(output_file)
| 22 | |
| 23 | |
| 24 | def 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 | |
| 65 | def read_db_with_caffe2(db_file, expected_checksum): |
no test coverage detected
searching dependent graphs…