Skip to content

Instantly share code, notes, and snippets.

View ternaus's full-sized avatar

Vladimir Iglovikov ternaus

View GitHub Profile
import numpy as np
import albumentations.augmentations.functional as F
black .
isort
@ternaus
ternaus / gist:a6a11847e3a1b0da41fc84de85476ef5
Last active July 27, 2020 19:09
For medium. Image+mask
import albumentations as A
transform = A.Compose([
A.HorizontalFlip(p=0.5),
A.ShiftScaleRotate(border_mode=cv2.BORDER_CONSTANT,
scale_limit=0.3,
rotate_limit=(10, 30),
p=0.5)
], p=1)
@ternaus
ternaus / gist:02f581143a9ebe4a89c1c690ab6736f9
Last active July 27, 2020 19:09
Medium, multitask, scenario 2
import albumentations as A
transform = A.Compose([
A.HorizontalFlip(p=0.5),
A.GridDistortion(p=0.5),
A.RandomCrop(height=1024, width=1024, p=0.5),
], p=1)
transformed = transform(image=image, masks=[mask, mask2])
@ternaus
ternaus / gist:5a4e47d640f0731850297ba84e4e351e
Last active July 27, 2020 19:10
Medium. Multitask. Scenario 3.
import albumentations as A
transform = A.Compose([A.HorizontalFlip(p=0.5),
A.ShiftScaleRotate(border_mode=cv2.BORDER_CONSTANT, scale_limit=0.3, p=0.5)],
bbox_params=albu.BboxParams(format='pascal_voc', label_fields=['category_ids']),
keypoint_params=albu.KeypointParams(format='xy'),
additional_targets={
"image1": "image",
"bboxes1": "bboxes",
"mask1": "mask",
# https://github.com/ternaus/retinaface/blob/master/retinaface/pre_trained_models.py
from collections import namedtuple
from torch.utils import model_zoo
from retinaface.predict_single import Model
model = namedtuple("model", ["url", "model"])
models = {
"resnet50_2020-07-20": model(
# https://raw.githubusercontent.com/ternaus/retinaface/master/setup.py
import io
import os
import re
import sys
from shutil import rmtree
from typing import Tuple, List
from setuptools import Command, find_packages, setup
@ternaus
ternaus / RandomResizedCrop.py
Last active April 4, 2024 21:45
Example of the application of RandomResizedCrop in Albumentations
import albumentations as A
import cv2
bgr_image = cv2.imread("cat1.jpeg")
image = cv2.cvtColor(bgr_image, cv2.COLOR_BGR2RGB)
transform = A.Compose([A.RandomResizedCrop(size=(512, 512),
scale=(0.08, 1),
ratio=(0.75, 1.33),
interpolation=cv2.INTER_AREA, p=0.5)])