# Path: batchup/image/utils.py
# class ImageArrayUInt8ToFloat32 (object):
#     """
#     An array wrapper class that converts `uint8` image values in the range
#     0:255 to `float32` with the range being (optionally) provided to the
#     constructor. The default range is 0:1.
# 
#     Note: read-only
#     """
#     def __init__(self, arr_u8, val_lower=0.0, val_upper=1.0):
#         """
#         Constructor
# 
#         Parameters
#         ----------
#         arr_8: array-like object e.g. a NumPy array
#             An object that supports `__len__` and `__getitem__` and
#             optionally has a shape attribute
#         val_lower: float
#             The lower end of the output value range
#         val_upper: float
#             The upper end of the output value range
#         """
#         self.arr_u8 = arr_u8
#         self.offset = np.float32(val_lower)
#         self.scale = np.float32((val_upper - val_lower) / 255.0)
#         self.dtype = np.float32
# 
#     @property
#     def shape(self):
#         """
#         Shape attribute accessor
# 
#         Returns
#         -------
#         The shape of the underlying array if available, otherwise
#         raises `AttributeError`
#         """
#         try:
#             return self.arr_u8.shape
#         except AttributeError:
#             raise AttributeError('Underlying array has no `shape` attribute')
# 
#     def __len__(self):
#         """
#         Length accessor
# 
#         Returns
#         -------
#         The length of the underlying array.
#         """
#         return len(self.arr_u8)
# 
#     def __getitem__(self, *indices):
#         """
#         Item accessor
# 
#         Accesses elements from the underlying array and converts them to
#         `float32` type.
# 
#         Parameters
#         ----------
#         indices
#             Indices into the underlying array
# 
#         Returns
#         -------
#         Items from underlying array converted to `float32`
#         """
#         x = self.arr_u8.__getitem__(*indices)
#         return x.astype(np.float32) * self.scale + self.offset


import os
import six
import shutil
import tarfile
import numpy as np
import tables
from .. import config
from ..image.utils import ImageArrayUInt8ToFloat32
from . import dataset
            self.test_y = f.root.stl.test_y
            self.unl_X_u8 = f.root.stl.unl_X_u8
            tr_folds = f.root.stl.fold_indices
            tr_folds = [tr_folds[i] for i in range(len(tr_folds))]
            self.tr_folds = tr_folds

            if n_val_folds == 0 or n_val_folds is None:
                self.train_X_u8 = train_X_u8
                self.train_y = train_y
                self.val_X_u8 = np.zeros((0, 3, 96, 96), dtype=np.uint8)
                self.val_y = np.zeros((0,), dtype=np.int32)
            else:
                val_indices = np.concatenate(tr_folds[-n_val_folds:], axis=0)
                val_mask = np.zeros((len(train_y),), dtype=bool)
                val_mask[val_indices] = True
                train_indices = np.arange(len(train_y))[~val_mask]
                self.train_X_u8 = train_X_u8[train_indices, :, :, :]
                self.val_X_u8 = train_X_u8[val_indices, :, :, :]
                self.train_y = train_y[train_indices]
                self.val_y = train_y[val_indices]

            self.class_names = dataset.classnames_from_h5(
                f.root.stl.class_names)
        else:
            raise RuntimeError('Could not load MNIST dataset')

        self.train_X = ImageArrayUInt8ToFloat32(self.train_X_u8, val_lower,
                                                val_upper)
        self.val_X = ImageArrayUInt8ToFloat32(self.val_X_u8, val_lower,
                                              val_upper)

# Path: batchup/image/utils.py
# class ImageArrayUInt8ToFloat32 (object):
#     """
#     An array wrapper class that converts `uint8` image values in the range
#     0:255 to `float32` with the range being (optionally) provided to the
#     constructor. The default range is 0:1.
# 
#     Note: read-only
#     """
#     def __init__(self, arr_u8, val_lower=0.0, val_upper=1.0):
#         """
#         Constructor
# 
#         Parameters
#         ----------
#         arr_8: array-like object e.g. a NumPy array
#             An object that supports `__len__` and `__getitem__` and
#             optionally has a shape attribute
#         val_lower: float
#             The lower end of the output value range
#         val_upper: float
#             The upper end of the output value range
#         """
#         self.arr_u8 = arr_u8
#         self.offset = np.float32(val_lower)
#         self.scale = np.float32((val_upper - val_lower) / 255.0)
#         self.dtype = np.float32
# 
#     @property
#     def shape(self):
#         """
#         Shape attribute accessor
# 
#         Returns
#         -------
#         The shape of the underlying array if available, otherwise
#         raises `AttributeError`
#         """
#         try:
#             return self.arr_u8.shape
#         except AttributeError:
#             raise AttributeError('Underlying array has no `shape` attribute')
# 
#     def __len__(self):
#         """
#         Length accessor
# 
#         Returns
#         -------
#         The length of the underlying array.
#         """
#         return len(self.arr_u8)
# 
#     def __getitem__(self, *indices):
#         """
#         Item accessor
# 
#         Accesses elements from the underlying array and converts them to
#         `float32` type.
# 
#         Parameters
#         ----------
#         indices
#             Indices into the underlying array
# 
#         Returns
#         -------
#         Items from underlying array converted to `float32`
#         """
#         x = self.arr_u8.__getitem__(*indices)
#         return x.astype(np.float32) * self.scale + self.offset


# Path: batchup/datasets/stl.py
import os
import six
import shutil
import tarfile
import numpy as np
import tables
from .. import config
from ..image.utils import ImageArrayUInt8ToFloat32
from . import dataset

            self.test_y = f.root.stl.test_y
            self.unl_X_u8 = f.root.stl.unl_X_u8
            tr_folds = f.root.stl.fold_indices
            tr_folds = [tr_folds[i] for i in range(len(tr_folds))]
            self.tr_folds = tr_folds

            if n_val_folds == 0 or n_val_folds is None:
                self.train_X_u8 = train_X_u8
                self.train_y = train_y
                self.val_X_u8 = np.zeros((0, 3, 96, 96), dtype=np.uint8)
                self.val_y = np.zeros((0,), dtype=np.int32)
            else:
                val_indices = np.concatenate(tr_folds[-n_val_folds:], axis=0)
                val_mask = np.zeros((len(train_y),), dtype=bool)
                val_mask[val_indices] = True
                train_indices = np.arange(len(train_y))[~val_mask]
                self.train_X_u8 = train_X_u8[train_indices, :, :, :]
                self.val_X_u8 = train_X_u8[val_indices, :, :, :]
                self.train_y = train_y[train_indices]
                self.val_y = train_y[val_indices]

            self.class_names = dataset.classnames_from_h5(
                f.root.stl.class_names)
        else:
            raise RuntimeError('Could not load MNIST dataset')

        self.train_X = ImageArrayUInt8ToFloat32(self.train_X_u8, val_lower,
                                                val_upper)
        self.val_X = ImageArrayUInt8ToFloat32(self.val_X_u8, val_lower,
                                              val_upper)

        self.test_X = ImageArrayUInt8ToFloat32(self.test_X_u8, val_lower,