-
-
Couldn't load subscription status.
- Fork 615
add bilinear upsample layer #1136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
734afc5
2d0bd18
d2fee6d
3110531
0d9b84f
a15f02e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||
| struct BilinearUpsample{T<:Integer} | ||||
| factor::Tuple{T,T} | ||||
| end | ||||
|
|
||||
| function (b::BilinearUpsample)(x::AbstractArray) | ||||
| W, H, C, N = size(x) | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be better to swap There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The data in Flux is stored in WHCN order isn’t it? Line 17 in 7a32a70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is, but I prefer to read it as a misunderstanding. I just wanted to mention it here in case you're not aware of it. It's okay to abuse the usage of WH since it's relative to the column/row-first order. |
||||
|
|
||||
| newW = W * b.factor[1] | ||||
| newH = H * b.factor[2] | ||||
|
|
||||
| out = similar(x, (newW, newH, C, N)) | ||||
|
|
||||
| for n = 1:N, c = 1:C, w = 1:newW, h = 1:newH | ||||
|
||||
| w₀ = (w - 0.5) / b.factor[1] + 0.5 | ||||
| h₀ = (h - 0.5) / b.factor[2] + 0.5 | ||||
|
|
||||
| w1 = floor(Int, w₀) | ||||
| w2 = w1 + 1 | ||||
| h1 = floor(Int, h₀) | ||||
| h2 = h1 + 1 | ||||
|
|
||||
| i1 = clamp(w1, 1, W) | ||||
| i2 = clamp(w2, 1, W) | ||||
| j1 = clamp(h1, 1, H) | ||||
| j2 = clamp(h2, 1, H) | ||||
|
|
||||
| out[w, h, c, n] = | ||||
| ( | ||||
| x[i1, j1, c, n] * (w2 - w₀) * (h2 - h₀) + | ||||
| x[i1, j2, c, n] * (w2 - w₀) * (h₀ - h1) + | ||||
| x[i2, j1, c, n] * (w₀ - w1) * (h2 - h₀) + | ||||
| x[i2, j2, c, n] * (w₀ - w1) * (h₀ - h1) | ||||
| ) / (w2 - w1 * h2 - h1) | ||||
| end | ||||
|
|
||||
| out | ||||
| end | ||||
|
|
||||
kczimm marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
| function Base.show(io::IO, b::BilinearUpsample) | ||||
| print(io, "BilinearUpsample(", b.factor[1], ", ", b.factor[2], ")") | ||||
| end | ||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.