from keras import Input
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Dropout
from keras.models import Model
from keras.layers import concatenate
from tensorflow.keras.optimizers import Adam
from keras.layers import Conv2DTranspose
def Enhancednet(pretrained_weights=None):
input_shape = (None, None, 1)
inputs = Input(shape=input_shape, name='input_img')
conv1 = Conv2D(16, 5, activation='relu', padding='same')(inputs)
drop1 = Dropout(0.6)(conv1)
pool1 = MaxPooling2D(pool_size=(2, 2))(drop1)
conv2 = Conv2D(24, 5, activation='relu', padding='same')(pool1)
drop2 = Dropout(0.6)(conv2)
pool2 = MaxPooling2D(pool_size=(2, 2))(drop2)
conv3 = Conv2D(32, 5, activation='relu', padding='same')(pool2)
drop3 = Dropout(0.6)(conv3)
pool3 = MaxPooling2D(pool_size=(2, 2))(drop3)
conv4 = Conv2D(40, 5, activation='relu', padding='same')(pool3)
drop4 = Dropout(0.6)(conv4)
up5 = Conv2D(32, 3, activation='relu', padding='same')(
Conv2DTranspose(32, 5, activation='relu', padding="same", strides=2)(drop4))
merge5 = concatenate([drop3, up5], axis=3)
conv5 = Conv2D(32, 5, activation='relu', padding='same')(merge5)
drop5 = Dropout(0.6)(conv5)
up6 = Conv2D(24, 3, activation='relu', padding='same')(
Conv2DTranspose(24, 5, activation='relu', padding="same", strides=2)(drop5))
merge6 = concatenate([drop2, up6], axis=3)
conv6 = Conv2D(24, 5, activation='relu', padding='same')(merge6)
drop6 = Dropout(0.6)(conv6)
up7 = Conv2D(16, 3, activation='relu', padding='same')(
Conv2DTranspose(16, 5, activation='relu', padding="same", strides=2)(drop6))
merge7 = concatenate([drop1, up7], axis=3)
conv7 = Conv2D(16, 5, activation='relu', padding='same')(merge7)
drop7 = Dropout(0.6)(conv7)
conv8 = Conv2D(1, 1, activation='relu')(drop7)
model = Model(inputs=inputs, outputs=conv8)
opt = Adam()
model.compile(optimizer=opt, loss='mse', metrics=['accuracy'])
if pretrained_weights:
model.load_weights(pretrained_weights)
return model