Skip to content

Commit

Permalink
update codebase to 1.0 and 1.x (continue #27) (#31)
Browse files Browse the repository at this point in the history
* add Project.toml

* update test for cache and minor fix

* update test for rotation and minor fix

* update flipdm to reverse

JuliaLang/julia#26369

* update test for crop and minor fix

* update test for resize

* update test for scale and minor fix

* update test for zoom and minor fix

* WIP: update test for distortion and minor fix

* update test for either and minor fix

* fix pipeline test

* update summary reference for distortedview

* WIP: fix tests for augment and operations

* drop julia 0.7 and update CI

* use FileIO v1.1.0

JuliaIO/FileIO.jl#245

* add 1.x tests to CI

* revert back unnecessary changes

* test windows in travis

* fix randomly failed test cases for inacuraccy reasons

* update to julia 1.1

* maybe_copy doesn't explain its usage
* replace Slice by OffsetArrays.IdentityUnitRange

JuliaArrays/OffsetArrays.jl#62

* update to julia 1.2 -- part I

* WIP: update to julia 1.2 -- part II

detect some type instable test cases, only the outmost wrapper is
instable here

* unify how types are displayed

Only meta operations such as Either, Pipeline doesn't have Agumentor
prefix

* add more test versions

* move safe_rand to compat.jl

rand is thread-safe in julia 1.3

* don't allow failures for julia 1.3

* fix commit "WIP: update 1.0"

* use explicit and intuitive CartesianIndex(1, 1)

* add method specialization for tweight

* allow FileIO 1.2

* fix type instability for Either

* update reference for FixedPointNumbers v0.7

* try: relax equality check for scale

* restore test cases in tst_scale.jl

* Revert "add method specialization for tweight"

This reverts commit a698382.

* Augmentor v0.6.0-pre
  • Loading branch information
johnnychen94 committed Jan 29, 2020
1 parent 1b0348e commit 7a30087
Show file tree
Hide file tree
Showing 38 changed files with 285 additions and 236 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
_build/
_static/
_templates
/Manifest.toml
18 changes: 4 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ language: julia
os:
- linux
- osx
- windows
julia:
- 0.7
- 1.0
- 1.1
- 1.2
- 1.3
- nightly
notifications:
email: false
Expand All @@ -18,14 +21,6 @@ matrix:
allow_failures:
- julia: nightly

## uncomment and modify the following lines to manually install system packages
#addons:
# apt: # apt-get for linux
# packages:
# - gfortran
#before_script: # homebrew for mac
# - if [ $TRAVIS_OS_NAME = osx ]; then brew install gcc; fi

#jobs:
# include:
# - stage: deploy
Expand All @@ -36,10 +31,5 @@ matrix:
# - julia -e 'import Pkg; Pkg.add("Documenter")'
# - julia -e 'import Augmentor; ENV["DOCUMENTER_DEBUG"] = "true"; include(joinpath("docs","make.jl"))'

## uncomment the following lines to override the default test script
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --check-bounds=yes --color=yes -e 'import Pkg; Pkg.clone(pwd()); Pkg.build("Augmentor"); Pkg.test("Augmentor"; coverage=true)';

after_success:
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'
49 changes: 49 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name = "Augmentor"
uuid = "02898b10-1f73-11ea-317c-6393d7073e15"
authors = ["Christof Stocker <stocker.christof@gmail.com>"]
version = "0.6.0-pre"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
ComputationalResources = "ed09eef8-17a6-5b46-8889-db040fac31e3"
CoordinateTransformations = "150eb455-5306-5404-9cee-2592286d6298"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
IdentityRanges = "bbac6d45-d8f3-5730-bfe4-7a449cd117ca"
ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534"
ImageFiltering = "6a3955dd-da59-5b1f-98d4-e7296123deb5"
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MLDataPattern = "9920b226-0b2a-5f5f-9153-9aa70a013f8b"
MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
ColorTypes = "0.7, 0.8"
ComputationalResources = "0.3"
CoordinateTransformations = "0.5"
FileIO = "1"
IdentityRanges = "0.3"
ImageCore = "0.8.1"
ImageFiltering = "0.4, 0.5, 0.6"
ImageTransformations = "0.5, 0.6, 0.7, 0.8"
Interpolations = "0.8, 0.9, 0.10, 0.11, 0.12"
MLDataPattern = "0.4, 0.5"
MappedArrays = "0.1, 0.2"
OffsetArrays = "0.8, 0.9, 0.10, 0.11"
Rotations = "0.7, 0.8, 0.9, 0.10, 0.11, 0.12"
StaticArrays = "0.8, 0.9, 0.10, 0.11, 0.12"
julia = "1"

[extras]
ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

[targets]
test = ["ImageInTerminal", "ImageMagick", "ReferenceTests", "Statistics", "TestImages", "Test"]
15 changes: 0 additions & 15 deletions REQUIRE

This file was deleted.

37 changes: 0 additions & 37 deletions appveyor.yml

This file was deleted.

14 changes: 12 additions & 2 deletions src/Augmentor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ using CoordinateTransformations
using Rotations
using Interpolations
using StaticArrays
using OffsetArrays
using IdentityRanges
using MLDataPattern
using ComputationalResources
using FileIO
using Base.PermutedDimsArrays: PermutedDimsArray
using LinearAlgebra
using OffsetArrays

# axes(::OffsetArray) changes from Base.Slice to Base.IdentityUnitRange in julia 1.1
# https://github.com/JuliaArrays/OffsetArrays.jl/pull/62
# TODO: switch to Base.IdentityUnitRange when we decide to drop 1.0 compatibility
using OffsetArrays: IdentityUnitRange

export

Expand Down Expand Up @@ -67,6 +73,7 @@ export

testpattern

include("compat.jl")
include("utils.jl")
include("types.jl")
include("operation.jl")
Expand Down Expand Up @@ -97,7 +104,10 @@ include("augment.jl")
include("augmentbatch.jl")

function __init__()
rand_mutex[] = Threads.Mutex()
if VERSION < v"1.3"
# see compat.jl
rand_mutex[] = Threads.Mutex()
end
end

end # module
4 changes: 2 additions & 2 deletions src/augment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ augment!(out, img, op::Operation) = augment!(out, img, (op,))

function augment!(out::AbstractArray, img::AbstractArray, pipeline::AbstractPipeline)
out_lazy = _augment_avoid_eager(img, pipeline)
copy!(match_idx(out, axes(out_lazy)), out_lazy)
copyto!(match_idx(out, axes(out_lazy)), out_lazy)
out
end

function augment!(outs::NTuple{N,AbstractArray}, imgs::NTuple{N,AbstractArray}, pipeline::AbstractPipeline) where N
outs_lazy = _augment_avoid_eager(imgs, pipeline)
map(outs, outs_lazy) do out, out_lazy
copy!(match_idx(out, axes(out_lazy)), out_lazy)
copyto!(match_idx(out, axes(out_lazy)), out_lazy)
end
outs
end
Expand Down
22 changes: 22 additions & 0 deletions src/compat.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if VERSION >= v"1.3"
const safe_rand = rand
else
# rand is thread safe after julia 1.3
# TODO: delete this when we decide to drop 1.0 compatibility

# --------------------------------------------------------------------
# rand() is not threadsafe (https://discourse.julialang.org/t/4683)

# Because we only require random numbers to sample parameters
# and not the actual expensive computation, this seems like a better
# approach than using separate RNG per thread.
const rand_mutex = Ref{Threads.Mutex}()

# constant overhead of about 80 ns compared to unsafe rand
function safe_rand(args...)
lock(rand_mutex[])
result = rand(args...)
unlock(rand_mutex[])
result
end
end
13 changes: 8 additions & 5 deletions src/distortedview.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ struct DistortedView{T,P<:AbstractMatrix,E<:AbstractExtrapolation,G,D} <: Abstra

function DistortedView(parent::AbstractMatrix{T}, grid::AbstractArray{Float64,3}) where T
@assert size(grid,1) == 2
# to compare two DistortedViews, their `axes` should be the same
parent = plain_axes(parent)
etp = ImageTransformations.box_extrapolation(parent, Flat())
field = ImageTransformations.box_extrapolation(grid, 0.0)
new{T,typeof(parent),typeof(etp),typeof(grid),typeof(field)}(parent, etp, grid, field)
end
end

Base.parent(A::DistortedView) = A.parent
Base.size(A::DistortedView) = map(length, axes(A.parent))
Base.size(A::DistortedView) = map(length, axes(A))
Base.axes(A::DistortedView) = axes(A.parent)

function Base.showarg(io::IO, A::DistortedView, toplevel)
print(io, typeof(A).name, '(')
Expand All @@ -22,7 +25,7 @@ function Base.showarg(io::IO, A::DistortedView, toplevel)
Base.showarg(io, A.grid, false)
print(io, " as ", size(A.field,2), '×', size(A.field,3), " vector field")
print(io, ')')
toplevel && print(io, " with eltype ", eltype(v))
toplevel && print(io, " with eltype ", eltype(A))
end

# inline speeds up ~30%
Expand All @@ -39,8 +42,8 @@ end
# map array indices to grid indices
gi, gj = (i-1)/(leny-1)*(gh-1)+1, (j-1)/(lenx-1)*(gw-1)+1
# compute parent indices offset
@inbounds dy = field[1, gi, gj] * leny
@inbounds dx = field[2, gi, gj] * lenx
@inbounds dy = field(1, gi, gj) * leny
@inbounds dx = field(2, gi, gj) * lenx
# compute parent indices and return value
# Note: we subtract instead of add, because the vector field is
# specified in forward mode (i.e. in reference to the source
Expand All @@ -50,6 +53,6 @@ end
checkbounds(indsx, j)
@inbounds y = indsy[i] - dy
@inbounds x = indsx[j] - dx
@inbounds res = etp[y, x]
@inbounds res = etp(y, x)
res
end
6 changes: 4 additions & 2 deletions src/operation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ for FUN in (:applyeager, :applylazy, :applypermute,
end

function applyeager(op::Operation, img::AbstractArray, param)
maybe_copy(applylazy(op, img, param))
# TODO: we don't need wrappers for eager mode, so we might want to
# add plain_array to it as well for the sake of simplicity
contiguous(applylazy(op, img, param))
end

function applyaffineview(op::Operation, img::AbstractArray, param)
Expand Down Expand Up @@ -116,7 +118,7 @@ end
@generated function toaffinemap_common(op::AffineOperation, img::AbstractArray{T,N}, param) where {T,N}
quote
tfm = toaffinemap(op, img, param)
AffineMap(SMatrix(tfm.m), SVector(tfm.v))::AffineMap{SArray{Tuple{$N,$N},Float64,$N,$(N*N)},SVector{$N,Float64}}
AffineMap(SMatrix(tfm.linear), SVector(tfm.translation))::AffineMap{SArray{Tuple{$N,$N},Float64,$N,$(N*N)},SVector{$N,Float64}}
end
end

Expand Down
10 changes: 5 additions & 5 deletions src/operations/cache.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pl = ElasticDistortion(3,3) |> zeros(20,20) |> Rotate(-10:10)
"""
struct CacheImage <: ImageOperation end

applyeager(op::CacheImage, img::AbstractArray, param) = maybe_copy(img)
applyeager(op::CacheImage, img::AbstractArray, param) = contiguous(img)

function showconstruction(io::IO, op::CacheImage)
print(io, typeof(op).name.name, "()")
Expand Down Expand Up @@ -92,12 +92,12 @@ function applylazy(op::CacheImageInto, img::Tuple)
end

function applylazy(op::CacheImageInto{<:AbstractArray}, img::AbstractArray, param)
copy!(match_idx(op.buffer, axes(img)), img)
copyto!(match_idx(op.buffer, axes(img)), img)
end

function applylazy(op::CacheImageInto{<:Tuple}, imgs::Tuple)
map(op.buffer, imgs) do buffer, img
copy!(match_idx(buffer, axes(img)), img)
copyto!(match_idx(buffer, axes(img)), img)
end
end

Expand Down Expand Up @@ -130,7 +130,7 @@ function Base.show(io::IO, op::CacheImageInto{<:AbstractArray})
print(io, summary(op.buffer))
else
print(io, typeof(op).name, "(")
showarg(io, op.buffer)
Base.showarg(io, op.buffer, false)
print(io, ")")
end
end
Expand All @@ -142,7 +142,7 @@ function Base.show(io::IO, op::CacheImageInto{<:Tuple})
else
print(io, typeof(op).name, "((")
for (i, buffer) in enumerate(op.buffer)
showarg(io, buffer)
Base.showarg(io, buffer, false)
i < length(op.buffer) && print(io, ", ")
end
print(io, "))")
Expand Down
2 changes: 1 addition & 1 deletion src/operations/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ end
@inline supports_lazy(::Type{<:ConvertEltype}) = true

function applyeager(op::ConvertEltype{T}, img::AbstractArray, param) where T
maybe_copy(convert(AbstractArray{T}, img))
contiguous(convert(AbstractArray{T}, img))
end

function applylazy(op::ConvertEltype{T}, img::AbstractArray, param) where T
Expand Down
Loading

0 comments on commit 7a30087

Please sign in to comment.