Note this package requires Flux#master
in order to be able to disable bias in convolutional layers,
as there is no release with this ability yet.
Implementation of ResNet in Julia language.
Pretrained on ImageNet weights were ported from PyTorch, tested and confirmed to give identical results with the PyTorch's version.
Model | Weights |
---|---|
ResNet18 | Download |
ResNet34 | Download |
ResNet50 | Download |
ResNet101 | Download |
ResNet152 | Download |
Because currently Flux.jl defines only bias β and scale γ as trainable parameters
for BatchNorm, you have to redefine trainable
function for BatchNorm as follows.
Flux.trainable(bn::Flux.BatchNorm) = (bn.β, bn.γ, bn.μ, bn.σ²)
After that you can load weights using BSON.jl.
model = resnet(18)
path = "./resnet18-pretrained.bson"
@load path parameters
loadweights!(model, parameters)
Given image one can perform inference simply by calling model
image = ...
y = model(image)
or if you want to extract features
features = image |> model.entry |> model.encoder
or extract list of features
entry = image |> model.entry
features = [model.encoder[1](entry)]
for encoder in model.encoder[2:end]
push!(features, encoder(features[end]))
end