-
Notifications
You must be signed in to change notification settings - Fork 635
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deep Learning Finishedgit statusgit status
- Loading branch information
Haibin
authored and
Haibin
committed
Apr 16, 2018
1 parent
3193b8e
commit b2c1e38
Showing
94 changed files
with
28,076 additions
and
1,390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
datasets | ||
images | ||
|
Binary file not shown.
Binary file added
BIN
+6 KB
Convolutional Neural Networks/Car detection for Autonomous Driving/.DS_Store
Binary file not shown.
File renamed without changes.
Binary file added
BIN
+6 KB
Convolutional Neural Networks/Car detection for Autonomous Driving/yad2k/.DS_Store
Binary file not shown.
71 changes: 71 additions & 0 deletions
71
...onal Neural Networks/Car detection for Autonomous Driving/yad2k/models/keras_darknet19.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Darknet19 Model Defined in Keras.""" | ||
import functools | ||
from functools import partial | ||
|
||
from keras.layers import Conv2D, MaxPooling2D | ||
from keras.layers.advanced_activations import LeakyReLU | ||
from keras.layers.normalization import BatchNormalization | ||
from keras.models import Model | ||
from keras.regularizers import l2 | ||
|
||
from ..utils import compose | ||
|
||
# Partial wrapper for Convolution2D with static default argument. | ||
_DarknetConv2D = partial(Conv2D, padding='same') | ||
|
||
|
||
@functools.wraps(Conv2D) | ||
def DarknetConv2D(*args, **kwargs): | ||
"""Wrapper to set Darknet weight regularizer for Convolution2D.""" | ||
darknet_conv_kwargs = {'kernel_regularizer': l2(5e-4)} | ||
darknet_conv_kwargs.update(kwargs) | ||
return _DarknetConv2D(*args, **darknet_conv_kwargs) | ||
|
||
|
||
def DarknetConv2D_BN_Leaky(*args, **kwargs): | ||
"""Darknet Convolution2D followed by BatchNormalization and LeakyReLU.""" | ||
no_bias_kwargs = {'use_bias': False} | ||
no_bias_kwargs.update(kwargs) | ||
return compose( | ||
DarknetConv2D(*args, **no_bias_kwargs), | ||
BatchNormalization(), | ||
LeakyReLU(alpha=0.1)) | ||
|
||
|
||
def bottleneck_block(outer_filters, bottleneck_filters): | ||
"""Bottleneck block of 3x3, 1x1, 3x3 convolutions.""" | ||
return compose( | ||
DarknetConv2D_BN_Leaky(outer_filters, (3, 3)), | ||
DarknetConv2D_BN_Leaky(bottleneck_filters, (1, 1)), | ||
DarknetConv2D_BN_Leaky(outer_filters, (3, 3))) | ||
|
||
|
||
def bottleneck_x2_block(outer_filters, bottleneck_filters): | ||
"""Bottleneck block of 3x3, 1x1, 3x3, 1x1, 3x3 convolutions.""" | ||
return compose( | ||
bottleneck_block(outer_filters, bottleneck_filters), | ||
DarknetConv2D_BN_Leaky(bottleneck_filters, (1, 1)), | ||
DarknetConv2D_BN_Leaky(outer_filters, (3, 3))) | ||
|
||
|
||
def darknet_body(): | ||
"""Generate first 18 conv layers of Darknet-19.""" | ||
return compose( | ||
DarknetConv2D_BN_Leaky(32, (3, 3)), | ||
MaxPooling2D(), | ||
DarknetConv2D_BN_Leaky(64, (3, 3)), | ||
MaxPooling2D(), | ||
bottleneck_block(128, 64), | ||
MaxPooling2D(), | ||
bottleneck_block(256, 128), | ||
MaxPooling2D(), | ||
bottleneck_x2_block(512, 256), | ||
MaxPooling2D(), | ||
bottleneck_x2_block(1024, 512)) | ||
|
||
|
||
def darknet19(inputs): | ||
"""Generate Darknet-19 model for Imagenet classification.""" | ||
body = darknet_body()(inputs) | ||
logits = DarknetConv2D(1000, (1, 1), activation='softmax')(body) | ||
return Model(inputs, logits) |
Oops, something went wrong.