Skip to main content

Package for easy printing and logging to the terminal/console.

Project description

Prerequisites

To run this package python3.10 is reccomended. On early stages of developing this project this might not be important, but all further dependencies can require 3.10 version only.

How to install?

Installing this is simple, just write to the terminal:

pip install robustprinter

About

History

This package was born in desparate search for the tool to conveniently print training information to the console. Altough Tensorflow has its own pre-built printer, which is quite nice, pytorch doesn't have such luxuary. Most of my applications depend on torch and I was tired of tedious print statements around my code that was hard to make beautiful.

Main idea is to incapsulate functionality that I may use across different other applications in one package.

Usage

Main classes are Printer and Formatter. Printer regulates what, when and where something must be printed and Formatter regulates how it must be printed. For now package has only DefaultFormatter class – child of Formatter, and all it does is prints beautifully training info.

To see package in work try this code:

import time
import numpy as np
from robustprinter import Printer, formatter
from robustprinter.formatter import DefaultFormatter

class TestFormatter(formatter.Formatter):
    def __init__(self) -> None:
        super(TestFormatter, self).__init__()
    
    def format(self, data) -> str:
        return data
    
metrics_list = [
    'precision', 'recall', 'mAP50', 'mAP50-95', 'accuracy',
    'FID', 'loss'
]

def generate_random_metrics(metrics: list) -> dict:
    result = dict()
    for metric in metrics:
        result[metric] = np.random.rand()
    return result

if __name__ == '__main__':
    print('Start test.')
    max_steps = 10

    rformatter = DefaultFormatter(max_columns=2)
    rprinter = Printer(formatter=rformatter)
    rprinter.start()

    data = dict()
    for epoch in range(3):
        data['epoch'] = epoch
        for step in range(max_steps):
            data['step'] = step + 1
            data['max_steps'] = 10
            data['partition'] = 'train'
            data['metrics'] = generate_random_metrics(metrics=metrics_list)

            rprinter.print(data=data)
            time.sleep(1)
        rprinter.break_loop()

Examples

DefaultFormatter

DefaultFormatter

Contribution

This repository is about designing new formatters and printers. If you have an idea and want to share it – you are welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robustprinter-0.0.10.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

robustprinter-0.0.10-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file robustprinter-0.0.10.tar.gz.

File metadata

  • Download URL: robustprinter-0.0.10.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for robustprinter-0.0.10.tar.gz
Algorithm Hash digest
SHA256 83d9bd69209e22278ed39f9e3f812cfdf3297d58eb2b8b8278f18307b29386ed
MD5 0d41774e8a3f020ce48d96eccf1c4738
BLAKE2b-256 bde3cec960dd947e5f900c47a7fe2ac46870d5e117b79179ed1ab76cdb6ed168

See more details on using hashes here.

File details

Details for the file robustprinter-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: robustprinter-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for robustprinter-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 ae6110730bf5e0f18105764f8dfd1650cf471d6b3384070819924a7bdb6c860d
MD5 e7427a7bc38e0fb5880f15f7802a6421
BLAKE2b-256 7849d9a0e9c616ec339222d85f3d0f1aa3acf1c219559d72b5199e7f2c338992

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page