Utils models
display_train_test_shape(df_train, df_test, df_shape=None)
Displays the size of a train/test split
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df_train |
DataFrame
|
Train dataset |
required |
df_test |
DataFrame
|
Test dataset |
required |
Kwargs: df_shape (int): Size of the initial dataset Raises: ValueError: If the object df_shape is not positive
Source code in template_vision/models_training/utils_models.py
load_model(model_dir, is_path=False)
Loads a model from a path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model_dir |
str
|
Name of the folder containing the model (e.g. model_autres_2019_11_07-13_43_19) |
required |
Kwargs: is_path (bool): If folder path instead of name (permits to load model from elsewhere) Returns: ?: Model dict: Model configurations
Source code in template_vision/models_training/utils_models.py
normal_split(df, test_size=0.25, seed=None)
Splits a DataFrame into train and test sets
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Dataframe containing the data |
required |
Kwargs: test_size (float): Proportion representing the size of the expected test set seed (int): random seed Raises: ValueError: If the object test_size is not between 0 and 1 Returns: DataFrame: Train dataframe DataFrame: Test dataframe
Source code in template_vision/models_training/utils_models.py
predict(data_input, model, model_conf, return_proba=False, **kwargs)
Gets predictions of a model on images
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_input |
str | list<str> | np.ndarray
|
New content to be predicted
- str: abs. path to an image
- list |
required |
model |
ModelClass
|
Model to use |
required |
model_conf |
dict
|
Model configurations |
required |
Kwargs: return_proba (bool): If probabilities must be return instead Raises: NotImplementedError: If model is object detection task FileNotFoundError: If the input file does not exist (input type == str) FileNotFoundError: If one of the input files does not exist (input type == list) ValueError: If the input image format is not compatible (input type == np.ndarray) ValueError: If the input array is not compatible (input type == np.ndarray) ValueError: If the input DataFrame does not contains a 'file_path' column (input type == pd.DataFrame) ValueError: If the input type is not a valid type option Returns: List[str], np.ndarray: predictions or probabilities - If return_proba -> np.ndarray - Else List[str]
Source code in template_vision/models_training/utils_models.py
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 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
predict_with_proba(data_input, model, model_conf)
Gets probabilities predictions of a model on a dataset
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_input |
str | list<str> | np.ndarray
|
New content to be predicted
- str: abs. path to an image
- list |
required |
model |
ModelClass
|
Model to use |
required |
model_conf |
dict
|
Model configurations |
required |
Raises: NotImplementedError: If model is object detection task ValueError : If predict does not return an np.ndarray Returns: Union[List[str], List[float]]: predictions, probabilities
Source code in template_vision/models_training/utils_models.py
remove_small_classes(df, col, min_rows=2)
Deletes the classes with small numbers of elements
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Dataframe containing the data |
required |
col |
str | int
|
Columns containing the classes |
required |
Kwargs: min_rows (int): Minimal number of lines in the training set (default: 2) Raises: ValueError: If the object min_rows is not positive Returns: pd.DataFrame: New dataset
Source code in template_vision/models_training/utils_models.py
stratified_split(df, col, test_size=0.25, seed=None)
Splits a DataFrame into train and test sets - Stratified strategy
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Dataframe containing the data |
required |
col |
str or int
|
column on which to do the stratified split |
required |
Kwargs: test_size (float): Proportion representing the size of the expected test set seed (int): Random seed Raises: ValueError: If the object test_size is not between 0 and 1 Returns: DataFrame: Train dataframe DataFrame: Test dataframe