本文整理匯總了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