Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified snapshots/augmentations/RandomRotate-bboxes.npy
Binary file not shown.
Binary file added snapshots/augmentations/RandomScale-bboxes.npy
Binary file not shown.
Binary file added snapshots/augmentations/RandomScale-image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added snapshots/augmentations/RandomShear-bboxes.npy
Binary file not shown.
Binary file added snapshots/augmentations/RandomShear-image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified snapshots/augmentations/Rotate-bboxes.npy
Binary file not shown.
Binary file modified snapshots/augmentations/Sequence-bboxes.npy
Binary file not shown.
100 changes: 50 additions & 50 deletions snapshots/run/aug_annotations.csv
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,46 @@ wheat1.jpg,0.427734,0.478516,0.53418,0.547852,1
wheat1.jpg,0.422852,0.647461,0.49707,0.711914,1
wheat1.jpg,0.461914,0.570312,0.611328,0.772461,1
wheat1.jpg,0.196289,0.777344,0.291992,0.966797,1
wheat1--1.jpg,0.1260154787957771,0.7355350322900526,0.18590317112581758,0.867874005492773,1
wheat1--1.jpg,0.1903355886823708,0.8260583126226958,0.29379566726560963,0.8875897903337371,1
wheat1--1.jpg,0.1426463787640624,0.4764248776469007,0.2246049888497339,0.5891361411820769,1
wheat1--1.jpg,0.1260154787957771,0.7355350322900526,0.18590317112581758,0.8678740054927732,1
wheat1--1.jpg,0.1903355886823708,0.8260583126226959,0.29379566726560963,0.887589790333737,1
wheat1--1.jpg,0.1426463787640624,0.4764248776469007,0.2246049888497339,0.5891361411820768,1
wheat1--1.jpg,0.09179597922942345,0.03352682741081094,0.21951247152051798,0.15095348037495876,1
wheat1--1.jpg,0.13035809275454543,0.13868151357451097,0.258094525756085,0.2306869527026658,1
wheat1--1.jpg,0.2234353693846658,0.1792380303124485,0.3443854910747047,0.24421635131913028,1
wheat1--1.jpg,0.18779779658567256,0.012966265921597612,0.2660309237130814,0.09986335308909369,1
wheat1--1.jpg,0.22559616178938902,0.016502767755508282,0.2721848450657655,0.05636305076130831,1
wheat1--1.jpg,0.13035809275454543,0.13868151357451097,0.25809452575608505,0.23068695270266582,1
wheat1--1.jpg,0.2234353693846658,0.1792380303124485,0.3443854910747047,0.24421635131913033,1
wheat1--1.jpg,0.18779779658567256,0.012966265921597612,0.2660309237130814,0.0998633530890937,1
wheat1--1.jpg,0.22559616178938902,0.016502767755508282,0.2721848450657655,0.05636305076130832,1
wheat1--1.jpg,0.4578205654136664,0.05133075470572648,0.5449038175622122,0.12077842936798783,1
wheat1--1.jpg,0.35974219900394394,0.041507093791732265,0.477945378628784,0.1517811657577691,1
wheat1--1.jpg,0.38163447485612184,0.22139882028834573,0.4389517273763313,0.2903980085150183,1
wheat1--1.jpg,0.38163447485612184,0.22139882028834573,0.4389517273763313,0.29039800851501824,1
wheat1--1.jpg,0.42935580982049537,0.2859064262248102,0.5185546431205136,0.35379336507763776,1
wheat1--1.jpg,0.6624469851493254,0.1918191019996222,0.774359216106334,0.2901014580486078,1
wheat1--1.jpg,0.6624469851493254,0.19181910199962215,0.774359216106334,0.2901014580486078,1
wheat1--1.jpg,0.6195288843101181,0.12934465846596535,0.6911722557073189,0.19190884101352837,1
wheat1--1.jpg,0.7784530669182361,0.07371595562208667,0.8561906869330828,0.14655486920045072,1
wheat1--1.jpg,0.5036951059500646,0.3897583988278445,0.5803928288738859,0.4677508656358801,1
wheat1--1.jpg,0.5795561646183348,0.3793819095147949,0.6844241724845882,0.5242064144974741,1
wheat1--1.jpg,0.5036951059500646,0.38975839882784447,0.5803928288738859,0.4677508656358801,1
wheat1--1.jpg,0.5795561646183348,0.37938190951479484,0.6844241724845882,0.5242064144974741,1
wheat1--1.jpg,0.6631497330635221,0.39997415011546417,0.7262989811417356,0.4756533317956014,1
wheat1--1.jpg,0.7852217814597716,0.30054363294917574,0.8660301427750743,0.3911908674057296,1
wheat1--1.jpg,0.7944603128486755,0.5807184071037012,0.8886770210347533,0.6543090306354349,1
wheat1--1.jpg,0.15210664644006763,0.3988688303234419,0.24916000773364852,0.47980333840520223,1
wheat1--1.jpg,0.7944603128486755,0.580718407103701,0.8886770210347533,0.6543090306354349,1
wheat1--1.jpg,0.15210664644006763,0.3988688303234419,0.24916000773364852,0.4798033384052023,1
wheat1--1.jpg,0.17794374055076584,0.3098036881528888,0.2845669092237807,0.3812160145223128,1
wheat1--1.jpg,0.2963629207744901,0.4520347524896124,0.37446492137207793,0.5371344708684405,1
wheat1--1.jpg,0.3142715450585308,0.526951190374702,0.3821861731860326,0.6232909951928478,1
wheat1--1.jpg,0.2483988351854908,0.5899442144044432,0.33744264100721294,0.7410456363079533,1
wheat1--1.jpg,0.2753652809113054,0.5847675603820816,0.39352781208194215,0.7458839795444681,1
wheat1--1.jpg,0.3767675060226752,0.6002163617540263,0.4638384964147733,0.7116813077905,1
wheat1--1.jpg,0.46253521743897114,0.5734009838203047,0.5499622095332191,0.680531516484118,1
wheat1--1.jpg,0.4077123402199251,0.4043452669140079,0.5197433688435875,0.5464413432851428,1
wheat1--1.jpg,0.2483988351854908,0.5899442144044432,0.33744264100721294,0.7410456363079534,1
wheat1--1.jpg,0.27536528091130547,0.5847675603820816,0.39352781208194215,0.7458839795444682,1
wheat1--1.jpg,0.3767675060226752,0.6002163617540263,0.4638384964147733,0.7116813077904999,1
wheat1--1.jpg,0.46253521743897114,0.5734009838203048,0.5499622095332191,0.680531516484118,1
wheat1--1.jpg,0.4077123402199251,0.40434526691400785,0.5197433688435875,0.5464413432851428,1
wheat1--1.jpg,0.5496155901927392,0.5192108546607421,0.6160038826683845,0.6242194862242089,1
wheat1--1.jpg,0.6039786249052156,0.508778921919427,0.6837187695384565,0.6134057052685209,1
wheat1--1.jpg,0.6134675287677246,0.6307885600281758,0.7672693932500452,0.7491693408149234,1
wheat1--1.jpg,0.6039786249052156,0.5087789219194269,0.6837187695384565,0.613405705268521,1
wheat1--1.jpg,0.6134675287677246,0.6307885600281757,0.7672693932500452,0.7491693408149234,1
wheat1--1.jpg,0.7674247470131037,0.7011894903549754,0.888240728690804,0.9607130441656498,1
wheat1--1.jpg,0.6933977927426337,0.7297671021266293,0.8173891262665578,0.9571542332214744,1
wheat1--1.jpg,0.4873919555120191,0.8442893698766332,0.54059871410964,0.8996565618394977,1
wheat1--1.jpg,0.3699029314143875,0.8421461122997198,0.4466380424809759,0.9288860305496682,1
wheat1--1.jpg,0.3699029314143875,0.8421461122997197,0.4466380424809759,0.9288860305496682,1
wheat1--1.jpg,0.13844774317775665,0.7593612952066074,0.21201069560283814,0.8186469176933916,1
wheat1--1.jpg,0.4372867186057866,0.474422489404521,0.5349879096364903,0.5467668759131885,1
wheat1--1.jpg,0.4477766990369346,0.6294320996726979,0.5204302583363911,0.6946913350868958,1
wheat1--1.jpg,0.4630891245587028,0.5616108464073888,0.6238334861619451,0.7595799170796714,1
wheat1--1.jpg,0.4477766990369346,0.6294320996726979,0.5204302583363911,0.694691335086896,1
wheat1--1.jpg,0.4630891245587028,0.5616108464073887,0.6238334861619451,0.7595799170796714,1
wheat1--1.jpg,0.27399194570513924,0.7306709717866631,0.3902431973663129,0.9126393176389738,1
wheat1--2.jpg,0.0,0.799805,0.037109,0.94043,1
wheat1--2.jpg,0.064453,0.892578,0.181641,0.949219,1
Expand Down Expand Up @@ -350,65 +350,65 @@ wheat2.jpg,0.012695,0.404297,0.057617,0.453125,1
wheat2--1.jpg,0.37915273563670515,0.8537115704158108,0.45633849829470347,0.9281898445002004,1
wheat2--1.jpg,0.3482011388564143,0.79542456581385,0.4455168305718107,0.8789756630169258,1
wheat2--1.jpg,0.423375425214153,0.8539353775545744,0.4897547162447866,0.9413714818539906,1
wheat2--1.jpg,0.25802627801190314,0.7444822374443413,0.34783173713713994,0.8536450126702309,1
wheat2--1.jpg,0.5456216498936772,0.8352276282822948,0.6557652328496321,0.9131628596632722,1
wheat2--1.jpg,0.25802627801190314,0.7444822374443414,0.34783173713713994,0.8536450126702309,1
wheat2--1.jpg,0.5456216498936772,0.8352276282822947,0.6557652328496321,0.9131628596632722,1
wheat2--1.jpg,0.6359017165031017,0.8303644399369666,0.6852126738628886,0.9099407433471262,1
wheat2--1.jpg,0.5998699993007016,0.8772440274984457,0.6540890353249057,0.9362828225294121,1
wheat2--1.jpg,0.7188771246384915,0.8576375938318318,0.8400969770220114,0.9428039504318758,1
wheat2--1.jpg,0.7188771246384915,0.8576375938318319,0.8400969770220114,0.9428039504318758,1
wheat2--1.jpg,0.13186628896596622,0.7517039926622167,0.19761971338753015,0.8232846350594691,1
wheat2--1.jpg,0.11341506281518,0.46789107166013505,0.17959779826452107,0.5526329624580114,1
wheat2--1.jpg,0.11341506281518,0.46789107166013494,0.17959779826452107,0.5526329624580114,1
wheat2--1.jpg,0.20288659300117284,0.5278174039751548,0.311605957572916,0.6240665976213327,1
wheat2--1.jpg,0.2473079999721169,0.4788714392172312,0.3236131000843344,0.5524509484316507,1
wheat2--1.jpg,0.28570352146221445,0.5425922002495907,0.3757621650953622,0.6377762659480349,1
wheat2--1.jpg,0.32062480668153825,0.6207992323535044,0.393577872969965,0.6983988171054891,1
wheat2--1.jpg,0.36229501475718895,0.5209655104962762,0.4296409606599404,0.5857533196334676,1
wheat2--1.jpg,0.28570352146221445,0.5425922002495905,0.3757621650953622,0.6377762659480349,1
wheat2--1.jpg,0.3206248066815383,0.6207992323535044,0.393577872969965,0.6983988171054891,1
wheat2--1.jpg,0.36229501475718895,0.5209655104962762,0.4296409606599404,0.5857533196334677,1
wheat2--1.jpg,0.2644857012198177,0.3588718627185998,0.34232543850230956,0.44135591181684347,1
wheat2--1.jpg,0.18908762818728123,0.2729066747390748,0.29161837293445003,0.3658329792135226,1
wheat2--1.jpg,0.48166731505630833,0.513272248525758,0.6080900258218723,0.6498320036121177,1
wheat2--1.jpg,0.18908762818728123,0.2729066747390748,0.29161837293445003,0.36583297921352265,1
wheat2--1.jpg,0.48166731505630833,0.513272248525758,0.6080900258218723,0.6498320036121176,1
wheat2--1.jpg,0.5634508421770434,0.6087698126942026,0.6692474168460537,0.7221994104378389,1
wheat2--1.jpg,0.6599647675219747,0.6366374271492536,0.7479894511031491,0.7674721887628098,1
wheat2--1.jpg,0.7205026332172112,0.7366496744005965,0.7818185712762128,0.7910849671754898,1
wheat2--1.jpg,0.7414713409266407,0.6385227429530353,0.8385620903629889,0.7282047024767087,1
wheat2--1.jpg,0.7911910383850607,0.6132467920348503,0.8663541912453272,0.6823356387997928,1
wheat2--1.jpg,0.6866634603899274,0.5403864891869525,0.7714131010286365,0.6341217390418283,1
wheat2--1.jpg,0.6385913740328759,0.37008353494122204,0.7245859133312138,0.4779555830818217,1
wheat2--1.jpg,0.5756418951821806,0.7902563291589818,0.6547106177586058,0.8527086722163159,1
wheat2--1.jpg,0.5756418951821806,0.7902563291589818,0.6547106177586057,0.852708672216316,1
wheat2--1.jpg,0.1440718429019282,0.8401284726872037,0.22321359612164873,0.9210518664516499,1
wheat2--1.jpg,0.39194671278226034,0.7723721610096571,0.48106004210692305,0.8647816293041436,1
wheat2--1.jpg,0.7345612384696345,0.8377287611228293,0.8508205448203073,0.9005176706498872,1
wheat2--1.jpg,0.3331199941082905,0.5098946599255181,0.3858402470383609,0.5687762055633009,1
wheat2--1.jpg,0.10819382031404769,0.3727523025960426,0.15407050018612456,0.42128141234716365,1
wheat2--2.jpg,0.1909503006914619,0.6568560061975816,0.2669008191547544,0.732289830826366,1
wheat2--1.jpg,0.10819382031404769,0.37275230259604253,0.15407050018612456,0.42128141234716365,1
wheat2--2.jpg,0.19095030069146196,0.6568560061975816,0.2669008191547544,0.732289830826366,1
wheat2--2.jpg,0.1937142289380578,0.607967350084723,0.28666904951848415,0.6976502466359817,1
wheat2--2.jpg,0.22099244773709803,0.6781174476547996,0.2930381641135625,0.7555018633984635,1
wheat2--2.jpg,0.13678905897491309,0.536321421672058,0.23204518828234444,0.6363993801661623,1
wheat2--2.jpg,0.22099244773709806,0.6781174476547995,0.2930381641135625,0.7555018633984635,1
wheat2--2.jpg,0.1367890589749131,0.536321421672058,0.23204518828234438,0.6363993801661623,1
wheat2--2.jpg,0.33456545483507705,0.7231732431695332,0.4357904988928118,0.8163041813193903,1
wheat2--2.jpg,0.406887915812858,0.7626516999584256,0.46462935242339964,0.8279705486423372,1
wheat2--2.jpg,0.36202037943054194,0.7732722282827891,0.41757627965625593,0.8300334535456574,1
wheat2--2.jpg,0.4607108912468488,0.8177533260244478,0.5716449857938827,0.9197322170547635,1
wheat2--2.jpg,0.36202037943054194,0.7732722282827892,0.41757627965625593,0.8300334535456574,1
wheat2--2.jpg,0.4607108912468488,0.8177533260244478,0.5716449857938827,0.9197322170547636,1
wheat2--2.jpg,0.045397904756109546,0.48075276035019576,0.11250136833251805,0.549405952738091,1
wheat2--2.jpg,0.17376368602393577,0.30348157476052595,0.24460300302365273,0.379143073638953,1
wheat2--2.jpg,0.2113817589223731,0.38087230434198294,0.3170325382916745,0.48325098333609817,1
wheat2--2.jpg,0.17376368602393577,0.30348157476052595,0.24460300302365268,0.379143073638953,1
wheat2--2.jpg,0.2113817589223731,0.38087230434198294,0.31703253829167455,0.48325098333609806,1
wheat2--2.jpg,0.28055444123989476,0.3717462969856578,0.35610196376329395,0.446605011960392,1
wheat2--2.jpg,0.2702034456854801,0.42833351043282514,0.3618960708187166,0.5212318132952531,1
wheat2--2.jpg,0.26376207983511807,0.49066503893618524,0.3378743952035958,0.565982855687836,1
wheat2--2.jpg,0.2637620798351181,0.4906650389361854,0.3378743952035958,0.565982855687836,1
wheat2--2.jpg,0.3549411169955458,0.45040435939810985,0.42169927880404723,0.5164735373119277,1
wheat2--2.jpg,0.3540403687345237,0.3087348945205257,0.43303562308994054,0.3889358266051341,1
wheat2--2.jpg,0.33526552269559107,0.22278761585761872,0.4351146734115213,0.32022576380720325,1
wheat2--2.jpg,0.42880816940100824,0.5035598100855017,0.5579016872221251,0.635236444387121,1
wheat2--2.jpg,0.4536153499730298,0.5980667436915578,0.561566363729743,0.7079122427261275,1
wheat2--2.jpg,0.4536153499730298,0.598066743691558,0.561566363729743,0.7079122427261275,1
wheat2--2.jpg,0.5091006185845908,0.6602357116008155,0.6086681970819801,0.7706528025467607,1
wheat2--2.jpg,0.5352930379662851,0.7456627786865401,0.5941797641533082,0.8029995997160577,1
wheat2--2.jpg,0.5909652558357136,0.6980464593679195,0.6855868874443538,0.7909460721048975,1
wheat2--2.jpg,0.6515754871149676,0.7054649307042561,0.7251122067167957,0.7774519214945974,1
wheat2--2.jpg,0.5959169283352619,0.6141711955412442,0.6831860260250563,0.7036791822832277,1
wheat2--2.jpg,0.6407437397258029,0.4908337537644992,0.7327255607899236,0.5883263879099762,1
wheat2--2.jpg,0.38776645813146815,0.710253202105314,0.4621068596305638,0.7804604056203831,1
wheat2--2.jpg,0.005231538412126744,0.5390590631533448,0.08514589431495097,0.6193179991765202,1
wheat2--2.jpg,0.6407437397258029,0.4908337537644992,0.7327255607899236,0.5883263879099764,1
wheat2--2.jpg,0.3877664581314682,0.7102532021053141,0.4621068596305638,0.7804604056203831,1
wheat2--2.jpg,0.005231538412126744,0.5390590631533448,0.08514589431495094,0.6193179991765201,1
wheat2--2.jpg,0.23679977017697673,0.6146957039978446,0.32671106262543403,0.7054679177091236,1
wheat2--2.jpg,0.49248316698908945,0.8124133167826983,0.5939367090584176,0.9004342299229677,1
wheat2--2.jpg,0.33874383817233533,0.42994994123481517,0.39315034285189937,0.48590635107188446,1
wheat2--2.jpg,0.2326609654389825,0.2429932533152236,0.27919662272406226,0.2902177181489683,1
wheat2--2.jpg,0.33874383817233533,0.42994994123481517,0.39315034285189937,0.4859063510718846,1
wheat2--2.jpg,0.23266096543898254,0.24299325331522362,0.27919662272406226,0.2902177181489683,1
wheat2--3.jpg,0.307617,0.901367,0.384766,0.975586,1
wheat2--3.jpg,0.275391,0.84082,0.375977,0.922852,1
wheat2--3.jpg,0.366211,0.896484,0.425781,0.986328,1
Expand Down Expand Up @@ -553,8 +553,8 @@ wheat3.jpg,0.859375,0.641602,1.0,0.741211,1
wheat3.jpg,0.720703,0.413086,0.849609,0.490234,1
wheat3.jpg,0.87207,0.12207,1.0,0.181641,1
wheat3.jpg,0.833984,0.948242,0.9375,1.0,1
wheat3--1.jpg,0.785524349971796,0.659172218980763,0.9179881523154363,0.7621135207140872,1
wheat3--1.jpg,0.6593555983430807,0.43781417703456355,0.7772515920249531,0.5191518421245941,1
wheat3--1.jpg,0.785524349971796,0.659172218980763,0.9179881523154363,0.7621135207140873,1
wheat3--1.jpg,0.6593555983430807,0.4378141770345636,0.7772515920249531,0.5191518421245941,1
wheat3--1.jpg,0.7538225168778905,0.18230716244653847,0.8665330222478675,0.24739824278418035,1
wheat3--1.jpg,0.7959133966509837,0.9391888239013733,0.8877445814164957,0.9951284564237372,1
wheat3--2.jpg,0.859375,0.641602,1.0,0.741211,1
Expand Down
47 changes: 47 additions & 0 deletions src/discolight/augmentations/normalize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""Normalize Images: This is extremely important if one decides to train on imagenet weights.
The code is with reference from Albumentations."""
import numpy as np
from discolight.params.params import Params
from .augmentation.types import Augmentation
from .decorators.accepts_probs import accepts_probs


@accepts_probs
class Normalize(Augmentation):

"""Normalize an image. Divide pixel values by 255 = 2**8 - 1, subtract mean per channel and divide by std per channel."""

def __init__(self, mean=, std=, max_pixel_value=255.0):

super().__init__()

self.mean = mean
self.std = std
self.max_pixel_value = max_pixel_value

@staticmethod
def params():
"""Return a Params object describing constructor parameters."""

return (
Params()
.add("mean", "", NumericalRange(), (0.485, 0.456, 0.406))
.add("std", "", NumericalRange(), (0.229, 0.224, 0.225))
# Note to user, it will not make sense to tune max_pixel_value to a too small value.
.add("max_pixel_value", "", NumericalRange(), (0.0, 255.0))
)

def augment_img(self, img, _bboxes):
"""Augment an image."""
mean = np.array(self.mean, dtype=np.float32)
mean *= self.max_pixel_value

std = np.array(self.std, dtype=np.float32)
std *= self.max_pixel_value

denominator = np.reciprocal(std, dtype=np.float32)

img = img.astype(np.float32)
img -= mean
img *= denominator
return img
4 changes: 3 additions & 1 deletion src/discolight/augmentations/randomrotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ def params():
return Params().add(
"angle_range",
"The range from which the random angle will be chosen",
NumericalRange(-360.0, 360.0), (-10.0, 10.0))
NumericalRange(-360.0, 360.0),
(-10.0, 10.0),
)

def augment(self, img, bboxes):
"""Augment an image."""
Expand Down
38 changes: 38 additions & 0 deletions src/discolight/augmentations/randomscale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"""An augmentation to randomly rotate an image."""
import random
from discolight.params.params import Params
from .augmentation.types import Augmentation, NumericalRange
from .scale import Scale
from .decorators.accepts_probs import accepts_probs


@accepts_probs
class RandomScale(Augmentation):

"""Randomly scale the given image."""

def __init__(self, scale_range):
"""Construct a RandomScale augmentation.

You should probably use the augmentation factory or Discolight
library interface to construct augmentations. Only invoke
this constructor directly if you know what you are doing.
"""
super().__init__()

self.scale_range = scale_range

@staticmethod
def params():
"""Return a Params object describing constructor parameters."""
return Params().add("scale_range",
"The scale range should be bigger than -1",
NumericalRange(-1), (0.2, 0.2))

def augment(self, img, bboxes):
"""Augment an image."""
scale_factor_x = random.uniform(*self.scale_range)
scale_factor_y = random.uniform(*self.scale_range)

return Scale(scale_x=scale_factor_x,
scale_y=scale_factor_y).augment(img, bboxes)
35 changes: 35 additions & 0 deletions src/discolight/augmentations/randomshear.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""An augmentation to randomly rotate an image."""
import random
from discolight.params.params import Params
from .augmentation.types import Augmentation, NumericalRange
from .shear import Shear
from .decorators.accepts_probs import accepts_probs


@accepts_probs
class RandomShear(Augmentation):

"""Randomly shear the given image."""

def __init__(self, shear_range):
"""Construct a RandomShear augmentation.

You should probably use the augmentation factory or Discolight
library interface to construct augmentations. Only invoke
this constructor directly if you know what you are doing.
"""
super().__init__()

self.shear_range = shear_range

@staticmethod
def params():
"""Return a Params object describing constructor parameters."""
return Params().add("shear_range", "The shear range has no bounds",
NumericalRange(), (0.2, 0.2))

def augment(self, img, bboxes):
"""Augment an image."""
shear_factor = random.uniform(*self.shear_range)

return Shear(shear_factor=shear_factor).augment(img, bboxes)
Loading