Skip to content

Commit

Permalink
Merge pull request #25 from Evizero/cleanup
Browse files Browse the repository at this point in the history
Misc updates
  • Loading branch information
Evizero committed Jul 9, 2018
2 parents ee8d925 + 1db30c8 commit cae5790
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 113 deletions.
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ New functionality:
processed the same way (even when randomness is involved).
See #23 for more information.

Other changes:

- Remove deprecated `Crop` and `CropNative` constructors.

- Update code for the benchmarks.

# v0.4.0

New operations:
Expand Down
192 changes: 94 additions & 98 deletions benchmark/benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using BenchmarkTools
using Augmentor, Images, TestImages
using PkgBenchmark

const SUITE = BenchmarkGroup()

pattern = testpattern()
affpattern = Augmentor.prepareaffine(pattern)
Expand All @@ -11,111 +13,105 @@ copy!(view(cameras,:,:,2), camera)
# compile the gauss filter (takes a couple seconds)
Augmentor.applyeager(ElasticDistortion(10), pattern)

shortname(op) = typeof(op).name.name
shortname(op) = string(typeof(op).name.name)

# missing: CombineChannels, CacheImageInto
@benchgroup "applyeager" ["eager", "operations"] begin
for op in [
NoOp(),
FlipX(), FlipY(),
ShearX(5), ShearY(5),
Either((Rotate90(), Rotate270()), (1,0)),
Rotate90(), Rotate180(), Rotate270(),
Rotate(45),
Crop(1:100,1:100),
CropNative(1:100,1:100),
CropSize(100,100),
CropRatio(1), RCropRatio(1),
Scale(1.1), Zoom(1.1),
Resize(100,100),
ConvertEltype(Gray),
CacheImage(),
ElasticDistortion(10),
SplitChannels(),
Reshape(400,300),
PermuteDims(2,1),
]
@bench "$(shortname(op))" Augmentor.applyeager($op, $pattern)
end
SUITE["applyeager"] = BenchmarkGroup(["eager", "operations"])
for op in [
NoOp(),
FlipX(), FlipY(),
ShearX(5), ShearY(5),
Either((Rotate90(), Rotate270()), (1,0)),
Rotate90(), Rotate180(), Rotate270(),
Rotate(45),
Crop(1:100,1:100),
CropNative(1:100,1:100),
CropSize(100,100),
CropRatio(1), RCropRatio(1),
Scale(1.1), Zoom(1.1),
Resize(100,100),
ConvertEltype(Gray),
CacheImage(),
ElasticDistortion(10),
SplitChannels(),
Reshape(400,300),
PermuteDims(2,1),
]
SUITE["applyeager"][shortname(op)] = @benchmarkable Augmentor.applyeager($op, $pattern)
end

@benchgroup "applylazy" ["lazy", "operations"] begin
for op in [
NoOp(),
FlipX(), FlipY(),
ShearX(5), ShearY(5),
Either((Rotate90(), Rotate270()), (1,0)),
Rotate90(), Rotate180(), Rotate270(),
Rotate(45),
Crop(1:100,1:100),
CropNative(1:100,1:100),
CropSize(100,100),
CropRatio(1), RCropRatio(1),
Scale(1.1), Zoom(1.1),
Resize(100,100),
ConvertEltype(Gray),
ElasticDistortion(10),
SplitChannels(),
Reshape(400,300),
PermuteDims(2,1),
]
@bench "$(shortname(op))" Augmentor.plain_array(Augmentor.applylazy($op, $pattern))
end
SUITE["applylazy"] = BenchmarkGroup(["lazy", "operations"])
for op in [
NoOp(),
FlipX(), FlipY(),
ShearX(5), ShearY(5),
Either((Rotate90(), Rotate270()), (1,0)),
Rotate90(), Rotate180(), Rotate270(),
Rotate(45),
Crop(1:100,1:100),
CropNative(1:100,1:100),
CropSize(100,100),
CropRatio(1), RCropRatio(1),
Scale(1.1), Zoom(1.1),
Resize(100,100),
ConvertEltype(Gray),
ElasticDistortion(10),
SplitChannels(),
Reshape(400,300),
PermuteDims(2,1),
]
SUITE["applylazy"][shortname(op)] = @benchmarkable Augmentor.plain_array(Augmentor.applylazy($op, $pattern))
end

@benchgroup "applyaffine" ["affine", "lazy", "operations"] begin
for op in [
NoOp(),
FlipX(), FlipY(),
ShearX(5), ShearY(5),
Either((Rotate90(), Rotate270()), (1,0)),
Rotate90(), Rotate180(), Rotate270(),
Rotate(45),
Scale(1.1),
]
@bench "$(shortname(op))" Augmentor.plain_array(Augmentor.applyaffine($op, $affpattern))
end
SUITE["applyaffine"] = BenchmarkGroup(["affine", "lazy", "operations"])
for op in [
NoOp(),
FlipX(), FlipY(),
ShearX(5), ShearY(5),
Either((Rotate90(), Rotate270()), (1,0)),
Rotate90(), Rotate180(), Rotate270(),
Rotate(45),
Scale(1.1),
]
SUITE["applyaffine"][shortname(op)] = @benchmarkable Augmentor.plain_array(Augmentor.applyaffine($op, $affpattern))
end

@benchgroup "applyaffineview" ["affine", "lazy", "operations"] begin
for op in [
NoOp(),
FlipX(), FlipY(),
ShearX(5), ShearY(5),
Either((Rotate90(), Rotate270()), (1,0)),
Rotate90(), Rotate180(), Rotate270(),
Rotate(45),
Crop(1:100,1:100),
CropNative(1:100,1:100),
CropSize(100,100),
CropRatio(1), RCropRatio(1),
Scale(1.1), Zoom(1.1),
Resize(100,100),
]
@bench "$(shortname(op))" Augmentor.plain_array(Augmentor.applyaffineview($op, $affpattern))
end
SUITE["applyaffineview"] = BenchmarkGroup(["affine", "lazy", "operations"])
for op in [
NoOp(),
FlipX(), FlipY(),
ShearX(5), ShearY(5),
Either((Rotate90(), Rotate270()), (1,0)),
Rotate90(), Rotate180(), Rotate270(),
Rotate(45),
Crop(1:100,1:100),
CropNative(1:100,1:100),
CropSize(100,100),
CropRatio(1), RCropRatio(1),
Scale(1.1), Zoom(1.1),
Resize(100,100),
]
SUITE["applyaffineview"][shortname(op)] = @benchmarkable Augmentor.plain_array(Augmentor.applyaffineview($op, $affpattern))
end

@benchgroup "augment" ["-"] begin
pl = ShearX(10)
@bench "affine1" augment($pattern, $pl)
pl = ShearX(10) |> ShearX(-10)
@bench "affine2" augment($pattern, $pl)
pl = ShearX(10) |> ShearX(-10) |> ShearY(10) |> ShearY(-10)
@bench "affine4" augment($pattern, $pl)
pl = Rotate180() |> Rotate90(1)
@bench "lazyrotate" augment($pattern, $pl)
pl = Rotate180() |> Crop(5:200,100:400) |> Rotate90(1) |> Crop(1:250,1:150)
@bench "lazycrop" augment($pattern, $pl)
pl = Resize(100,100) |> Resize(200,400) |> Resize(20,20) |> Resize(100,100)
@bench "resize" augment($pattern, $pl)
end
grp = SUITE["augment"] = BenchmarkGroup(["-"])
pl = ShearX(10)
grp["affine1"] = @benchmarkable augment($pattern, $pl)
pl = ShearX(10) |> ShearX(-10)
grp["affine2"] = @benchmarkable augment($pattern, $pl)
pl = ShearX(10) |> ShearX(-10) |> ShearY(10) |> ShearY(-10)
grp["affine3"] = @benchmarkable augment($pattern, $pl)
pl = Rotate180() |> Rotate90(1)
grp["lazyrotate"] = @benchmarkable augment($pattern, $pl)
pl = Rotate180() |> Crop(5:200,100:400) |> Rotate90(1) |> Crop(1:250,1:150)
grp["lazycrop"] = @benchmarkable augment($pattern, $pl)
pl = Resize(100,100) |> Resize(200,400) |> Resize(20,20) |> Resize(100,100)
grp["resize"] = @benchmarkable augment($pattern, $pl)

@benchgroup "augment!" ["-"] begin
pl = Rotate180() |> Rotate90()
out = similar(pattern, 400, 300)
@bench "lazyrotate" augment!($out, $pattern, $pl)
pl = Resize(100,100) |> Resize(200,400) |> Resize(20,20) |> Resize(100,100)
out = similar(pattern, 100, 100)
@bench "resize" augment!($out, $pattern, $pl)
end
grp = SUITE["augment!"] = BenchmarkGroup(["-"])
pl = Rotate180() |> Rotate90()
out = similar(pattern, 400, 300)
grp["lazyrotate"] = @benchmarkable augment!($out, $pattern, $pl)
pl = Resize(100,100) |> Resize(200,400) |> Resize(20,20) |> Resize(100,100)
out = similar(pattern, 100, 100)
grp["resize"] = @benchmarkable augment!($out, $pattern, $pl)
4 changes: 0 additions & 4 deletions src/operations/crop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ end
Crop(::Tuple{}) = throw(MethodError(Crop, ((),)))
Crop(indexes::Range...) = Crop(indexes)

@deprecate Crop(x, y, width, height) Crop(y:y+height-1, x:x+width-1)

@inline supports_eager(::Type{<:Crop}) = false
@inline supports_affineview(::Type{<:Crop}) = true
@inline supports_view(::Type{<:Crop}) = true
Expand Down Expand Up @@ -164,8 +162,6 @@ end
CropNative(::Tuple{}) = throw(MethodError(CropNative, ((),)))
CropNative(indexes::Range...) = CropNative(indexes)

@deprecate CropNative(x, y, width, height) CropNative(y:y+height-1, x:x+width-1)

@inline supports_eager(::Type{<:CropNative}) = false
@inline supports_affineview(::Type{<:CropNative}) = true
@inline supports_view(::Type{<:CropNative}) = true
Expand Down
2 changes: 0 additions & 2 deletions test/operations/tst_crop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
@test_throws MethodError Crop(())
@test typeof(@inferred(Crop(1:10))) <: Crop{1} <: Crop <: Augmentor.ImageOperation
@test typeof(@inferred(Crop(1:10,3:5))) <: Crop{2} <: Crop <: Augmentor.ImageOperation
@test @inferred(Crop(1,4,10,5)) === @inferred(Crop((4:8,1:10)))
@test @inferred(Crop(Base.OneTo(10), Base.OneTo(5))) === @inferred(Crop((1:10,1:5)))
@test @inferred(Crop(Base.OneTo(10), 1:5)) === @inferred(Crop((1:10,1:5)))
@test str_show(Crop(3:4)) == "Augmentor.Crop{1}((3:4,))"
Expand Down Expand Up @@ -124,7 +123,6 @@ end
@test_throws MethodError CropNative(())
@test typeof(@inferred(CropNative(1:10))) <: CropNative{1} <: CropNative <: Augmentor.ImageOperation
@test typeof(@inferred(CropNative(1:10,3:5))) <: CropNative{2} <: CropNative <: Augmentor.ImageOperation
@test @inferred(CropNative(1,4,10,5)) === @inferred(CropNative((4:8,1:10)))
@test @inferred(CropNative(Base.OneTo(10), Base.OneTo(5))) === @inferred(CropNative((1:10,1:5)))
@test @inferred(CropNative(Base.OneTo(10), 1:5)) === @inferred(CropNative((1:10,1:5)))
@test str_show(CropNative(3:4)) == "Augmentor.CropNative{1}((3:4,))"
Expand Down
10 changes: 1 addition & 9 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
# Things that needs to be tested
# [x] Utility functions work properly and type stable
# [x] Individual operations do what they should
# [x] Individual operations are always type stable
# [x] Lazy Either works correctly and type stable
# [x] Operations accept AbstractArray as input (esp. Array and SubArray)

using ImageCore, ImageFiltering, ImageTransformations, CoordinateTransformations, Interpolations, OffsetArrays, StaticArrays, ColorTypes, FixedPointNumbers, TestImages, IdentityRanges, MappedArrays, ComputationalResources, MLDataPattern, ReferenceTests, Base.Test
using ImageInTerminal
using ImageCore, ImageFiltering, ImageTransformations, CoordinateTransformations, Interpolations, OffsetArrays, StaticArrays, ColorTypes, FixedPointNumbers, TestImages, IdentityRanges, MappedArrays, ComputationalResources, MLDataPattern, ImageInTerminal, ReferenceTests, Base.Test

# check for ambiguities
refambs = detect_ambiguities(ImageTransformations, Base, Core)
Expand Down

0 comments on commit cae5790

Please sign in to comment.