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
from keras import layers as ls | |
from keras import models | |
from keras.regularizers import l2 | |
def bn_relu_conv(in_tensor, | |
filters, | |
kernel_size, | |
strides=1, | |
padding='same', | |
weight_decay=1e-4): |
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
from keras import layers as ls | |
from keras.models import Model | |
def conv_relu(in_tensor, kernel_size, filters): | |
# A simple Convolution, BatchNormalization and Relu Stack | |
conv = ls.Conv2D(filters, kernel_size, | |
strides=1, padding='same', | |
kernel_initializer='he_normal')(in_tensor) | |
return ls.Activation('relu')(conv) |
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
from keras import layers as ls | |
from keras.regularizers import l2 | |
from keras.models import Model | |
def conv_bn_relu(in_tensor, kernel_size, | |
filters, strides, | |
padding='same', apply_relu=True, | |
weight_decay=5e-4): | |
# A simple Convolution, BatchNormalization and Relu Stack |
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
import keras.layers as ls #import Conv2D, DepthwiseConv2D, BatchNormalization, Dense | |
from keras.models import Model | |
from functools import partial | |
def depthwise_separable_conv(in_tensor, filters_pw, strides): | |
l1_1 = ls.DepthwiseConv2D(3, strides=strides, | |
depth_multiplier=1, padding='same')(in_tensor) | |
l1_2 = ls.BatchNormalization()(l1_1) | |
l1_3 = ls.Activation('relu')(l1_2) |
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
from keras import layers | |
from keras.models import Model | |
from functools import partial | |
conv1x1 = partial(layers.Conv2D, kernel_size=1, activation='relu') | |
conv3x3 = partial(layers.Conv2D, kernel_size=3, padding='same', activation='relu') | |
conv5x5 = partial(layers.Conv2D, kernel_size=5, padding='same', activation='relu') | |
def inception_module(in_tensor, c1, c3_1, c3, c5_1, c5, pp): |
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
from keras import layers | |
from keras.models import Model | |
def _after_conv(in_tensor): | |
norm = layers.BatchNormalization()(in_tensor) | |
return layers.Activation('relu')(norm) | |
def conv1(in_tensor, filters): | |
conv = layers.Conv2D(filters, kernel_size=1, strides=1)(in_tensor) | |
return _after_conv(conv) |
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
from keras import layers | |
from keras.models import Model, Sequential | |
from functools import partial | |
conv3 = partial(layers.Conv2D, | |
kernel_size=3, | |
strides=1, | |
padding='same', | |
activation='relu') |
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
from keras import layers | |
from keras.models import Model | |
def alexnet(in_shape=(227,227,3), n_classes=1000, opt='sgd'): | |
in_layer = layers.Input(in_shape) | |
conv1 = layers.Conv2D(96, 11, strides=4, activation='relu')(in_layer) | |
pool1 = layers.MaxPool2D(3, 2)(conv1) | |
conv2 = layers.Conv2D(256, 5, strides=1, padding='same', activation='relu')(pool1) | |
pool2 = layers.MaxPool2D(3, 2)(conv2) | |
conv3 = layers.Conv2D(384, 3, strides=1, padding='same', activation='relu')(pool2) |
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
from keras import layers | |
from keras.models import Model | |
def lenet_5(in_shape=(32,32,1), n_classes=10, opt='sgd'): | |
in_layer = layers.Input(in_shape) | |
conv1 = layers.Conv2D(filters=20, kernel_size=5, | |
padding='same', activation='relu')(in_layer) | |
pool1 = layers.MaxPool2D()(conv1) | |
conv2 = layers.Conv2D(filters=50, kernel_size=5, | |
padding='same', activation='relu')(pool1) |
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
def check_armstrong(num): | |
cube_sum = 0 | |
temp = num | |
while temp >= 0: | |
digit = temp % 10 | |
cube_sum = cube_sum + digit ** 3 | |
temp = temp / 10 | |
return cube_sum == num |
NewerOlder