本文整理汇总了Python中scipy.io.matlab.loadmat方法的典型用法代码示例。如果您正苦于以下问题:Python matlab.loadmat方法的具体用法?Python matlab.loadmat怎么用?Python matlab.loadmat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.io.matlab
的用法示例。
在下文中一共展示了matlab.loadmat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from scipy.io import matlab [as 别名]
# 或者: from scipy.io.matlab import loadmat [as 别名]
def __init__(self, file_path: PathType):
assert HAVE_MAT, self.installation_mesg
super().__init__()
file_path = Path(file_path) if isinstance(file_path, str) else file_path
if not isinstance(file_path, Path):
raise TypeError(f"Expected a str or Path file_path but got '{type(file_path).__name__}'")
file_path = file_path.resolve() # get absolute path to this file
if not file_path.is_file():
raise ValueError(f"Specified file path '{file_path}' is not a file.")
self._kwargs = {"file_path": str(file_path.absolute())}
try: # load old-style (up to 7.2) .mat file
self._data = loadmat(file_path, matlab_compatible=True)
self._old_style_mat = True
except NameError: # loadmat not defined
raise ImportError("Old-style .mat file given, but `loadmat` is not defined.")
except NotImplementedError: # new style .mat file
try:
self._data = h5py.File(file_path, "r+")
self._old_style_mat = False
except NameError:
raise ImportError("Version 7.2 .mat file given, but you don't have h5py installed.")
示例2: load
# 需要导入模块: from scipy.io import matlab [as 别名]
# 或者: from scipy.io.matlab import loadmat [as 别名]
def load(filename):
"""
load any python object
"""
fd = open(filename, "r")
aux = cPickle.load(fd)
fd.close()
return aux
# def loadmat(filename):
# """
# load an array in matlab format
# """
# import scipy.io.matlab
# aux = scipy.io.matlab.loadmat(filename)
# fd.close()
# return aux
示例3: ReadDatasetFile
# 需要导入模块: from scipy.io import matlab [as 别名]
# 或者: from scipy.io.matlab import loadmat [as 别名]
def ReadDatasetFile(dataset_file_path):
"""Reads dataset file in Revisited Oxford/Paris ".mat" format.
Args:
dataset_file_path: Path to dataset file, in .mat format.
Returns:
query_list: List of query image names.
index_list: List of index image names.
ground_truth: List containing ground-truth information for dataset. Each
entry is a dict corresponding to the ground-truth information for a query.
The dict may have keys 'easy', 'hard', or 'junk', mapping to a NumPy
array of integers; additionally, it has a key 'bbx' mapping to a NumPy
array of floats with bounding box coordinates.
"""
with tf.io.gfile.GFile(dataset_file_path, 'rb') as f:
cfg = matlab.loadmat(f)
# Parse outputs according to the specificities of the dataset file.
query_list = [str(im_array[0]) for im_array in np.squeeze(cfg['qimlist'])]
index_list = [str(im_array[0]) for im_array in np.squeeze(cfg['imlist'])]
ground_truth_raw = np.squeeze(cfg['gnd'])
ground_truth = []
for query_ground_truth_raw in ground_truth_raw:
query_ground_truth = {}
for ground_truth_key in _GROUND_TRUTH_KEYS:
if ground_truth_key in query_ground_truth_raw.dtype.names:
adjusted_labels = query_ground_truth_raw[ground_truth_key] - 1
query_ground_truth[ground_truth_key] = adjusted_labels.flatten()
query_ground_truth['bbx'] = np.squeeze(query_ground_truth_raw['bbx'])
ground_truth.append(query_ground_truth)
return query_list, index_list, ground_truth