1
1
"""
2
- Upsample(mode = :nearest; [scale, size])
2
+ Upsample(mode = :nearest; [scale, size])
3
+ Upsample(scale, mode = :nearest)
3
4
4
5
An upsampling layer. One of two keywords must be given:
5
6
@@ -16,31 +17,33 @@ and corresponding NNlib's methods are:
16
17
17
18
```juliarepl
18
19
julia> m = Upsample(scale = (2, 3))
19
- Upsample(:nearest, scale= (2, 3))
20
+ Upsample(:nearest, scale = (2, 3))
20
21
21
22
julia> m(ones(2, 2, 1, 1)) |> size
22
23
(4, 6, 1, 1)
23
24
24
25
julia> m = Upsample(:bilinear, size = (4, 5))
25
- Upsample(:bilinear, size= (4, 5))
26
+ Upsample(:bilinear, size = (4, 5))
26
27
27
28
julia> m(ones(2, 2, 1, 1)) |> size
28
29
(4, 5, 1, 1)
29
30
"""
30
- struct Upsample{Mode,S, T}
31
+ struct Upsample{mode, S, T}
31
32
scale:: S
32
33
size:: T
33
34
end
34
35
35
- function Upsample (mode = :nearest ; scale = nothing , size = nothing )
36
+ function Upsample (mode:: Symbol = :nearest ; scale = nothing , size = nothing )
36
37
mode in [:nearest , :bilinear ] ||
37
38
throw (ArgumentError (" mode=:$mode is not supported." ))
38
- if ~ ( (scale === nothing ) ⊻ (size === nothing ))
39
- throw (ArgumentError (" Either scale or size should be specified." ))
39
+ if ! ( isnothing (scale) ⊻ isnothing (size))
40
+ throw (ArgumentError (" Either scale or size should be specified (but not both) ." ))
40
41
end
41
42
return Upsample {mode,typeof(scale),typeof(size)} (scale, size)
42
43
end
43
44
45
+ Upsample (scale, mode:: Symbol = :nearest ) = Upsample (mode; scale)
46
+
44
47
(m:: Upsample{:nearest} )(x:: AbstractArray ) =
45
48
NNlib. upsample_nearest (x, m. scale)
46
49
function (m:: Upsample{:nearest, Int} )(x:: AbstractArray{T, N} ) where {T, N}
0 commit comments