This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reduce_mem_usage(props): | |
""" | |
Code seen on https://www.kaggle.com/jesucristo/fraud-complete-eda | |
to reduce memory usage of a dataframe by using the write | |
dtype for each variable. | |
/!\ Be careful with it's usage, dat could be broken after /!\ | |
NaN value are replaced by -1 | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_pdf_without_text(pdf: fitz.Document) -> fitz.Document: | |
for i in range(0, pdf.pageCount): | |
page = pdf[i] | |
for xref in page._getContents(): | |
stream = pdf._getXrefStream(xref).replace(b'Tm', b'Tm\n3 Tr') | |
pdf._updateStream(xref, stream) | |
return pdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## GridMask augmentation for imgaug | |
## | |
## Code based on this kernel https://www.kaggle.com/shivyshiv/efficientnet-gridmask-training-pytorch | |
from imgaug.augmenters import meta | |
from imgaug import parameters as iap | |
import imgaug.augmenters as iaa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import numpy as np | |
from PIL import Image, ImageEnhance, ImageOps | |
class ImageNetPolicy(object): | |
def __init__(self, fillcolor=(128, 128, 128)): | |
self.policies = [ | |
SubPolicy(0.4, "posterize", 8, 0.6, "rotate", 9, fillcolor), |