def setup_class(self): self.dir_tmp = tempfile.mkdtemp() x = np.array([[[ 1, 2, 3], [ 4, 5, 6] ], [[ 7, 8, 9], [10, 11, 12] ], [[13, 14, 15], [16, 17, 18], ], [[19, 20, 21], [22, 23, 24] ] ]) tol.arrays_to_lmdb([y for y in x], os.path.join(self.dir_tmp, 'x_lmdb'))
def test_arr_single(self, mock_dat, mock_caffe): # expected serialization of the test image s = '\x08\x03\x10\x04\x18\x02"\x18\x01\x04\x07\n\r\x10\x13\x16\x02\x05\x08\x0b\x0e\x11\x14\x17\x03\x06\t\x0c\x0f\x12\x15\x18(\x00' # mock caffe calls made by our module mock_dat.return_value.SerializeToString.return_value = s mock_caffe.io.array_to_datum.return_value = caffe.proto.caffe_pb2.Datum() # use the module and test it path_lmdb = os.path.join(self.dir_tmp, 'xarr1_lmdb') tol.arrays_to_lmdb([self.arr[0]], path_lmdb) assert_true(os.path.isdir(path_lmdb), "failed to save LMDB") count = 0 with lmdb.open(path_lmdb, readonly=True).begin() as txn: for key, value in txn.cursor(): assert_equal(key, '0000000000', "Unexpected key.") assert_equal(value, s, "Unexpected content.") count += 1 assert_equal(count, 1, "Unexpected number of samples.")