Nagakiran1 / 4-simple-steps-in-Builiding-OCR

Optical character recognition (OCR) is process of classification of opti- cal patterns contained in a digital image. The character recognition is achieved through segmentation, feature extraction and classification. Keras Deep learning Network is used at here in recognising the Text characters and OpenCV is used in segmenting the text and Noise normalization.
40 stars 12 forks source link

Regularization DropBLock : When I add the regularization block for each Colvolution Layer I got the followinf probem . #3

Open hamzaca opened 4 years ago

hamzaca commented 4 years ago

TypeError: An op outside of the function building code is being passed a "Graph" tensor. It is possible to have Graph tensors leak out of the function building context by including a tf.init_scope in your function building code. For example, the following function will fail: @tf.function def has_init_scope(): my_constant = tf.constant(1.) with tf.init_scope(): added = my_constant * 2 The graph tensor has name: strided_slice:0

**I added a regularization block after each convolution layer.

Here is my code :**


    import keras
    from keras  import datasets, layers, models, optimizers    
    import matplotlib.pyplot as plt
    from keras_drop_block import DropBlock2D

    input_shape = (32,32,3)
    def Build_Model_Block_Drop() : 

        model = models.Sequential()
        model.add(layers.Conv2D(32,(3,3), activation= 'relu', input_shape =input_shape))
        model.add(DropBlock2D(block_size=5, keep_prob=0.8, name='Dropout_Block-1'))
        model.add(layers.Conv2D(64,(3,3), activation='relu'))
        model.add(layers.MaxPool2D((2,2)))
        model.add(DropBlock2D(block_size=5, keep_prob=0.8, name='Dropout_Block-2'))

        model.add(layers.Conv2D(64,(3,3), activation='relu'))
        model.add(DropBlock2D(block_size=5, keep_prob=0.8,name='Dropout_Block-3'))

        model.add(layers.Conv2D(64,(3,3), activation='relu'))
        model.add(layers.MaxPool2D((2,2)))
        model.add(DropBlock2D(block_size=5, keep_prob=0.8, name='Dropout_Block-4'))

        model.add(layers.Flatten())
        model.add(layers.Dense(60,activation='relu'))
        model.add(layers.Dense(64,activation='relu'))
        model.add(layers.Dense(10,activation='softmax'))
                model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',
                                         metrics = ['accuracy'])

        return model