How to use the tfrecord.ExitOnExceptionHandler function in tfrecord

To help you get started, we’ve selected a few tfrecord examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jinnovation / rainy-image-dataset / tfrecord.py View on Github external
import tensorflow as tf


class ExitOnExceptionHandler(logging.StreamHandler):
    def __init__(self, critical_levels, *args, **kwargs):
        self.lvls = critical_levels
        super().__init__(*args, **kwargs)

    def emit(self, record):
        if record.levelno in self.lvls:
            raise SystemExit(-1)


logger = logging.getLogger(__name__)
click_log.basic_config(logger)
logger.handlers.append(ExitOnExceptionHandler([logging.CRITICAL]))

tf.enable_eager_execution()


def indices_all(ground_truth_dir):
    return [
        os.path.splitext(os.path.basename(f))[0]
        for f in glob.glob(os.path.join(ground_truth_dir, "*.jpg"))
    ]


def serialize_example(f_in, f_out, is_strict=True):
    def _bytes(value):
        return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value]))

    def _int(value):