Utils
DownloadProgressBar
Bases: tqdm
Displays a progress bar
Source code in template_vision/utils.py
HiddenPrints
Hides all prints
Source code in template_vision/utils.py
NpEncoder
Bases: JSONEncoder
JSON encoder to manage numpy objects
Source code in template_vision/utils.py
data_agnostic_str_to_list(function)
Decorator to transform a string into a list of one element. DO NOT CAST BACK TO ONE ELEMENT.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function |
func
|
Function to decorate |
required |
Returns: function: The decorated function
Source code in template_vision/utils.py
display_shape(df)
Displays the number of line and of column of a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Table to parse |
required |
Source code in template_vision/utils.py
download_url(urls, output_path)
Downloads an object from a list of URLs. This function will try every URL until it find an available one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urls |
list
|
List of URL to try |
required |
output_path |
str
|
Where to save the downloaded object |
required |
Raises: ConnectionError: If no URL is available
Source code in template_vision/utils.py
find_folder_path(folder_name, base_folder=None)
Find a folder in a base folder and its subfolders. If base_folder is None, considers folder_name as a path and check it exists
i.e., with the following structure : - C:/ - base_folder/ - folderA/ - folderB/ - folderC/ find_folder_path(folderA, C:/base_folder) == C:/base_folder/folderA find_folder_path(folderB, C:/base_folder) == C:/base_folder/folderA/folderB find_folder_path(C:/base_folder/folderC, None) == C:/base_folder/folderC find_folder_path(folderB, None) raises an error
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_name |
str
|
name of the folder to find. If base_folder is None, consider a path instead. |
required |
Kwargs: base_folder (str): path of the base folder. If None, consider folder_name as a path. Raises: FileNotFoundError: If we can't find folder_name in base_folder FileNotFoundError: If folder_name is not a valid path (case where base_folder is None) Returns: str: path to the wanted folder
Source code in template_vision/utils.py
get_chunk_limits(x, chunksize=10000)
Gets chunk limits from a pandas series or dataframe.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Series or DataFrame
|
Documents to consider |
required |
Kwargs:
chunksize (int): The chunk size
Raises:
ValueError: If the chunk size is negative
Returns:
list
Source code in template_vision/utils.py
get_data_path()
Returns the path to the data folder
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path of the data folder |
Source code in template_vision/utils.py
get_models_path()
Returns the path to the models folder
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path of the models folder |
Source code in template_vision/utils.py
get_package_version()
Returns the current version of the package
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
version of the package |
get_ressources_path()
Returns the path to the ressources folder
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
Path of the ressources folder |
Source code in template_vision/utils.py
is_ndarray_convertable(obj)
Returns True if the object is covertable to a builtin type in the same way a np.ndarray is
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Any
|
an object to test |
required |
Returns: bool: True if the object is covertable to a list as a np.ndarray is
Source code in template_vision/utils.py
ndarray_to_builtin_object(obj)
Transform a numpy.ndarray like object to a builtin type like int, float or list
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Any
|
An object |
required |
Raises: ValueError: Raise a ValueError when obj is not ndarray convertable Returns: Any: The object converted to a builtin type like int, float or list
Source code in template_vision/utils.py
read_folder(folder_path, images_ext=('.jpg', '.jpeg', '.png'), sep=';', encoding='utf-8', accept_no_metadata=False)
Loads images and classes / bboxes from a directory of images
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path |
str
|
Directory with the images to be loaded - abs path |
required |
Kwargs: images_ext (tuple): Accepted images extensions if automatic detection (i.e. no metadata file) sep (str): Separator of the metadata file - if exists encoding (str): Encoding of the metadata file - if exists accept_no_metadata (bool): If we allow no targets metadata (i.e. returns only file paths, useful for predictions) Returns: list: List of images path list: List of classes associated with images if classification task, bboxes if objet detection task str: Name of the prerprocessing pipeline used str: Task type ('classification' or 'object_detection')
Source code in template_vision/utils.py
read_folder_classification(folder_path, images_ext=('.jpg', '.jpeg', '.png'), sep=';', encoding='utf-8', accept_no_metadata=False)
Loads images and classes from a directory of images - classification task
Solution 1: usage of a metadata file (metadata.csv) Solution 2: all images at root directory, and prefixed with class names (e.g. class_filename.ext) Solution 3: all images saved in class subdirectories Solution 4: read images from root directory - no targets
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path |
str
|
Directory with the images to be loaded - abs path |
required |
Kwargs: images_ext (tuple): Accepted images extensions if automatic detection (i.e. no metadata file) sep (str): Separator of the metadata file - if exists encoding (str): Encoding of the metadata file - if exists accept_no_metadata (bool): If we allow no targets metadata (i.e. returns only file paths, useful for predictions) Raises: FileNotFoundError: If folder path does not exists NotADirectoryError: If the provided path is not a directory ValueError: If column 'filename' does not exists in the metadata file ValueError: If column 'class' does not exists in the metadata file and accept_no_metadata is False RuntimeError: If no loading solution found Returns: list: List of images path list: List of classes associated with images str: Name of the prerprocessing pipeline used
Source code in template_vision/utils.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
read_folder_object_detection(folder_path, images_ext=('.jpg', '.jpeg', '.png'), sep=';', encoding='utf-8', accept_no_metadata=False)
Loads images and bboxes from a directory of images - object detection task
Solution 1: usage of a metadata file (metadata_bboxes.csv) Solution 2: read images from root directory - no targets
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path |
str
|
Directory with the images to be loaded - abs path |
required |
Kwargs: images_ext (tuple): Accepted images extensions if automatic detection (i.e. no metadata file) sep (str): Separator of the metadata file - if exists encoding (str): Encoding of the metadata file - if exists accept_no_metadata (bool): If we allow no targets metadata (i.e. returns only file paths, useful for predictions) Raises: FileNotFoundError: If folder path does not exists NotADirectoryError: If the provided path is not a directory ValueError: If column 'filename' does not exists in the metadata file RuntimeError: If no loading solution found Returns: list: List of images path list: List of bboxes associated with images str: Name of the prerprocessing pipeline used
Source code in template_vision/utils.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
|
rebuild_metadata_classification(filenames_list, classes_list)
Rebuilds a metadata file from files names and associated classes - classification task
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filenames_list |
list
|
List of files names (actually a path relative to files parent directory) |
required |
classes_list |
list
|
List of classes |
required |
Raises: ValueError: Both list must be of same length Returns: pd.DataFrame: The new metadata dataframe
Source code in template_vision/utils.py
rebuild_metadata_object_detection(filenames_list, bboxes_list)
Rebuilds a metadata file from files names and associated bboxes - object detection task
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filenames_list |
list
|
List of files names (actually a path relative to files parent directory) |
required |
bboxes_list |
list
|
List of bboxes |
required |
Raises: ValueError: Both list must be of same length Returns: pd.DataFrame: The new metadata dataframe
Source code in template_vision/utils.py
trained_needed(function)
Decorator to ensure that a model has been trained.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
function |
func
|
Function to decorate |
required |
Returns: function: The decorated function