diff --git a/NEWS.md b/NEWS.md index b727d1d8..d9602f2d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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: diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl index 7f1bf7a7..e0cfc993 100644 --- a/benchmark/benchmarks.jl +++ b/benchmark/benchmarks.jl @@ -1,5 +1,7 @@ +using BenchmarkTools using Augmentor, Images, TestImages -using PkgBenchmark + +const SUITE = BenchmarkGroup() pattern = testpattern() affpattern = Augmentor.prepareaffine(pattern) @@ -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) diff --git a/src/operations/crop.jl b/src/operations/crop.jl index f301a5ed..7fd9fd3f 100644 --- a/src/operations/crop.jl +++ b/src/operations/crop.jl @@ -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 @@ -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 diff --git a/test/operations/tst_crop.jl b/test/operations/tst_crop.jl index bfa5820a..aa375c60 100644 --- a/test/operations/tst_crop.jl +++ b/test/operations/tst_crop.jl @@ -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,))" @@ -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,))" diff --git a/test/runtests.jl b/test/runtests.jl index aa95aea0..30e79eac 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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)