diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-04-15 16:26:03 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-04-15 16:26:03 +0200 |
| commit | 79f0e696f3f6067a0841a37404fb546dedaa07cb (patch) | |
| tree | a064f2841dc532f81fcf04eb84300e679fda2b27 /check/app/utils | |
| parent | e257e83f313a2976347b0a30f58e66b7bcbc1235 (diff) | |
cli suite working
Diffstat (limited to 'check/app/utils')
| -rw-r--r-- | check/app/utils/im_utils.py | 3 | ||||
| -rw-r--r-- | check/app/utils/logger_utils.py | 68 |
2 files changed, 70 insertions, 1 deletions
diff --git a/check/app/utils/im_utils.py b/check/app/utils/im_utils.py index dfd5739..747e900 100644 --- a/check/app/utils/im_utils.py +++ b/check/app/utils/im_utils.py @@ -15,6 +15,7 @@ import torch import torch.nn as nn import torchvision.models as models import torchvision.transforms as transforms +import struct from torch.autograd import Variable from sklearn.metrics.pairwise import cosine_similarity import datetime @@ -214,7 +215,7 @@ def phash2int(phash): :returns: binary-encoded bigint """ phash.hash[-1] = False - phash_as_bigint = struct.unpack('Q', numpy.packbits(phash.hash))[0] + phash_as_bigint = struct.unpack('Q', np.packbits(phash.hash))[0] return phash_as_bigint def compute_phash_int(im): diff --git a/check/app/utils/logger_utils.py b/check/app/utils/logger_utils.py new file mode 100644 index 0000000..d4f962e --- /dev/null +++ b/check/app/utils/logger_utils.py @@ -0,0 +1,68 @@ +""" +Logger instantiator for use with Click utlity scripts +""" +import sys +import os +import logging + +import colorlog + +from app.settings import app_cfg as cfg + + +class Logger: + + logger_name = 'app' + + def __init__(self): + pass + + @staticmethod + def create(verbosity=4, logfile=None): + """Configures a logger from click params + :param verbosity: (int) between 0 and 5 + :param logfile: (str) path to logfile + :returns: logging root object + """ + + loglevel = (5 - (max(0, min(verbosity, 5)))) * 10 # where logging.DEBUG = 10 + date_format = '%Y-%m-%d %H:%M:%S' + if 'colorlog' in sys.modules and os.isatty(2): + cformat = '%(log_color)s' + cfg.LOGFILE_FORMAT + f = colorlog.ColoredFormatter(cformat, date_format, + log_colors = { 'DEBUG' : 'yellow', 'INFO' : 'white', + 'WARNING' : 'bold_yellow', 'ERROR': 'bold_red', + 'CRITICAL': 'bold_red' }) + else: + f = logging.Formatter(cfg.LOGFILE_FORMAT, date_format) + + # logger = logging.getLogger(Logger.logger_name) + logger = logging.getLogger(cfg.LOGGER_NAME) + logger.setLevel(loglevel) + + if logfile: + # create file handler which logs even debug messages + fh = logging.FileHandler(logfile) + fh.setLevel(loglevel) + logger.addHandler(fh) + + # add colored handler + ch = logging.StreamHandler() + ch.setFormatter(f) + logger.addHandler(ch) + + if verbosity == 0: + logger.disabled = True + + # test + # logger.debug('Hello Debug') + # logger.info('Hello Info') + # logger.warn('Hello Warn') + # logger.error('Hello Error') + # logger.critical('Hello Critical') + + return logger + + @staticmethod + def getLogger(): + return logging.getLogger(cfg.LOGGER_NAME)
\ No newline at end of file |
