Exemple #1
0
# dataset specs
X_train, y_train = load_dataset_spplited(fname=FTRAIN, test=False)
print("splitted=", X_train.shape, y_train.shape)
pic_width = 96
pic_height = 96
pic_channels = 1  # grayscale
num_classes = 15 * 2
# other
input = PicturePlaceholder(
    sample_input_shape=[pic_height, pic_width, pic_channels])
output = LabelsPlaceholder(num_classes=num_classes)

cnn = Network()
# First CNN layer
cnn.add_layer(BatchNormLayer(name="batch_norm1"))\
    .add_layer(ConvolutionalLayer(name="conv1", filter_size=5, num_filters=24, strides=[1, 1, 1, 1])) \
    .add_layer(ActivationLayer(name="relu1", activation_fn=tf.nn.relu))\
    .add_layer(MaxPoolLayer(name="pool1", padding="VALID"))

# Second CNN layer
cnn.add_layer(ConvolutionalLayer(name="conv2", filter_size=5, num_filters=36, strides=[1, 1, 1, 1], padding="VALID")) \
    .add_layer(ActivationLayer(name="relu2", activation_fn=tf.nn.relu))\
    .add_layer(MaxPoolLayer(name="pool2", padding="VALID"))

# Third CNN layer
cnn.add_layer(ConvolutionalLayer(name="conv3", filter_size=5, num_filters=48, strides=[1, 1, 1, 1], padding="VALID")) \
    .add_layer(ActivationLayer(name="relu3", activation_fn=tf.nn.relu))\
    .add_layer(MaxPoolLayer(name="pool3", padding="VALID"))

# Fourth CNN layer
cnn.add_layer(ConvolutionalLayer(name="conv4", filter_size=3, num_filters=64, strides=[1, 1, 1, 1], padding="VALID")) \
# dataset specs
X_train, y_train = load_dataset_spplited(fname=FTRAIN, test=False)
print("splitted=", X_train.shape, y_train.shape)
pic_width = 96
pic_height = 96
pic_channels = 1  # grayscale
num_classes = 15 * 2
# other
input = PicturePlaceholder(
    sample_input_shape=[pic_height, pic_width, pic_channels])
output = LabelsPlaceholder(num_classes=num_classes)

cnn = Network()
# First CNN layer
cnn.add_layer(ConvolutionalLayer(name="conv1", filter_size=5, num_filters=24))\
    .add_layer(MaxPoolLayer(name="pool1"))\
    .add_layer(BatchNormLayer(name="batch_norm1"))\
    .add_layer(ActivationLayer(name="relu1", activation_fn=tf.nn.relu))

# Second CNN layer
cnn.add_layer(ConvolutionalLayer(name="conv2", filter_size=5, num_filters=36))\
    .add_layer(MaxPoolLayer(name="pool2"))\
    .add_layer(BatchNormLayer(name="batch2"))\
    .add_layer(ActivationLayer(name="relu2", activation_fn=tf.nn.relu))

# Third CNN layer
cnn.add_layer(ConvolutionalLayer(name="conv3", filter_size=5, num_filters=48))\
    .add_layer(MaxPoolLayer(name="pool3"))\
    .add_layer(BatchNormLayer(name="batch3"))\
    .add_layer(ActivationLayer(name="relu3", activation_fn=tf.nn.relu))