-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlr_utils.py
41 lines (31 loc) · 1.49 KB
/
lr_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import numpy as np
import h5py
def load_dataset():
"""
Load the dataset from H5 files and preprocess it.
Returns:
--------
train_set_x_orig : numpy.ndarray
Training set features, originally loaded from the dataset.
train_set_y_orig : numpy.ndarray
Training set labels, reshaped to a 2D array.
test_set_x_orig : numpy.ndarray
Test set features, originally loaded from the dataset.
test_set_y_orig : numpy.ndarray
Test set labels, reshaped to a 2D array.
classes : numpy.ndarray
Array containing the list of class labels.
"""
# Load training data
with h5py.File('datasets/train_catvnoncat.h5', "r") as train_dataset:
train_set_x_orig = np.array(train_dataset["train_set_x"][:]) # Training set features
train_set_y_orig = np.array(train_dataset["train_set_y"][:]) # Training set labels
# Load test data
with h5py.File('datasets/test_catvnoncat.h5', "r") as test_dataset:
test_set_x_orig = np.array(test_dataset["test_set_x"][:]) # Test set features
test_set_y_orig = np.array(test_dataset["test_set_y"][:]) # Test set labels
classes = np.array(test_dataset["list_classes"][:]) # Class labels
# Reshape the labels to be 2D arrays for consistency
train_set_y_orig = train_set_y_orig.reshape((1, -1))
test_set_y_orig = test_set_y_orig.reshape((1, -1))
return train_set_x_orig, train_set_y_orig, test_set_x_orig, test_set_y_orig, classes