Skip to content
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

How to use Metalhead'model as ImageClassifier model? #200

Open
zsz00 opened this issue Mar 20, 2022 · 3 comments
Open

How to use Metalhead'model as ImageClassifier model? #200

zsz00 opened this issue Mar 20, 2022 · 3 comments

Comments

@zsz00
Copy link

zsz00 commented Mar 20, 2022

How to use Metalhead'model as ImageClassifier model?
such as:

using Flux, MLJFlux, Metalhead

ImageClassifier = @load ImageClassifier

model = ResNet50(pretrain=false, nclasses=20)

clf = ImageClassifier(builder=model,
		                  epochs=500,
                                  optimiser=ADAM(0.001),
		                  loss=Flux.crossentropy,
                                  batch_size=512,
                                  acceleration=CUDALibs(),)

mach = machine(clf, images, labels)
@zsz00 zsz00 changed the title How to use Metalhead'models as ImageClassifier model? How to use Metalhead'model as ImageClassifier model? Mar 20, 2022
@zsz00
Copy link
Author

zsz00 commented Mar 20, 2022

I found it

mutable struct MyConvBuilder
end

function MLJFlux.build(b::MyConvBuilder, rng, n_in, n_out, n_channels)
    model = ResNet18(pretrain=false, nclasses=n_out)
    return model
end

clf = ImageClassifier(builder=MyConvBuilder(),
		                  epochs=500,
                                  optimiser=ADAM(0.001),
		                  loss=Flux.crossentropy,
                                  batch_size=512,
                                  acceleration=CUDALibs(),)

@ablaom
Copy link
Collaborator

ablaom commented Mar 23, 2022

Thanks. Perhaps we can now resolve #162! I'm happy to make MetalHead as a dependency of MLJFlux. PR welcome.

@ablaom
Copy link
Collaborator

ablaom commented Jun 23, 2022

Closed in favour of #205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants