Coverage for src/elpv_dataset/utils.py: 100%
16 statements
« prev ^ index » next coverage.py v7.6.2, created at 2024-10-13 18:45 +0200
« prev ^ index » next coverage.py v7.6.2, created at 2024-10-13 18:45 +0200
1# SPDX-FileCopyrightText: 2018-present Sergiu Deitsch <sergiu.deitsch@gmail.com>
2#
3# SPDX-License-Identifier: Apache-2.0
5from PIL import Image
6import numpy as np
7import os
10def load_dataset(fname=None):
11 if fname is None:
12 fname = os.path.join(os.path.dirname(__file__), 'data', 'labels.csv')
14 data = np.genfromtxt(
15 fname, dtype=['|S19', '<f8', '|S4'], names=['path', 'probability', 'type']
16 )
17 image_fnames = np.char.decode(data['path'])
18 probs = data['probability']
19 types = np.char.decode(data['type'])
21 def load_cell_image(fname):
22 with Image.open(fname) as image:
23 return np.asarray(image)
25 dir = os.path.dirname(fname)
27 images = np.array([load_cell_image(os.path.join(dir, fn)) for fn in image_fnames])
29 return images, probs, types