Utilities#
- FilePath: TypeAliasType = str | bytes | os.PathLike#
Type alias for a file path.
str
|bytes
|os.PathLike
- class glasses_detector.utils.eval_infer_mode(model: Module)[source]#
Bases:
object
Context manager and decorator for evaluation and inference.
This class can be used as a context manager or a decorator to set a PyTorch
Module
to evaluation mode viaeval()
and enableinference_mode
for the duration of a function or awith
statement. After the function or thewith
statement, the model’s mode, i.e.,training
property, andinference_mode
are restored to their original states.Example
model = ... # Your PyTorch model @eval_infer_mode(model) def your_function(): # E.g., forward pass pass # or with eval_infer_mode(model): # E.g., forward pass pass
- Parameters:
model (torch.nn.Module) – The PyTorch model to be set to evaluation mode.
- glasses_detector.utils.is_url(x: str) bool [source]#
Check if a string is a valid URL.
Takes any string and checks if it is a valid URL.
See also
- glasses_detector.utils.flatten(items: T) T [source]#
- glasses_detector.utils.flatten(items: Iterable[T | Iterable]) list[T]
Flatten a nested list.
This function takes any nested iterable and returns a flat list.
- glasses_detector.utils.is_path_type(path: Any) TypeGuard[FilePath] [source]#
Check if an object is a valid path type.
This function takes any object and checks if it is a valid path type. A valid path type is either a
str
,bytes
oros.PathLike
object.