Diff of /autoencoder.py [000000] .. [7a2365]

Switch to unified view

a b/autoencoder.py
1
"""Autoencoder.ipynb
2
3
**
4
 * This file is part of Hybrid CNN-LSTM for COVID-19 Severity Score Prediction paper.
5
 *
6
 * Written by Ankan Ghosh Dastider and Farhan Sadik.
7
 *
8
 * Copyright (c) by the authors under Apache-2.0 License. Some rights reserved, see LICENSE.
9
 */
10
 
11
"""
12
#denoising with autoencoder + classification
13
from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D,concatenate,SeparableConv2D
14
from keras.models import Model
15
import tensorflow as tf
16
17
IMG_WIDTH = 128
18
IMG_HEIGHT = 128
19
IMG_CHANNELS = 3
20
21
densenet = DenseNet201(weights='imagenet', include_top=False)
22
#Build the model
23
inputs = Input((IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS))
24
#s = Lambda(lambda x: x / 255)(inputs)
25
s=inputs
26
27
############
28
# Encoding #
29
############
30
31
# Conv1 #
32
x_128 = Conv2D(filters = 16, kernel_size = (3, 3), activation='relu', padding='same')(inputs) #128,128,16
33
x = MaxPooling2D(pool_size = (2, 2), padding='same')(x_128)#64,64,16
34
35
# Conv2 #
36
x_64 = Conv2D(filters = 8, kernel_size = (3, 3), activation='relu', padding='same')(x)#64,64,8
37
x_32 = MaxPooling2D(pool_size = (2, 2), padding='same')(x_64)#32,32,8 
38
39
# Conv 3 #
40
x_32_1 = Conv2D( 8, (3, 3), activation='relu', padding='same')(x_32) #32,32,8
41
#x = MaxPooling2D(pool_size = (2, 2), padding='same')(x)
42
43
# Conv 4 #
44
#x = Conv2D( 8, (3, 3), activation='relu', padding='same')(x) #16
45
#x = MaxPooling2D(pool_size = (2, 2), padding='same')(x)
46
# Conv 5 #
47
#x = Conv2D( 8, (3, 3), activation='relu', padding='same')(x) #8
48
encoded_16 = MaxPooling2D(pool_size = (2, 2), padding='same')(x_32_1) #16,16,8
49
#conv 6
50
#x = Conv2D( 8, (3, 3), activation='relu', padding='same')(x) 
51
#encoded = MaxPooling2D(pool_size = (2, 2), padding='same')(x)
52
53
############
54
# Decoding #
55
############
56
57
# DeConv1
58
y_16 = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded_16)#16,16,8
59
y_32 = UpSampling2D((2, 2))(y_16)#32,32,8
60
61
y_32=concatenate([x_32,y_32])#32,32,8
62
63
#temp_32=MaxPooling2D(pool_size = (2, 2), padding='same')(x_64) 
64
#y_32= 
65
66
# DeConv2
67
y_32= Conv2D(8, (3, 3), activation='relu', padding='same')(y_32)#32,32,8
68
y_64= UpSampling2D((2, 2))(y_32) #64,64,8
69
y_64=concatenate([x_64,y_64]) #64,64,8
70
71
# DeConv2
72
y_64 = Conv2D(16, (3, 3), activation='relu', padding='same')(y_64)#64,64,16
73
y_128= UpSampling2D((2, 2))(y_64)#128,128,16
74
75
y_128=concatenate([y_128,x_128])
76
77
# DeConv2
78
#x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
79
#x = UpSampling2D((2, 2))(x)
80
81
# DeConv2
82
#x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
83
#x = UpSampling2D((2, 2))(x)
84
85
# Deconv3
86
#x = Conv2D(16, (3, 3), activation='relu')(x)
87
#x = UpSampling2D((2, 2))(x)
88
decoded = Conv2D(3, (3, 3), activation='sigmoid', padding='same')(y_128)#128,128,3
89
90
decoded=concatenate([decoded,inputs ])
91
decoded = Conv2D(3, (3, 3), activation='sigmoid', padding='same')(decoded)
92
93
x=Conv2D(3, (3, 3), activation='relu', kernel_initializer='he_normal', padding='same')(decoded)