Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Refactor repo with more complete models and documentation #70

Merged
merged 54 commits into from
Jul 29, 2021
Merged
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
602ccec
Added vision models
darsnack Aug 28, 2020
518ba8c
inception v3
rishabhvarshney14 Nov 22, 2020
b829363
corrected model name
rishabhvarshney14 Nov 23, 2020
2ca5282
added SqueezeNet and reduce code repetition
rishabhvarshney14 Nov 26, 2020
e5ef7a8
added DenseNet
rishabhvarshney14 Nov 26, 2020
749f510
some minor changes
rishabhvarshney14 Nov 26, 2020
64376e3
Update to latest Flux
Jan 12, 2021
be80077
Add initial training routine
Jan 14, 2021
5c3cafb
Add updated training script for distributed
Jan 24, 2021
5cc32c4
Updated scripts and README for training
darsnack Jan 24, 2021
0041b88
Updated to latest Flux constructs
Jan 24, 2021
5c2b9f2
Fix Flux compat
darsnack Jan 26, 2021
ffa1544
Updated for released Flux
darsnack Jan 26, 2021
4bd498f
Use Flux#master for now
darsnack Jan 27, 2021
0960dd1
Transfer weights instead
darsnack Feb 15, 2021
7a5c384
Fix resnet to exclude bias from conv layers
darsnack Feb 22, 2021
7d21ed5
Removed BN from googlenet
darsnack Feb 22, 2021
c8894ce
Fix typos in googlenet
darsnack Feb 22, 2021
fe16624
Fix densenet names
darsnack Feb 23, 2021
e37ac87
Add pretrained weight loading
darsnack Mar 2, 2021
f1d0597
Remove training folder for now
darsnack Mar 2, 2021
71a0013
Add pretrained tests and update BSON
darsnack Mar 8, 2021
0dcf081
Add doc strings
darsnack Mar 8, 2021
250ea74
Adjust CI
darsnack Mar 8, 2021
8ad4878
Add initial docs
darsnack Mar 8, 2021
489b410
Add quickstart
darsnack Mar 8, 2021
c5bf016
Update to latest Flux
darsnack Mar 28, 2021
1a48e55
Stop tracking Manifest
darsnack Mar 28, 2021
f4fc9cf
Stop tracking Manifest
darsnack Mar 28, 2021
576f909
Update quickstart
darsnack Mar 28, 2021
0931dfb
Change default initialization
darsnack Mar 28, 2021
dd9975d
Fix alignment of whitespace
darsnack Mar 28, 2021
ab9d76d
Apply suggestions from code review
darsnack Mar 28, 2021
0b86849
Fix file endings
darsnack Mar 28, 2021
3c9f6dd
Add struct versions of models
darsnack Jun 3, 2021
9bb0b30
Update to latest Artifacts system
darsnack Jun 3, 2021
5875374
Add Artifacts/LazyArtifacts to Project.toml
darsnack Jun 3, 2021
d2fbf0f
Fix missing return
darsnack Jun 3, 2021
8ff0a38
Make DenseNet test grouping better
darsnack Jun 3, 2021
ae54958
Add functors
darsnack Jun 11, 2021
feb2241
Fix imports
darsnack Jun 12, 2021
a4a7ab6
Fix functors use
darsnack Jun 16, 2021
c97f4ec
Make output classes configurable
darsnack Jun 18, 2021
906a004
Use FluxML/MetalheadWeights
darsnack Jun 18, 2021
a87d589
Refactor growth rate in DenseNet
darsnack Jul 27, 2021
0f6de0d
Make GoogLeNet inception block internal helper
darsnack Jul 27, 2021
edee644
Remove extra type parameters from VGG/ResNet
darsnack Jul 27, 2021
36005f2
Adjust formatting
darsnack Jul 27, 2021
e4923b0
Big(!) show and test fixes
darsnack Jul 27, 2021
d275c50
Remove extra import
darsnack Jul 29, 2021
37538af
Add gradient tests
darsnack Jul 29, 2021
a587b3d
Break classifier and backbone into two sub-Chains
darsnack Jul 29, 2021
f9e7be5
Reduce BS
darsnack Jul 29, 2021
07925ea
skip backwards pass tests
DhairyaLGandhi Jul 29, 2021
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
Prev Previous commit
Next Next commit
Break classifier and backbone into two sub-Chains
  • Loading branch information
darsnack committed Jul 29, 2021
commit a587b3d4320f880cf7ed04e52519f55ca5768a6b
30 changes: 15 additions & 15 deletions src/alexnet.jl
Original file line number Diff line number Diff line change
@@ -8,21 +8,21 @@ Create an AlexNet model
- `nclasses`: the number of output classes
"""
function alexnet(; nclasses = 1000)
layers = Chain(Conv((11, 11), 3 => 64, stride = (4, 4), relu, pad = (2, 2)),
MaxPool((3, 3), stride = (2, 2)),
Conv((5, 5), 64 => 192, relu, pad = (2, 2)),
MaxPool((3, 3), stride = (2, 2)),
Conv((3, 3), 192 => 384, relu, pad = (1, 1)),
Conv((3, 3), 384 => 256, relu, pad = (1, 1)),
Conv((3, 3), 256 => 256, relu, pad = (1, 1)),
MaxPool((3, 3), stride = (2, 2)),
AdaptiveMeanPool((6,6)),
flatten,
Dropout(0.5),
Dense(256 * 6 * 6, 4096, relu),
Dropout(0.5),
Dense(4096, 4096, relu),
Dense(4096, nclasses))
layers = Chain(Chain(Conv((11, 11), 3 => 64, stride = (4, 4), relu, pad = (2, 2)),
MaxPool((3, 3), stride = (2, 2)),
Conv((5, 5), 64 => 192, relu, pad = (2, 2)),
MaxPool((3, 3), stride = (2, 2)),
Conv((3, 3), 192 => 384, relu, pad = (1, 1)),
Conv((3, 3), 384 => 256, relu, pad = (1, 1)),
Conv((3, 3), 256 => 256, relu, pad = (1, 1)),
MaxPool((3, 3), stride = (2, 2)),
AdaptiveMeanPool((6,6))),
Chain(flatten,
Dropout(0.5),
Dense(256 * 6 * 6, 4096, relu),
Dropout(0.5),
Dense(4096, 4096, relu),
Dense(4096, nclasses)))

return layers
end
8 changes: 4 additions & 4 deletions src/densenet.jl
Original file line number Diff line number Diff line change
@@ -73,10 +73,10 @@ function densenet(inplanes, growth_rates; reduction = 0.5, nclasses = 1000)
end
push!(layers, BatchNorm(outplanes, relu))

return Chain(layers...,
AdaptiveMeanPool((1, 1)),
flatten,
Dense(outplanes, nclasses))
return Chain(Chain(layers...),
Chain(AdaptiveMeanPool((1, 1)),
flatten,
Dense(outplanes, nclasses)))
end

"""
40 changes: 20 additions & 20 deletions src/googlenet.jl
Original file line number Diff line number Diff line change
@@ -39,26 +39,26 @@ Create an Inception-v1 model (commonly referred to as GoogLeNet)
- `nclasses`: the number of output classes
"""
function googlenet(; nclasses = 1000)
layers = Chain(Conv((7, 7), 3 => 64; stride = 2, pad = 3),
MaxPool((3, 3), stride = 2, pad = 1),
Conv((1, 1), 64 => 64),
Conv((3, 3), 64 => 192; pad = 1),
MaxPool((3, 3), stride = 2, pad = 1),
_inceptionblock(192, 64, 96, 128, 16, 32, 32),
_inceptionblock(256, 128, 128, 192, 32, 96, 64),
MaxPool((3, 3), stride = 2, pad = 1),
_inceptionblock(480, 192, 96, 208, 16, 48, 64),
_inceptionblock(512, 160, 112, 224, 24, 64, 64),
_inceptionblock(512, 128, 128, 256, 24, 64, 64),
_inceptionblock(512, 112, 144, 288, 32, 64, 64),
_inceptionblock(528, 256, 160, 320, 32, 128, 128),
MaxPool((3, 3), stride = 2, pad = 1),
_inceptionblock(832, 256, 160, 320, 32, 128, 128),
_inceptionblock(832, 384, 192, 384, 48, 128, 128),
AdaptiveMeanPool((1, 1)),
flatten,
Dropout(0.4),
Dense(1024, nclasses))
layers = Chain(Chain(Conv((7, 7), 3 => 64; stride = 2, pad = 3),
MaxPool((3, 3), stride = 2, pad = 1),
Conv((1, 1), 64 => 64),
Conv((3, 3), 64 => 192; pad = 1),
MaxPool((3, 3), stride = 2, pad = 1),
_inceptionblock(192, 64, 96, 128, 16, 32, 32),
_inceptionblock(256, 128, 128, 192, 32, 96, 64),
MaxPool((3, 3), stride = 2, pad = 1),
_inceptionblock(480, 192, 96, 208, 16, 48, 64),
_inceptionblock(512, 160, 112, 224, 24, 64, 64),
_inceptionblock(512, 128, 128, 256, 24, 64, 64),
_inceptionblock(512, 112, 144, 288, 32, 64, 64),
_inceptionblock(528, 256, 160, 320, 32, 128, 128),
MaxPool((3, 3), stride = 2, pad = 1),
_inceptionblock(832, 256, 160, 320, 32, 128, 128),
_inceptionblock(832, 384, 192, 384, 48, 128, 128),
AdaptiveMeanPool((1, 1))),
Chain(flatten,
Dropout(0.4),
Dense(1024, nclasses)))

return layers
end
44 changes: 22 additions & 22 deletions src/inception.jl
Original file line number Diff line number Diff line change
@@ -150,28 +150,28 @@ Create an Inception-v3 model ([reference](https://arxiv.org/abs/1512.00567v3)).
`inception3` does not currently support pretrained weights.
"""
function inception3(; nclasses = 1000)
layer = Chain(conv_bn((3, 3), 3, 32; stride = 2)...,
conv_bn((3, 3), 32, 32)...,
conv_bn((3, 3), 32, 64; pad = 1)...,
MaxPool((3, 3), stride = 2),
conv_bn((1, 1), 64, 80)...,
conv_bn((3, 3), 80, 192)...,
MaxPool((3, 3), stride = 2),
inception_a(192, 32),
inception_a(256, 64),
inception_a(288, 64),
inception_b(288),
inception_c(768, 128),
inception_c(768, 160),
inception_c(768, 160),
inception_c(768, 192),
inception_d(768),
inception_e(1280),
inception_e(2048),
AdaptiveMeanPool((1, 1)),
Dropout(0.2),
flatten,
Dense(2048, nclasses))
layer = Chain(Chain(conv_bn((3, 3), 3, 32; stride = 2)...,
conv_bn((3, 3), 32, 32)...,
conv_bn((3, 3), 32, 64; pad = 1)...,
MaxPool((3, 3), stride = 2),
conv_bn((1, 1), 64, 80)...,
conv_bn((3, 3), 80, 192)...,
MaxPool((3, 3), stride = 2),
inception_a(192, 32),
inception_a(256, 64),
inception_a(288, 64),
inception_b(288),
inception_c(768, 128),
inception_c(768, 160),
inception_c(768, 160),
inception_c(768, 192),
inception_d(768),
inception_e(1280),
inception_e(2048),
AdaptiveMeanPool((1, 1))),
Chain(Dropout(0.2),
flatten,
Dense(2048, nclasses)))

return layer
end
8 changes: 3 additions & 5 deletions src/resnet.jl
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ function resnet(; block, shortcut_config, channel_config, block_config, nclasses
skip_projection(inplanes, outplanes[end], i != 1)))
end
inplanes = outplanes[end]
for j in 2:nrepeats
for _ in 2:nrepeats
if shortcut_config == :A || shortcut_config == :B
push!(layers, Parallel(+, block(inplanes, outplanes, false),
skip_identity(inplanes, outplanes[end])))
@@ -116,11 +116,9 @@ function resnet(; block, shortcut_config, channel_config, block_config, nclasses
end
baseplanes *= 2
end
push!(layers, AdaptiveMeanPool((1, 1)))
push!(layers, flatten)
push!(layers, Dense(inplanes, nclasses))

return Chain(layers...)
return Chain(Chain(layers..., AdaptiveMeanPool((1, 1))),
Chain(flatten, Dense(inplanes, nclasses)))
end

const resnet_config =
30 changes: 15 additions & 15 deletions src/squeezenet.jl
Original file line number Diff line number Diff line change
@@ -28,21 +28,21 @@ Create a SqueezeNet
([reference](https://arxiv.org/abs/1602.07360v4)).
"""
function squeezenet()
layers = Chain(Conv((3, 3), 3 => 64, relu, stride = 2),
MaxPool((3, 3), stride = 2),
fire(64, 16, 64, 64),
fire(128, 16, 64, 64),
MaxPool((3, 3), stride = 2),
fire(128, 32, 128, 128),
fire(256, 32, 128, 128),
MaxPool((3, 3), stride = 2),
fire(256, 48, 192, 192),
fire(384, 48, 192, 192),
fire(384, 64, 256, 256),
fire(512, 64, 256, 256),
Dropout(0.5),
Conv((1, 1), 512 => 1000, relu),
AdaptiveMeanPool((1, 1)),
layers = Chain(Chain(Conv((3, 3), 3 => 64, relu, stride = 2),
MaxPool((3, 3), stride = 2),
fire(64, 16, 64, 64),
fire(128, 16, 64, 64),
MaxPool((3, 3), stride = 2),
fire(128, 32, 128, 128),
fire(256, 32, 128, 128),
MaxPool((3, 3), stride = 2),
fire(256, 48, 192, 192),
fire(384, 48, 192, 192),
fire(384, 64, 256, 256),
fire(512, 64, 256, 256),
Dropout(0.5),
Conv((1, 1), 512 => 1000, relu),
AdaptiveMeanPool((1, 1))),
flatten)

return layers
2 changes: 1 addition & 1 deletion src/vgg.jl
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ function vgg(imsize; config, inchannels, batchnorm = false, nclasses, fcsize, dr
conv = vgg_convolutional_layers(config, batchnorm, inchannels)
imsize = outputsize(conv, (imsize..., inchannels); padbatch = true)[1:3]
class = vgg_classifier_layers(imsize, nclasses, fcsize, dropout)
return Chain(conv..., class...)
return Chain(Chain(conv...), Chain(class...))
end

const vgg_config = Dict(:A => [(64,1), (128,1), (256,2), (512,2), (512,2)],