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

flatten layers appear as closures #94

Closed
adrhill opened this issue Oct 13, 2021 · 2 comments
Closed

flatten layers appear as closures #94

adrhill opened this issue Oct 13, 2021 · 2 comments

Comments

@adrhill
Copy link
Contributor

adrhill commented Oct 13, 2021

When using Metalhead models, layers using flatten appear as closures, e.g. Metalhead.var"#44#45"() in the following example.

This makes it impossible to dispatch on these layers or infer what they are without looking into the Metalhead source.

Example

julia> model = VGG19();

julia> model.layers
Chain(
  Conv((3, 3), 3 => 64, relu, pad=1),   # 1_792 parameters
  Conv((3, 3), 64 => 64, relu, pad=1),  # 36_928 parameters
  MaxPool((2, 2)),
  Conv((3, 3), 64 => 128, relu, pad=1),  # 73_856 parameters
  Conv((3, 3), 128 => 128, relu, pad=1),  # 147_584 parameters
  MaxPool((2, 2)),
  Conv((3, 3), 128 => 256, relu, pad=1),  # 295_168 parameters
  Conv((3, 3), 256 => 256, relu, pad=1),  # 590_080 parameters
  Conv((3, 3), 256 => 256, relu, pad=1),  # 590_080 parameters
  Conv((3, 3), 256 => 256, relu, pad=1),  # 590_080 parameters
  MaxPool((2, 2)),
  Conv((3, 3), 256 => 512, relu, pad=1),  # 1_180_160 parameters
  Conv((3, 3), 512 => 512, relu, pad=1),  # 2_359_808 parameters
  Conv((3, 3), 512 => 512, relu, pad=1),  # 2_359_808 parameters
  Conv((3, 3), 512 => 512, relu, pad=1),  # 2_359_808 parameters
  MaxPool((2, 2)),
  Conv((3, 3), 512 => 512, relu, pad=1),  # 2_359_808 parameters
  Conv((3, 3), 512 => 512, relu, pad=1),  # 2_359_808 parameters
  Conv((3, 3), 512 => 512, relu, pad=1),  # 2_359_808 parameters
  Conv((3, 3), 512 => 512, relu, pad=1),  # 2_359_808 parameters
  MaxPool((2, 2)),
  Metalhead.var"#44#45"(),
  Dense(25088, 4096, relu),             # 102_764_544 parameters
  Dropout(0.5),
  Dense(4096, 4096, relu),              # 16_781_312 parameters
  Dropout(0.5),
  Dense(4096, 1000),                    # 4_097_000 parameters
  NNlib.softmax,
)                   # Total: 38 arrays, 143_667_240 parameters, 548.053 MiB.

(jl_qLymP0) pkg> status Metalhead
      Status `/private/var/folders/74/wcz8c9qs5dzc8wgkk7839k5c0000gn/T/jl_qLymP0/Project.toml`
  [dbeba491] Metalhead v0.5.3
@adrhill
Copy link
Contributor Author

adrhill commented Oct 13, 2021

I'm not sure whether this is just a missing reexport by Metalheads or whether I should make a PR to Flux.

I guess the introduction of a struct would be most useful for my personal use-case of dispatching on individual layer types:

struct Flatten end
(::Flatten)(x) = flatten(x)

@ToucheSir
Copy link
Member

ToucheSir commented Oct 13, 2021

This should be fixed on master as of #70. You should see then flatten instead of an anonymous function.

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