Progress¶
-
class Progress(message, total_cnt=
None, ext_logger=None, is_size=False, need_info_log=False, min_report_percent=1, log_extra=None, update_task_progress=True)[source]¶ Bases:
objectProgress reporter for long-running operations.
Can be used as a callback to increment and log progress (optionally with size-based labels).
Modules operations monitoring and displaying statistics of data processing.
Progressobject is immutable.- Parameters:
- message : str¶
Progress message e.g. “Images uploaded:”, “Processing:”.
- total_cnt : int, optional¶
Total count.
- ext_logger : logger, optional¶
Logger object.
- is_size : bool, optional¶
Shows Label size.
- need_info_log : bool, optional¶
Shows info log.
- min_report_percent : int, optional¶
Minimum report percent of total items in progress to log.
- Usage Example:
import os from dotenv import load_dotenv import supervisely as sly from supervisely.sly_logger import logger # Load secrets and create API object from .env file (recommended) # Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication if sly.is_development(): load_dotenv(os.path.expanduser("~/supervisely.env")) api = sly.Api.from_env() progress = sly.Progress("Images downloaded: ", len(img_infos), ext_logger=logger, is_size=True, need_info_log=True) api.image.download_paths(ds_id, image_ids, save_paths, progress_cb=progress.iters_done_report) # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 0, # "total": 6, "current_label": "0.0 B", "total_label": "6.0 B", "timestamp": "2021-03-17T13:57:45.659Z", "level": "info"} # {"message": "Images downloaded: [0.0 B / 6.0 B]", "timestamp": "2021-03-17T13:57:45.660Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 1, # "total": 6, "current_label": "1.0 B", "total_label": "6.0 B", "timestamp": "2021-03-17T13:57:46.134Z", "level": "info"} # {"message": "Images downloaded: [1.0 B / 6.0 B]", "timestamp": "2021-03-17T13:57:46.134Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 2, # "total": 6, "current_label": "2.0 B", "total_label": "6.0 B", "timestamp": "2021-03-17T13:57:46.135Z", "level": "info"} # {"message": "Images downloaded: [2.0 B / 6.0 B]", "timestamp": "2021-03-17T13:57:46.135Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 3, # "total": 6, "current_label": "3.0 B", "total_label": "6.0 B", "timestamp": "2021-03-17T13:57:46.135Z", "level": "info"} # {"message": "Images downloaded: [3.0 B / 6.0 B]", "timestamp": "2021-03-17T13:57:46.135Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 4, # "total": 6, "current_label": "4.0 B", "total_label": "6.0 B", "timestamp": "2021-03-17T13:57:46.135Z", "level": "info"} # {"message": "Images downloaded: [4.0 B / 6.0 B]", "timestamp": "2021-03-17T13:57:46.135Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 5, # "total": 6, "current_label": "5.0 B", "total_label": "6.0 B", "timestamp": "2021-03-17T13:57:46.136Z", "level": "info"} # {"message": "Images downloaded: [5.0 B / 6.0 B]", "timestamp": "2021-03-17T13:57:46.136Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Images downloaded: ", "current": 6, # "total": 6, "current_label": "6.0 B", "total_label": "6.0 B", "timestamp": "2021-03-17T13:57:46.136Z", "level": "info"} # {"message": "Images downloaded: [6.0 B / 6.0 B]", "timestamp": "2021-03-17T13:57:46.136Z", "level": "info"}
Methods
Increments the current iteration counter by 1
Increments the current iteration counter by 1 and logs a message depending on current number of iterations.
Increments the current iteration counter by given count
Increments the current iteration counter by given count and logs a message depending on current number of iterations.
need_reportLogs a message with level INFO on logger.
Determines whether the message should be logged depending on current number of iterations
Logs a message with level INFO in logger.
Sets counter current value and total value and logs a message depending on current number of iterations.
Increments the current iteration counter by this value minus the current value of the counter and logs a message depending on current number of iterations.
- iter_done_report()[source]¶
Increments the current iteration counter by 1 and logs a message depending on current number of iterations.
- Returns:
None
- Return type:
None
- Usage Example:
import supervisely as sly progress = sly.Progress("Processing:", len(img_infos)) for img_info in img_infos: img_names.append(img_info.name) progress.iter_done_report() # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 0, "total": 6, "timestamp": "2021-03-17T14:29:33.207Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 1, "total": 6, "timestamp": "2021-03-17T14:29:33.207Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 2, "total": 6, "timestamp": "2021-03-17T14:29:33.207Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 3, "total": 6, "timestamp": "2021-03-17T14:29:33.207Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 4, "total": 6, "timestamp": "2021-03-17T14:29:33.207Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 5, "total": 6, "timestamp": "2021-03-17T14:29:33.207Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 6, "total": 6, "timestamp": "2021-03-17T14:29:33.207Z", "level": "info"}
- iters_done_report(count)[source]¶
Increments the current iteration counter by given count and logs a message depending on current number of iterations.
- Parameters:
- Returns:
None
- Return type:
None
- Usage Example:
import supervisely as sly progress = sly.Progress("Processing:", len(img_infos)) for img_info in img_infos: img_names.append(img_info.name) progress.iters_done_report(1) # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 0, "total": 6, "timestamp": "2021-03-17T14:31:21.655Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 1, "total": 6, "timestamp": "2021-03-17T14:31:21.655Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 2, "total": 6, "timestamp": "2021-03-17T14:31:21.655Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 3, "total": 6, "timestamp": "2021-03-17T14:31:21.655Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 4, "total": 6, "timestamp": "2021-03-17T14:31:21.655Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 5, "total": 6, "timestamp": "2021-03-17T14:31:21.655Z", "level": "info"} # {"message": "progress", "event_type": "EventType.PROGRESS", "subtask": "Processing:", # "current": 6, "total": 6, "timestamp": "2021-03-17T14:31:21.655Z", "level": "info"}
- print_progress()[source]¶
Logs a message with level INFO on logger. Message contain type of progress, subtask message, currtnt and total number of iterations
- report_if_needed()[source]¶
Determines whether the message should be logged depending on current number of iterations
- report_progress()[source]¶
Logs a message with level INFO in logger. Message contain type of progress, subtask message, current and total number of iterations
- Returns:
None
- Return type:
None
-
set(current, total, report=
True)[source]¶ Sets counter current value and total value and logs a message depending on current number of iterations.