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

Bump compat for Metalhead #232

Merged
merged 5 commits into from
Aug 24, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions test/image.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,29 @@ mutable struct MyNeuralNetwork <: MLJFlux.Builder
kernel2
end

function MLJFlux.build(model::MyNeuralNetwork, rng, ip, op, n_channels)
# to get a matrix whose last dimension mathces that of the array input (the batch size):
function make2d(x)
l = length(x)
b = size(x)[end]
reshape(x, div(l, b), b)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I thought this use of reshape would avoid the "scalar indexing error", but tests are still not passing.

end

function MLJFlux.build(builder::MyNeuralNetwork, rng, ip, op, n_channels)
init = Flux.glorot_uniform(rng)
Flux.Chain(
Flux.Conv(model.kernel1, n_channels=>2, init=init),
Flux.Conv(model.kernel2, 2=>1, init=init),
x->reshape(x, :, size(x)[end]),
Flux.Dense(16, op, init=init))
front = Flux.Chain(
Flux.Conv(builder.kernel1, n_channels=>2, init=init),
Flux.Conv(builder.kernel2, 2=>1, init=init),
make2d,
)
d = Flux.outputsize(front, (ip..., n_channels, 1))[1]
return Flux.Chain(
front,
Flux.Dense(d, op, init=init)
)
end

builder = MyNeuralNetwork((2,2), (2,2))
images, labels = MLJFlux.make_images(stable_rng)
images, labels = MLJFlux.make_images(stable_rng);
losses = []

@testset_accelerated "ImageClassifier basic tests" accel begin
Expand Down