-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencoder.py
More file actions
38 lines (30 loc) · 1.45 KB
/
Copy pathencoder.py
File metadata and controls
38 lines (30 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import matplotlib.pyplot as plt
import numpy as np
from keras import layers, optimizers, losses, metrics
from tensorflow import keras
from tensorflow.python.keras import Input, Model
from tensorflow.python.keras.layers import BatchNormalization, MaxPooling1D, Conv1D, UpSampling1D
def encoder(num_of_convs, num_of_filters, conv_filter_size, input_img):
# encoder with <num_of_convs> layers
# creates 1st convolutional layer
conv = Conv1D(num_of_filters, conv_filter_size, activation='relu', padding='same')(input_img)
conv = BatchNormalization()(conv)
conv = Conv1D(num_of_filters, conv_filter_size, activation='relu', padding='same')(conv)
conv = BatchNormalization()(conv)
pool = MaxPooling1D(pool_size=2)(conv)
# creates the rest layers
i = 0
while i < int(num_of_convs) - 1:
if i == 0 or i == 1:
conv = Conv1D(num_of_filters, conv_filter_size, activation='relu', padding='same')(pool)
else:
conv = Conv1D(num_of_filters, conv_filter_size, activation='relu', padding='same')(conv)
conv = BatchNormalization()(conv)
conv = Conv1D(num_of_filters, conv_filter_size, activation='relu', padding='same')(conv)
conv = BatchNormalization()(conv)
# max pooling only after 1st and 2nd layers
if i == 0:
pool = MaxPooling1D(pool_size=2)(conv)
num_of_filters *= 2
i += 1
return conv, num_of_filters