repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
triton | triton-main/python/triton/compiler/compiler.py | from __future__ import annotations
import functools
import hashlib
import json
import os
import re
import subprocess
import tempfile
from collections import namedtuple
from pathlib import Path
from typing import Any, Tuple
from .._C.libtriton.triton import (add_external_libs, compile_ptx_to_cubin,
... | 23,660 | 36.797125 | 144 | py |
triton | triton-main/python/triton/compiler/code_generator.py | import ast
import inspect
import re
import sys
import warnings
from typing import Any, Callable, Dict, Optional, Tuple, Type, Union
from .. import language
from .._C.libtriton.triton import ir
from ..language import constexpr, tensor
# ideally we wouldn't need any runtime component
from ..runtime import JITFunction
fr... | 49,833 | 42.790861 | 177 | py |
triton | triton-main/python/triton/compiler/__init__.py | from .compiler import CompiledKernel, compile, instance_descriptor
from .errors import CompilationError
__all__ = ["compile", "instance_descriptor", "CompiledKernel", "CompilationError"]
| 188 | 36.8 | 82 | py |
triton | triton-main/python/triton/language/semantic.py | from __future__ import annotations # remove after python 3.11
import warnings
from functools import wraps
from typing import List, Optional, Sequence, Tuple, TypeVar
from .._C.libtriton.triton import ir
from . import core as tl
T = TypeVar('T')
# Create custom exception that prints message "hello"
class Incompat... | 65,322 | 41.116699 | 272 | py |
triton | triton-main/python/triton/language/core.py | from __future__ import annotations
from contextlib import contextmanager
from enum import Enum
from functools import wraps
from typing import Callable, List, Sequence, TypeVar
from .._C.libtriton.triton import ir
from ..runtime.jit import jit
from . import math, semantic
T = TypeVar('T')
TRITON_MAX_TENSOR_NUMEL = 1... | 62,163 | 31.175983 | 137 | py |
triton | triton-main/python/triton/language/math.py | import functools
import os
from . import core
@functools.lru_cache()
def libdevice_path():
import torch
third_party_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "third_party")
if torch.version.hip is None:
default = os.path.join(third_party_dir, "cuda", "lib", "libdevice.1... | 75,127 | 47.943322 | 157 | py |
triton | triton-main/python/triton/language/standard.py | from __future__ import annotations
from ..runtime.jit import jit
from . import core
# -----------------------
# Standard library
# -----------------------
@jit
def cdiv(x, div):
"""
Computes the ceiling division of :code:`x` by :code:`div`
:param x: the input number
:type input: Block
:param di... | 2,320 | 22.444444 | 98 | py |
triton | triton-main/python/triton/language/random.py | from ..runtime.jit import jit
from . import core as tl
PHILOX_KEY_A: tl.constexpr = 0x9E3779B9
PHILOX_KEY_B: tl.constexpr = 0xBB67AE85
PHILOX_ROUND_A: tl.constexpr = 0xD2511F53
PHILOX_ROUND_B: tl.constexpr = 0xCD9E8D57
N_ROUNDS_DEFAULT = 10 # Default number of rounds for philox
# -------------------
# randint
# ----... | 5,569 | 30.117318 | 109 | py |
triton | triton-main/python/triton/language/__init__.py | """isort:skip_file"""
# Import order is significant here.
from . import math
from . import extra
from .standard import (
cdiv,
sigmoid,
softmax,
ravel,
swizzle2d,
zeros,
zeros_like,
)
from .core import (
TRITON_MAX_TENSOR_NUMEL,
abs,
advance,
arange,
argmin,
argmax,
... | 3,122 | 13.593458 | 35 | py |
triton | triton-main/python/triton/language/extra/cuda.py | import os
from .. import core
__path__ = os.path.dirname(os.path.abspath(__file__))
@core.extern
def globaltimer(_builder=None):
return core.extern_elementwise("cuda", os.path.join(__path__, "cuda.bc"), [],
{tuple(): ("globaltimer", core.dtype("int64")),
... | 641 | 31.1 | 82 | py |
triton | triton-main/python/triton/language/extra/__init__.py | from . import cuda
__all__ = ['cuda']
| 39 | 9 | 18 | py |
triton | triton-main/python/triton/ops/flash_attention.py | """
Fused Attention
===============
This is a Triton implementation of the Flash Attention algorithm
(see: Dao et al., https://arxiv.org/pdf/2205.14135v2.pdf; Rabe and Staats https://arxiv.org/pdf/2112.05682v2.pdf)
Sequence Parallel implementation inspired by HazyResearch
(see https://github.com/HazyResearch/flash-att... | 15,056 | 35.107914 | 113 | py |
triton | triton-main/python/triton/ops/cross_entropy.py | import torch
from .. import heuristics, jit
from .. import language as tl
from .. import next_power_of_2
def num_warps(N):
if N < 2048:
return 4
elif N < 8192:
return 8
return 16
@heuristics({'num_warps': lambda nargs: num_warps(nargs['N'])})
@heuristics({'BLOCK': lambda nargs: next_pow... | 3,450 | 34.947917 | 89 | py |
triton | triton-main/python/triton/ops/matmul.py | import torch
from .. import Config, autotune, cdiv, heuristics, jit
from .. import language as tl
from .matmul_perf_model import early_config_prune, estimate_matmul_time
_ordered_datatypes = [torch.float16, torch.bfloat16, torch.float32]
def get_higher_dtype(a, b):
if a is b:
return a
assert a in _... | 8,026 | 41.696809 | 127 | py |
triton | triton-main/python/triton/ops/__init__.py | # from .conv import _conv, conv
from . import blocksparse
from .cross_entropy import _cross_entropy, cross_entropy
from .flash_attention import attention
from .matmul import _matmul, matmul
__all__ = [
"blocksparse",
"_cross_entropy",
"cross_entropy",
"_matmul",
"matmul",
"attention",
]
| 313 | 19.933333 | 56 | py |
triton | triton-main/python/triton/ops/matmul_perf_model.py | import heapq
import torch
from .. import cdiv
from .._C.libtriton.triton import runtime
from ..runtime import driver
from ..testing import get_dram_gbps, get_max_simd_tflops, get_max_tensorcore_tflops
def get_tensorcore_tflops(backend, device, num_ctas, num_warps, dtype):
''' return compute throughput in TOPS '... | 6,369 | 39.062893 | 117 | py |
triton | triton-main/python/triton/ops/blocksparse/softmax.py | import torch
from ... import jit
from ... import language as tl
from ... import next_power_of_2
def num_warps(n):
if n <= 128:
return 1
if n <= 256:
return 2
if n <= 512:
return 4
if n <= 4096:
return 8
return 16
@jit
def _blocksparse_softmax_fwd(
Out, A, str... | 7,905 | 31.804979 | 94 | py |
triton | triton-main/python/triton/ops/blocksparse/matmul.py | import torch
from ... import cdiv, heuristics, jit
from ... import language as tl
# ********************************************************
# --------------------------------------------------------
# Sparse = Dense x Dense (SDD)
# This operation uses super-blocking to make sure that
# it's done efficiently when sma... | 15,615 | 34.652968 | 114 | py |
triton | triton-main/python/triton/ops/blocksparse/__init__.py | from .matmul import matmul
from .softmax import softmax
__all__ = [
"matmul",
"softmax",
]
| 100 | 11.625 | 28 | py |
triton | triton-main/test/lit.cfg.py | # -*- Python -*-
import os
import platform
import re
import subprocess
import tempfile
import lit.formats
import lit.util
from lit.llvm import llvm_config
from lit.llvm.subst import FindTool, ToolSubst
# Configuration file for the 'lit' test runner
# name: The name of this test suite
config.name = 'TRITON'
config.... | 2,187 | 28.567568 | 79 | py |
triton | triton-main/docs/conf.py | # -*- coding: utf-8 -*-
#
# Triton documentation build configuration file, created by
# sphinx-quickstart on Mon Feb 10 01:19:09 2020.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# Al... | 7,261 | 29.008264 | 84 | py |
G-PATE | G-PATE-master/main.py | import os
import scipy.misc
import numpy as np
from model import DCGAN
from utils import pp, visualize, to_json, show_all_variables, mkdir
import tensorflow as tf
import argparse
from gen_data import batch2str
import sys
import pickle
# os.environ["CUDA_VISIBLE_DEVICES"] = "1"
flags = tf.app.flags
flags.DEFINE_inte... | 6,951 | 43.564103 | 118 | py |
G-PATE | G-PATE-master/pate_core.py |
# core method from 'Scalable Private Learning with PATE'
# Copyright 2017 The 'Scalable Private Learning with PATE' Authors All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the Licens... | 12,472 | 32.350267 | 87 | py |
G-PATE | G-PATE-master/download.py | """
Modification of https://github.com/stanfordnlp/treelstm/blob/master/scripts/download.py
Downloads the following:
- Celeb-A dataset
- LSUN dataset
- MNIST dataset
"""
from __future__ import print_function
import os
import sys
import gzip
import json
import shutil
import zipfile
import argparse
import requests
impo... | 5,501 | 28.902174 | 112 | py |
G-PATE | G-PATE-master/rdp_utils.py | import numpy as np
import math
import sys
from sklearn.preprocessing import normalize
from pate_core import *
from numpy import linalg as LA
EPS = sys.float_info.epsilon
# Algorithm 1 in 'Scalable Private Learning with PATE'
def gnmax_thresh_aggregator(counts, thresh_cnt, sigma_thresh, sigma, orders):
log_pr_an... | 12,952 | 36.436416 | 124 | py |
G-PATE | G-PATE-master/dp_pca.py | # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 2,314 | 37.583333 | 97 | py |
G-PATE | G-PATE-master/utils.py | """
Some codes from https://github.com/Newmu/dcgan_code
"""
from __future__ import division
import math
import json
import random
import pprint
import scipy.misc
import numpy as np
from time import gmtime, strftime
from six.moves import xrange
import os
import tensorflow as tf
import tensorflow.contrib.slim as slim
p... | 9,032 | 33.215909 | 131 | py |
G-PATE | G-PATE-master/model.py | from __future__ import division
import os
import time
import math
from glob import glob
import tensorflow as tf
import numpy as np
from six.moves import xrange
import json
import sys
from keras.datasets import cifar10
from ops import *
from utils import *
from rdp_utils import *
from pate_core import *
import pickle
fr... | 57,590 | 43.575077 | 156 | py |
G-PATE | G-PATE-master/gen_data.py | import numpy as np
import argparse
x = [2, 2, 5, 8, 8, 9, 10, 11, 11, 12, 15, 28, 32, 42, 46, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101]
y = [[-1, 2], [-1, 2], [-1, 5], [-1, 8], [-1, 8], [-1, 9], [-1, 10], [-1, 11], [-1, 11], [-1, 12], [-1, 15], [-1, 28], [-1, 32], [-1, 42], [-1, 46], [14515... | 2,152 | 24.630952 | 502 | py |
G-PATE | G-PATE-master/ops.py | import math
import numpy as np
import tensorflow as tf
from tensorflow.python.framework import ops
from utils import *
try:
image_summary = tf.image_summary
scalar_summary = tf.scalar_summary
histogram_summary = tf.histogram_summary
merge_summary = tf.merge_summary
SummaryWriter = tf.train.SummaryWriter
e... | 3,925 | 34.369369 | 155 | py |
G-PATE | G-PATE-master/dp_utils.py | # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 2,431 | 32.777778 | 80 | py |
G-PATE | G-PATE-master/input.py | # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 5,028 | 31.031847 | 136 | py |
G-PATE | G-PATE-master/evaluation/train-classifier-celebA.py | #!/usr/bin/env python
# coding: utf-8
import numpy as np
import argparse
import joblib
import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
# config.gpu_options.per_process_gpu_memory_fraction = 0.3
tf.keras.backend.set_session(tf.Session(config=config));
def load_celeb():
... | 2,797 | 30.438202 | 107 | py |
G-PATE | G-PATE-master/evaluation/train-classifier-fmnist.py | #!/usr/bin/env python
# coding: utf-8
import numpy as np
import argparse
import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
# config.gpu_options.per_process_gpu_memory_fraction = 0.3
tf.keras.backend.set_session(tf.Session(config=config));
def pipeline():
parser = argpars... | 2,846 | 32.892857 | 109 | py |
G-PATE | G-PATE-master/evaluation/train-classifier-mnist.py | #!/usr/bin/env python
# coding: utf-8
import numpy as np
import argparse
import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
# config.gpu_options.per_process_gpu_memory_fraction = 0.3
tf.keras.backend.set_session(tf.Session(config=config));
def pipeline():
parser = argpa... | 2,661 | 32.696203 | 109 | py |
G-PATE | G-PATE-master/evaluation/train-classifier-hair.py | #!/usr/bin/env python
# coding: utf-8
# In[13]:
import numpy as np
import argparse
import joblib
import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
# config.gpu_options.per_process_gpu_memory_fraction = 0.3
tf.keras.backend.set_session(tf.Session(config=config));
def load_cel... | 2,820 | 29.010638 | 107 | py |
G-PATE | G-PATE-master/evaluation/train-classifier-small-celebA.py | #!/usr/bin/env python
# coding: utf-8
import numpy as np
import argparse
parser = argparse.ArgumentParser(description='Train classifier and evaluate their accuracy')
parser.add_argument('--data', type=str, help='datafile name')
args = parser.parse_args()
import joblib
data = joblib.load(args.data)
print(args.data)
... | 2,390 | 27.129412 | 107 | py |
kraken | kraken-main/setup.py | #!/usr/bin/env python
from setuptools import setup
setup(
include_package_data=True,
setup_requires=['pbr'],
pbr=True,
)
| 134 | 14 | 30 | py |
kraken | kraken-main/kraken/rpred.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 28,893 | 40.454806 | 121 | py |
kraken | kraken-main/kraken/linegen.py | #
# Copyright 2014 Google Inc. All rights reserved.
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# ... | 15,140 | 36.201474 | 120 | py |
kraken | kraken-main/kraken/align.py | #
# Copyright 2021 Teklia
# Copyright 2021 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applica... | 6,614 | 32.75 | 137 | py |
kraken | kraken-main/kraken/blla.py | #
# Copyright 2019 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 15,295 | 41.371191 | 140 | py |
kraken | kraken-main/kraken/pageseg.py | #
# Copyright 2015 Benjamin Kiessling
# 2014 Thomas M. Breuel
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by a... | 15,329 | 34.651163 | 118 | py |
kraken | kraken-main/kraken/kraken.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 30,865 | 42.351124 | 139 | py |
kraken | kraken-main/kraken/transcribe.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 4,922 | 42.955357 | 119 | py |
kraken | kraken-main/kraken/__init__.py | """
entry point for kraken functionality
"""
| 45 | 10.5 | 36 | py |
kraken | kraken-main/kraken/binarization.py | #
# Copyright 2015 Benjamin Kiessling
# 2014 Thomas M. Breuel
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by a... | 4,189 | 33.344262 | 95 | py |
kraken | kraken-main/kraken/repo.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 10,633 | 39.280303 | 124 | py |
kraken | kraken-main/kraken/serialization.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 14,465 | 41.422287 | 123 | py |
kraken | kraken-main/kraken/ketos/pretrain.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 15,667 | 52.474403 | 137 | py |
kraken | kraken-main/kraken/ketos/linegen.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 7,173 | 42.743902 | 124 | py |
kraken | kraken-main/kraken/ketos/dataset.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 4,912 | 50.177083 | 134 | py |
kraken | kraken-main/kraken/ketos/segmentation.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 29,987 | 48.98 | 151 | py |
kraken | kraken-main/kraken/ketos/util.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 1,889 | 28.076923 | 95 | py |
kraken | kraken-main/kraken/ketos/__init__.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 2,546 | 28.275862 | 113 | py |
kraken | kraken-main/kraken/ketos/transcription.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 9,437 | 40.946667 | 142 | py |
kraken | kraken-main/kraken/ketos/repo.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 4,240 | 37.207207 | 155 | py |
kraken | kraken-main/kraken/ketos/recognition.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 26,702 | 52.087475 | 151 | py |
kraken | kraken-main/kraken/contrib/heatmap_overlay.py | #! /usr/bin/env python
"""
Produces semi-transparent neural segmenter output overlays
"""
import click
@click.command()
@click.option('-i', '--model', default=None, show_default=True, type=click.Path(exists=True),
help='Baseline detection model to use.')
@click.argument('files', nargs=-1)
def cli(model,... | 1,903 | 31.271186 | 98 | py |
kraken | kraken-main/kraken/contrib/recognition_boxes.py | #!/usr/bin/env python
"""
Draws transparent character bounding boxes over images giving a legacy
segmenter model.
"""
import os
import sys
from PIL import Image, ImageDraw
from kraken.pageseg import segment
from kraken.binarization import nlbin
from kraken.rpred import rpred
from itertools import cycle
from kraken.l... | 1,081 | 24.761905 | 70 | py |
kraken | kraken-main/kraken/contrib/print_word_spreader.py | #!/usr/bin/env python
#2020, Bruce Robertson
#Master file at https://github.com/brobertson/Lace2-tools/blob/master/normalize_hocr.py
import html, os, sys, argparse
from statistics import mean
from lxml import etree
from PIL import Image
#a custom exception to indicate when a page or other element doesn't
#have a bound... | 13,880 | 49.111913 | 344 | py |
kraken | kraken-main/kraken/contrib/repolygonize.py | #!/usr/bin/env python
"""
Reads in a bunch of ALTO documents and repolygonizes the lines contained with
the kraken polygonizer.
"""
import click
@click.command()
@click.option('-f', '--format-type', type=click.Choice(['alto', 'page']), default='alto',
help='Sets the input document format. In ALTO and Pa... | 4,374 | 38.0625 | 113 | py |
kraken | kraken-main/kraken/contrib/segmentation_overlay.py | #!/usr/bin/env python
"""
Draws a transparent overlay of baseline segmenter output over a list of image
files.
"""
import re
import os
import click
import unicodedata
from itertools import cycle
from collections import defaultdict
cmap = cycle([(230, 25, 75, 127),
(60, 180, 75, 127)])
bmap = (0, 130, 20... | 6,737 | 43.622517 | 124 | py |
kraken | kraken-main/kraken/contrib/generate_scripts.py | #!/usr/bin/env python3
"""
Script fetching the latest unicode Scripts.txt and dumping it as json.
"""
from urllib import request
import json
import regex
uri = 'http://www.unicode.org/Public/UNIDATA/Scripts.txt'
re = regex.compile(r'^(?P<start>[0-9A-F]{4,6})(..(?P<end>[0-9A-F]{4,6}))?\s+; (?P<name>[A-Za-z]+)')
with ... | 1,125 | 33.121212 | 100 | py |
kraken | kraken-main/kraken/contrib/forced_alignment_overlay.py | #!/usr/bin/env python
"""
Draws a transparent overlay of the forced alignment output over the input
image.
"""
import re
import os
import click
import unicodedata
from lxml import etree
from itertools import cycle
from unicodedata import normalize
cmap = cycle([(230, 25, 75, 127),
(60, 180, 75, 127),
... | 5,190 | 36.345324 | 108 | py |
kraken | kraken-main/kraken/contrib/set_seg_options.py | #!/usr/bin/env python
"""
A script setting the metadata of segmentation models.
"""
import click
import shutil
@click.command()
@click.option('-b', '--bounding-region', multiple=True, help='Sets region identifiers which bound line bounding polygons')
@click.option('--topline/--baseline', default=False, help='Sets mod... | 2,098 | 35.824561 | 140 | py |
kraken | kraken-main/kraken/contrib/extract_lines.py | #! /usr/bin/env python
import click
@click.command()
@click.option('-f', '--format-type', type=click.Choice(['xml', 'alto', 'page', 'binary']), default='xml',
help='Sets the input document format. In ALTO and PageXML mode all '
'data is extracted from xml files containing both baselines, ... | 3,955 | 49.075949 | 150 | py |
kraken | kraken-main/kraken/contrib/baselineset_overlay.py | #! /usr/bin/env python
"""
Produces semi-transparent neural segmenter output overlays
"""
import click
@click.command()
@click.argument('files', nargs=-1)
def cli(files):
import torch
from PIL import Image
from os.path import splitext
import torchvision.transforms as tf
from kraken.lib import dat... | 1,640 | 33.1875 | 100 | py |
kraken | kraken-main/kraken/contrib/hyperparameters/tune_pretraining.py | #!/usr/bin/env python
"""
A script for a grid search over pretraining hyperparameters.
"""
import click
from functools import partial
from ray import tune
from ray.tune.integration.pytorch_lightning import TuneReportCallback
from kraken.lib.default_specs import RECOGNITION_PRETRAIN_HYPER_PARAMS, RECOGNITION_SPEC
fro... | 3,872 | 43.011364 | 142 | py |
kraken | kraken-main/kraken/contrib/hyperparameters/tune_training.py | #!/usr/bin/env python
"""
A script for a grid search over pretraining hyperparameters.
"""
import sys
from functools import partial
from ray import tune
from ray.tune.integration.pytorch_lightning import TuneReportCallback
from kraken.lib.default_spec import RECOGNITION_PRETRAIN_HYPER_PARAMS, RECOGNITION_SPEC
from k... | 2,190 | 37.438596 | 164 | py |
kraken | kraken-main/kraken/lib/lstm.py | # flake8: noqa
from typing import Dict
from scipy.special import expit
initial_range = 0.1
class Codec(object):
"""Translate between integer codes and characters."""
def init(self, charset):
charset = sorted(list(set(charset)))
self.code2char = {} # type: Dict[int, str]
self.char2cod... | 3,744 | 28.488189 | 82 | py |
kraken | kraken-main/kraken/lib/exceptions.py | """
kraken.lib.exceptions
~~~~~~~~~~~~~~~~~~~~~
All custom exceptions raised by kraken's modules and packages. Packages should
always define their exceptions here.
"""
class KrakenCodecException(Exception):
def __init__(self, message=None):
Exception.__init__(self, message)
class KrakenStopTrainingExc... | 1,521 | 21.382353 | 78 | py |
kraken | kraken-main/kraken/lib/xml.py | #
# Copyright 2019 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 19,114 | 38.906054 | 121 | py |
kraken | kraken-main/kraken/lib/codec.py | #
# Copyright 2017 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 11,105 | 40.909434 | 135 | py |
kraken | kraken-main/kraken/lib/progress.py | # Copyright Benjamin Kiessling
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required b... | 6,470 | 39.698113 | 135 | py |
kraken | kraken-main/kraken/lib/ctc_decoder.py | #
# Copyright 2017 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 6,701 | 39.131737 | 113 | py |
kraken | kraken-main/kraken/lib/vgsl.py | """
VGSL plumbing
"""
import re
import json
import torch
import logging
import warnings
from torch import nn
from os import PathLike
from typing import Sequence, List, Tuple, Union, Optional, Iterable, Callable, Dict, Any
from kraken.lib import layers
from kraken.lib.codec import PytorchCodec
from kraken.lib.exceptio... | 35,478 | 43.740227 | 181 | py |
kraken | kraken-main/kraken/lib/morph.py | """
Various add-ons to the SciPy morphology package
"""
import numpy as np
from scipy.ndimage import label as _label
from scipy.ndimage import distance_transform_edt
from scipy.ndimage import find_objects as _find_objects
from scipy.ndimage import filters
def label(image: np.ndarray, **kw) -> np.ndarray:
"""
... | 4,601 | 32.591241 | 79 | py |
kraken | kraken-main/kraken/lib/lineest.py | import warnings
from PIL import Image
import numpy as np
from kraken.lib.util import pil2array, array2pil
from scipy.ndimage import affine_transform, gaussian_filter, uniform_filter
__all__ = ['CenterNormalizer', 'dewarp']
def scale_to_h(img, target_height, order=1, dtype=np.dtype('f'), cval=0):
h, w = img.shap... | 3,119 | 35.705882 | 79 | py |
kraken | kraken-main/kraken/lib/segmentation.py | #
# Copyright 2019 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 45,374 | 41.052827 | 152 | py |
kraken | kraken-main/kraken/lib/log.py | #
# Copyright 2018 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 848 | 28.275862 | 69 | py |
kraken | kraken-main/kraken/lib/arrow_dataset.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 13,976 | 43.942122 | 112 | py |
kraken | kraken-main/kraken/lib/default_specs.py | #
# Copyright 2020 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 5,152 | 45.845455 | 178 | py |
kraken | kraken-main/kraken/lib/layers.py | """
Layers for VGSL models
"""
import torch
import numpy as np
from typing import List, Tuple, Optional, Iterable
from torch.nn import Module, Sequential
from torch.nn import functional as F
from torch.nn.utils.rnn import pad_packed_sequence, pack_padded_sequence
from coremltools.proto import NeuralNetwork_pb2
# all ... | 41,375 | 42.416579 | 200 | py |
kraken | kraken-main/kraken/lib/util.py | """
Ocropus's magic PIL-numpy array conversion routines. They express slightly
different behavior from PIL.Image.toarray().
"""
import torch
import unicodedata
import numpy as np
from PIL import Image
from typing import Union
__all__ = ['pil2array', 'array2pil', 'is_bitonal', 'make_printable', 'get_im_str']
def pi... | 2,723 | 27.375 | 82 | py |
kraken | kraken-main/kraken/lib/models.py | """
kraken.lib.models
~~~~~~~~~~~~~~~~~
Wrapper around TorchVGSLModel including a variety of forward pass helpers for
sequence classification.
"""
from os import PathLike
from os.path import expandvars, expanduser, abspath
import torch
import numpy as np
import kraken.lib.lineest
import kraken.lib.ctc_decoder
from t... | 8,040 | 35.058296 | 122 | py |
kraken | kraken-main/kraken/lib/functional_im_transforms.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 2,764 | 25.84466 | 108 | py |
kraken | kraken-main/kraken/lib/__init__.py | 0 | 0 | 0 | py | |
kraken | kraken-main/kraken/lib/train.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 57,490 | 49.742277 | 171 | py |
kraken | kraken-main/kraken/lib/sl.py | import numpy as np
def dim0(s):
"""Dimension of the slice list for dimension 0."""
return s[0].stop-s[0].start
def dim1(s):
"""Dimension of the slice list for dimension 1."""
return s[1].stop-s[1].start
def area(a):
"""Return the area of the slice list (ignores anything past a[:2]."""
retu... | 697 | 16.02439 | 73 | py |
kraken | kraken-main/kraken/lib/dataset/utils.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 12,846 | 34.00545 | 128 | py |
kraken | kraken-main/kraken/lib/dataset/segmentation.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 14,843 | 44.673846 | 137 | py |
kraken | kraken-main/kraken/lib/dataset/__init__.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 910 | 42.380952 | 99 | py |
kraken | kraken-main/kraken/lib/dataset/recognition.py | #
# Copyright 2015 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 23,940 | 40.277586 | 137 | py |
kraken | kraken-main/kraken/lib/pretrain/model.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 21,793 | 44.404167 | 133 | py |
kraken | kraken-main/kraken/lib/pretrain/layers.py | """
Layers for VGSL models
"""
import torch
from typing import Tuple, Optional
from torch.nn import Module, Embedding, Linear
from kraken.lib.vgsl import VGSLBlock
from kraken.lib.pretrain.util import compute_mask_indices, sample_negatives
# all tensors are ordered NCHW, the "feature" dimension is C, so the output o... | 5,457 | 41.640625 | 157 | py |
kraken | kraken-main/kraken/lib/pretrain/util.py | # Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Sequence, Union, Tuple
import torch
import random
import numpy as np
def positive_integers_with_sum(n, total):
ls = ... | 5,805 | 33.975904 | 128 | py |
kraken | kraken-main/kraken/lib/pretrain/__init__.py | #
# Copyright 2022 Benjamin Kiessling
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | 718 | 34.95 | 70 | py |
kraken | kraken-main/tests/test_layers.py | # -*- coding: utf-8 -*-
import unittest
import torch
from kraken.lib import layers
class TestLayers(unittest.TestCase):
"""
Testing custom layer implementations.
"""
def setUp(self):
torch.set_grad_enabled(False)
def test_maxpool(self):
"""
Test maximum pooling layer.
... | 9,708 | 33.675 | 88 | py |
kraken | kraken-main/tests/test_transcribe.py | # -*- coding: utf-8 -*-
import os
import json
import unittest
from PIL import Image
from io import BytesIO
from lxml import etree
from pathlib import Path
from kraken.transcribe import TranscriptionInterface
thisfile = Path(__file__).resolve().parent
resources = thisfile / 'resources'
class TestTranscriptionInterfa... | 924 | 25.428571 | 77 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.