using Flux
using Flux:@functor
function ConvBlock(inc,out,k,s,p,use_act)
return Chain(
Conv((k,k),inc=>out,stride = s,pad = p,bias=true),
use_act ? x -> leakyrelu.(x,0.2) : x -> x
)
end
mutable struct DenseResidualBlock
residual_beta
blocks
end
@functor DenseResidualBlock
function DenseResidualBlock(inc,c = 32,residual_beta = 0.2)
blocks = []
for i in 0:4
in_channels = inc + c*i
out_channels = i<=3 ? c : inc
use_act = i<=3 ? true : false
push!(blocks,ConvBlock(in_channels,out_channels,3,1,1,use_act))
end
return DenseResidualBlock(residual_beta,blocks)
end
function (m::DenseResidualBlock)(x)
new_inputs = x
local out,new_inputs
for block in m.blocks
out = block(new_inputs)
new_inputs = cat(new_inputs,out,dims=3)
end
return m.residual_beta * out + x
end
When I run this
drb = DenseResidualBlock(64)
I get this error ERROR: MethodError: no method matching *(::Chain{Tuple{Conv{2,4,typeof(identity),Array{Float32,4},Array{Float32,1}},var"#13#15"}}, ::Int64)