From 300308bbfefa9bc4e974265c48969cc81b7ce349 Mon Sep 17 00:00:00 2001 From: Amir MOHAMMADI <amir.mohammadi@idiap.ch> Date: Tue, 26 Apr 2022 15:52:03 +0200 Subject: [PATCH] in hdf5 files, if one key exists, just load that --- bob/io/base/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bob/io/base/__init__.py b/bob/io/base/__init__.py index be46d05..80612ba 100644 --- a/bob/io/base/__init__.py +++ b/bob/io/base/__init__.py @@ -88,12 +88,17 @@ def open_file(filename): if extension in hdf5_extensions: with h5py.File(filename, "r") as f: - if "array" not in f.keys(): + keys = list(f.keys()) + if len(keys) == 1: + key = keys[0] + else: + key = "array" + if key not in keys: raise RuntimeError( - "The file '%s' does not contain the key 'array'" % filename + f"The file {filename} does not contain the key {key}" ) - return np.array(f["array"]) + return np.array(f[key]) elif extension in image_extensions: img = imageio.imread(filename) -- GitLab