Skip to content

Commit

Permalink
channel pooling along any dimension (GPU)
Browse files Browse the repository at this point in the history
  • Loading branch information
pluskid committed Dec 19, 2014
1 parent 6b99f33 commit 822dabc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
36 changes: 16 additions & 20 deletions src/cuda/layers/channel-pooling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function forward(backend::GPUBackend, pool::StdPoolingFunction,
output = state.blobs[i]

if isa(pool, Pooling.Max)
cuda_max_channel_pooling_forward(backend, input, output, state.etc[i], state.layer)
cuda_max_channel_pooling_forward(backend, input, output, state.etc[i], state.layer, state.op_dims[i])
elseif isa(pool, Pooling.Mean)
cuda_mean_channel_pooling_forward(backend, input, output, state.etc[i], state.layer)
cuda_mean_channel_pooling_forward(backend, input, output, state.etc[i], state.layer, state.op_dims[i])
else
error("Pooling for $pool not implemented yet")
end
Expand All @@ -57,9 +57,9 @@ function backward(backend::GPUBackend, pool::StdPoolingFunction, state::ChannelP
diff = diffs[i]
if !isa(diff, NullBlob)
if isa(pool, Pooling.Max)
cuda_max_channel_pooling_backward(backend, diff, state.blobs_diff[i], state.etc[i], state.layer)
cuda_max_channel_pooling_backward(backend, diff, state.blobs_diff[i], state.etc[i], state.layer, state.op_dims[i])
elseif isa(pool, Pooling.Mean)
cuda_mean_channel_pooling_backward(backend, diff, state.blobs_diff[i], state.layer)
cuda_mean_channel_pooling_backward(backend, diff, state.blobs_diff[i], state.layer, state.op_dims[i])
else
error("Pooling for $pool not implemented yet")
end
Expand All @@ -70,15 +70,14 @@ function backward(backend::GPUBackend, pool::StdPoolingFunction, state::ChannelP
end

function cuda_mean_channel_pooling_forward{T}(backend::GPUBackend, input::CuTensorBlob{T},
output::CuTensorBlob{T}, integral::CuPtr, layer)
output::CuTensorBlob{T}, integral::CuPtr, layer, op_dim)

width, height, channels, num = size(input)
pooled_chann = size(output, 3)
spatial_dim_T, channels, num = split_dims(input, op_dim)
pooled_chann = size(output, op_dim)
one = convert(T, 1)
neg_one = convert(T, -1)
scale = convert(T, 1.0/layer.kernel)

spatial_dim_T = width*height
spatial_dim = spatial_dim_T * sizeof(T)
fea_dim = spatial_dim * channels
output_fea_dim = spatial_dim * pooled_chann
Expand Down Expand Up @@ -116,15 +115,14 @@ function cuda_mean_channel_pooling_forward{T}(backend::GPUBackend, input::CuTens
end

function cuda_mean_channel_pooling_backward{T}(backend::GPUBackend, input::CuTensorBlob{T},
output::CuTensorBlob{T}, layer)
output::CuTensorBlob{T}, layer, op_dim)

width, height, channels, num = size(input)
pooled_chann = size(output, 3)
spatial_dim_T, channels, num = split_dims(input, op_dim)
pooled_chann = size(output, op_dim)
scale = 1/convert(T, layer.kernel)

fill!(input, 0)

spatial_dim_T = width*height
spatial_dim = spatial_dim_T * sizeof(T)
fea_dim = spatial_dim * channels
output_fea_dim = spatial_dim * pooled_chann
Expand Down Expand Up @@ -157,11 +155,10 @@ function cuda_geometry_max_chann_pool(sp_dim::Int, num::Int)

end
function cuda_max_channel_pooling_forward{T}(backend::GPUBackend, input::CuTensorBlob{T},
output::CuTensorBlob{T}, mask::CuPtr, layer)
output::CuTensorBlob{T}, mask::CuPtr, layer, op_dim)

width, height, channels, num = size(input)
sp_dim = width*height
pooled_chann = get_chann(output)
sp_dim, channels, num = split_dims(input, op_dim)
pooled_chann = size(output, op_dim)

cuda_dim = cuda_geometry_max_chann_pool(sp_dim, num);
if T == Float32
Expand All @@ -177,11 +174,10 @@ function cuda_max_channel_pooling_forward{T}(backend::GPUBackend, input::CuTenso
end

function cuda_max_channel_pooling_backward{T}(backend::GPUBackend, input::CuTensorBlob{T},
output::CuTensorBlob{T}, mask::CuPtr, layer)
output::CuTensorBlob{T}, mask::CuPtr, layer, op_dim)

width, height, channels, num = size(input)
sp_dim = width*height
pooled_chann = get_chann(output)
sp_dim, channels, num = split_dims(input, op_dim)
pooled_chann = size(output, op_dim)

cuda_dim = cuda_geometry_max_chann_pool(sp_dim, num);
if T == Float32
Expand Down
4 changes: 0 additions & 4 deletions src/layers/channel-pooling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ function forward(backend::CPUBackend, pool::StdPoolingFunction,
max_channel_pooling_forward(reshape(input,dims_in), reshape(output,dims_out), reshape(state.etc[i],dims_out), state.layer)
elseif isa(pool, Pooling.Mean)
mean_channel_pooling_forward(reshape(input,dims_in), reshape(output,dims_out), state.etc[i], state.layer)
else
error("Pooling for $pool not implemented yet")
end
end
end
Expand All @@ -130,8 +128,6 @@ function backward(backend::CPUBackend, pool::StdPoolingFunction, state::ChannelP
reshape(state.etc[i],dims_out), state.layer)
elseif isa(pool, Pooling.Mean)
mean_channel_pooling_backward(reshape(diff.data,dims_in), reshape(state.blobs_diff[i].data,dims_out), state.layer)
else
error("Pooling for $pool not implemented yet")
end
end
end
Expand Down

0 comments on commit 822dabc

Please sign in to comment.