Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def createmodel():
- img = layers.Input(shape=imgshape) # Get image as an input of size 50,200,1
- conv1 = layers.Conv2D(16, (3, 3), padding='same', activation='relu')(img) # 50*200
- bn1 = layers.BatchNormalization()(conv1)
- # dn1_1 = layers.Dropout(0.2)(bn1)
- mp1 = layers.MaxPooling2D(pool_size=(2, 2),padding='same')(bn1) # 25*100
- conv2 = layers.Conv2D(32, (3, 3), padding='same', activation='relu')(mp1)
- bn2 = layers.BatchNormalization()(conv2)
- # dn2_2 = layers.Dropout(0.2)(bn2)
- mp2 = layers.MaxPooling2D(pool_size=(2, 2),padding='same')(bn2) # 13*50
- bn2_2 = layers.BatchNormalization()(mp2)
- conv3 = layers.Conv2D(64, (3, 3), padding='same', activation='relu')(bn2_2)
- bn3 = layers.BatchNormalization()(conv3) # to improve the stability of model
- # dn3_3 = layers.Dropout(0.2)(bn3)
- mp3 = layers.MaxPooling2D(pool_size=(2, 2),padding='same')(bn3) # 7*25
- bn3_3 = layers.BatchNormalization()(mp3) # t
- conv4 = layers.Conv2D(128, (3, 3), padding='same', activation='relu')(bn3_3)
- bn4 = layers.BatchNormalization()(conv4) # to improve the stability of model
- # dn4_4 = layers.Dropout(0.2)(bn4)
- mp4 = layers.MaxPooling2D(pool_size=(2, 2), padding='same')(bn4)
- # bn4 = layers.BatchNormalization()(mp4)
- bn4_4 = layers.BatchNormalization()(mp4)
- conv5 = layers.Conv2D(256, (3, 3), padding='same', activation='relu')(bn4_4)
- bn5 = layers.BatchNormalization()(conv5)
- mp5 = layers.MaxPooling2D((2, 2), padding='same')(bn5)
- # conv6 = layers.Conv2D(512, (3, 3), padding='same', activation='relu')(mp5)
- # bn6 = layers.BatchNormalization()(conv6)
- # mp6 = layers.MaxPooling2D((2, 2), padding='same')(bn6)
- # final = layers.Dropout(0.3)(mp5)
- # bn5_5 = layers.BatchNormalization()(mp5)
- # conv6 = layers.Conv2D(512, (3, 3), padding='same', activation='relu')(bn5_5)
- # bn6 = layers.BatchNormalization()(conv6)
- # mp6 = layers.MaxPooling2D((2, 2), padding='same')(bn6)
- # bn6_6 = layers.BatchNormalization()(mp6)
- # drop_la = layers.Dropout(0.5)(bn5_5)
- # full = layers.Dropout(0.5)(mp5)
- # bn4 = layers.BatchNormalization()(conv4) # to improve the stability of model
- # mp4 = layers.MaxPooling2D((2,2), padding='same')(bn4) # 7*25
- flat = layers.Flatten()(mp5) # convert the layer into 1-D
- outs = []
- for _ in range(5): # for 5 letters of captcha
- dens1 = layers.Dense(512, activation='relu')(flat)
- drop = layers.BatchNormalization()(dens1)
- #1 - sigmoid
- #2 - softmax
- res = layers.Dense(nchar, activation='softmax')(drop)
- # rea_ = layers.Dropout(0.2)(res) # drops 0.5 fraction of nodes
- # layers.Dropout(0.5)
- outs.append(res) # result of layers
- # Compile model and return it
- # img = img.reshape(1000, 50, 200, 1)
- model = Model(img, outs) # create model
- # optimizer = keras.optimizers.Adam(learning_rate=0.01)
- model.compile(loss='categorical_crossentropy', optimizer='Adam', metrics=["accuracy"]*5)
- return model
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement