Quickstart
Using a model from Metalhead is as simple as selecting a model from the table of available models. For example, below we use the ResNet-50 model with pre-trained weights.
using Flux, Metalhead
model = ResNet50(pretrain=true)
LoadError("string", 3, ArgumentError("No pre-trained weights available for ResNet50."))
Now, we can use this model with Flux like any other model. Below, we train it on some randomly generated data.
using Flux: onehotbatch
batchsize = 8
data = [(rand(Float32, 224, 224, 3, batchsize), onehotbatch(rand(1:1000), 1:1000))
for _ in 1:3]
opt = ADAM()
ps = Flux.params(model)
loss(x, y, m) = Flux.Losses.logitcrossentropy(m(x), y)
for (i, (x, y)) in enumerate(data)
@info "Starting batch $i ..."
gs = gradient(() -> loss(x, y, model), ps)
Flux.update!(opt, ps, gs)
end
LoadError("string", 7, UndefVarError(:model))