Пример #1
0
 def __init__(self):
     self.im_heigth = 8 * 40
     self.im_width = 16 * 40
     input_shape = (self.im_heigth, self.im_width, 1)
     self.maskModel = getSegModel(input_shape)
     self.ocrModel = getOCRModel()
     self.ocrModel.load_weights(currPath+'/checkpoints/OCRmodel_vl0.7638.hdf5')
Пример #2
0
def locnetWithMask(input_shape):
    segmodel = getSegModel(input_shape)
    for layer in segmodel.layers:
        layer.trainable = False
    inp = Input(input_shape)
    segmentMask = segmodel(inp)
    combinedinput = concatenate([inp,segmentMask], axis=-1)

    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(64, kernel_size=3, padding='same')(combinedinput))))
    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(64, kernel_size=3, padding='same')(x))))
    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(128, kernel_size=3, padding='same')(x))))
    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(128, kernel_size=3, padding='same')(x))))
    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(256, kernel_size=3, padding='same')(x))))
    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(256, kernel_size=3, padding='same')(x))))
    xZ = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(256, kernel_size=3, padding='same')(x))))
    x = Flatten()(xZ)
    x = Dense(256, name='emb1', activation='relu')(x)
    x = Dropout(0.25)(x)
    x = Dense(256, name='emb2', activation='relu')(x)
    x = Dropout(0.25)(x)
    x = Dense(6, name='out')(x)
    locnet = Model(input=inp, output=x)

    locnet.load_weights('checkpoints/LOCNET_vl0.0469.hdf5')
    locnet.compile('adam', 'mse')
    for layer in locnet.layers:
        layer.trainable = False
    locnet.summary()
    return  locnet
Пример #3
0
def locnet_and_sp_mask(input_shape):
    segmodel = getSegModel(input_shape, compile=False)
    transformedInputSize = (32, 16 * 32, 1)

    # for layer in segmodel.layers:
    #     layer.trainable = False
    inp = Input(input_shape)
    segmentMask = segmodel(inp)
    combinedinput = concatenate([inp, segmentMask], axis=-1)

    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(32, kernel_size=3, padding='same')(segmentMask))))
    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(32, kernel_size=3, padding='same')(x))))
    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(64, kernel_size=3, padding='same')(x))))
    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(64, kernel_size=3, padding='same')(x))))
    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(128, kernel_size=3, padding='same')(x))))
    x = MaxPooling2D((2, 2))(LeakyReLU(0.2)(BatchNormalization()(Conv2D(128, kernel_size=3, padding='same')(x))))
    xZ = LeakyReLU(0.2)(BatchNormalization()(Conv2D(128, kernel_size=3, padding='same')(x)))
    x = LeakyReLU(0.2)(BatchNormalization()(Conv2D(64, kernel_size=3, padding='same')(xZ)))
    x = Reshape((2048,))(x)
    x = Dropout(0.25)(x)
    x = LeakyReLU(0.2)(Dense(256, name='emb2')(x))
    x = Dropout(0.25)(x)
    x = Dense(6, name='out')(x)
    locnet = Model(input=inp, output=x)
    #locnet.compile('adam','mse')
    #locnet.load_weights('checkpoints/LOCNET_vl0.0469.hdf5')

    transformedMask = SpatialTransformer(localization_net=locnet, output_size=transformedInputSize[:2], input_shape=input_shape)(segmentMask)
    model = Model(input = inp, outputs=[x, transformedMask, segmentMask])

    model.compile('sgd', ['mse', 'mse', 'binary_crossentropy'], loss_weights=[1.,0.,1.])
    model.summary()
    return model
Пример #4
0
def locnet_on_mask(shape, retunCrop=False):


    transformedInputSize = (32, 16 * 32, 1)

    locnet = getlocnet(shape)

    inp  = Input(shape)

    transformedInput = SpatialTransformer(localization_net=locnet,
                                          output_size=transformedInputSize[:2],
                                          input_shape=shape)(inp)

    segmodel = getSegModel(transformedInputSize)
    for layer in segmodel.layers:
        layer.trainable = False
    segOutput = segmodel(transformedInput)

    if retunCrop:
        endToEndModel = Model(input=inp, output=[segOutput, transformedInput])
    else:
        endToEndModel = Model(input=inp, output=segOutput)
    endToEndModel.compile('sgd', 'binary_crossentropy')
    return endToEndModel
Пример #5
0
import numpy as np
from scipy.misc import imsave
from utils import crop_rotate, mirror
import cv2
import os
import math
import itertools
from scipy.misc import imsave
from adjustTextPosition import adjust

im_heigth = 8 * 40
im_width = 16 * 40
input_shape = (im_heigth, im_width, 1)
max_angle = 45

model = getSegModel(input_shape)
model.load_weights('checkpoints/segmenter_vl0.0163.hdf5')

imgs = [
    os.path.join(root, f) for root, _, files in os.walk('./tmp') for f in files
    if f.lower().endswith('.jpg')
]

for imgpath in imgs:
    savepath = imgpath.replace('tmp', 'trainimgs')
    if not os.path.exists(savepath):
        img = Image.open(imgpath)
        img = img.resize((im_width, im_heigth))

        img = np.array(img.convert('L'))
        np_img = img / 127.5 - 1