def test_nyudv2_to_lmdb_info(self, mock_dat, mock_caffe): # mock caffe calls made by our module mock_dat.return_value.SerializeToString.return_value = 'x' mock_caffe.io.array_to_datum.return_value = caffe.proto.caffe_pb2.Datum() 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] ] ]) imgs = np.expand_dims(x, axis=1).astype(float) imgs = np.tile(imgs, (3, 1, 1)) dat = {n2l.NYUDV2DataType.IMAGES : imgs, n2l.NYUDV2DataType.LABELS : x.astype(int) + 1, n2l.NYUDV2DataType.DEPTHS : x.astype(float) + 2 } p = os.path.join(self.dir_tmp, 'foo.mat') io.savemat(p, dat) prefix = 'xyz_' lmdb_info = n2l.nyudv2_to_lmdb(p, prefix, self.dir_tmp) assert_is_instance(lmdb_info, list) for info_ in lmdb_info: n = info_[0] plmdb = info_[-1] assert_true(os.path.isdir(plmdb)) if 'val' in os.path.basename(plmdb): assert_equal(n, 0)
def test_nyudv2_to_lmdb_info(self, mock_dat, mock_caffe): # mock caffe calls made by our module mock_dat.return_value.SerializeToString.return_value = 'x' mock_caffe.io.array_to_datum.return_value = caffe.proto.caffe_pb2.Datum() 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] ] ]) imgs = np.expand_dims(x, axis=1).astype(float) imgs = np.tile(imgs, (3, 1, 1)) dat = {n2l.NYUDV2DataType.IMAGES : imgs, n2l.NYUDV2DataType.LABELS : x.astype(int)+1, n2l.NYUDV2DataType.DEPTHS : x.astype(float)+2 } p = os.path.join(self.dir_tmp, 'foo.mat') io.savemat(p, dat) prefix = 'xyz_' lmdb_info = n2l.nyudv2_to_lmdb(p, prefix, self.dir_tmp) assert_is_instance(lmdb_info, list) for info_ in lmdb_info: n = info_[0] plmdb = info_[-1] assert_true(os.path.isdir(plmdb)) if 'val' in os.path.basename(plmdb): assert_equal(n, 0)