Giter Site home page Giter Site logo

wu9961 / blurredimagedetection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jasonsey/blurredimagedetection

0.0 1.0 0.0 1.72 MB

detecting the blurred image by CNN and decision tree model. build on Keras

License: MIT License

Dockerfile 0.90% Makefile 1.42% Thrift 0.10% Python 97.58%

blurredimagedetection's Introduction

Blurred Image Detection

detecting the blurred image

Recognition effect

Testing on a data set of 214 blurred images and 241 clear images, the F1 score of model's recognition is 0.81. Here are partial outputs.

Project Structure

.
├── data								# data set folder
│   ├── input							# input data folder
│   │   └── License						# input data folder
│   │       ├── Test					# for test
│   │       │   ├── Bad_License
│   │       │   └── Good_License
│   │       └── Train					# for train
│   │           ├── Bad_License
│   │           └── Good_License
│   └── output							# output data folder
│       ├── cache						# cache data folder
│       ├── decision_tree				# decision tree model's model and log folder
│       │   └── models
│       ├── stacking					# stacking model's model and log folder
│       │   └── models
│       └── total_image					# CNN model's model and log folder
│           ├── log
│           └── models
├── docker-compose.yml					# docker compose configuration file
├── Dockerfile
├── Dockerfile.base						# the base dockerfile where the Dockerfile bases
├── interface.thrift					# thrift configuration file
├── Makefile							# pipline for docker container
├── requirements.txt					# dependency packages' information
├── docs
│   └── InterfaceDocument.md			# interface document
└── src									# source code
    ├── api								# api packages
    │   ├── __init__.py
    │   ├── cv2_api
    │   │   ├── __init__.py
    │   │   └── detection.py
    │   ├── decision_tree
    │   │   ├── __init__.py
    │   │   ├── detection.py
    │   │   └── train.py
    │   ├── stacking
    │   │   ├── __init__.py
    │   │   ├── detection.py
    │   │   └── train.py
    │   ├── thrift_api
    │   │   ├── __init__.py
    │   │   ├── interface				# thrift auto-generated folder
    │   └── total_image
    │       ├── __init__.py
    │       ├── detection.py
    │       ├── model.py
    │       └── train.py
    ├── dataset							# tools for reading data set
    │   ├── __init__.py
    │   ├── create_dataset.py
    │   └── read_dataset.py
    ├── deploy							# tools for deployment
    │   ├── __init__.py
    │   ├── detection.py
    │   ├── thrift_client.py
    │   └── thrift_server.py
    ├── utils							# comon tools
    │       ├── __init__.py
    │       ├── callbacks.py
    │       ├── params.py
    │       ├── server_tools.py
    │       └── tools.py
    ├── __main__.py
    ├── main.py							# main entry
    └── config.py						# global configuration file

Project Introduction

The project consists of 3 models, CNN model, decision tree model and stacking model (another decision tree model to connect the two previous output and output the final result)

CNN model

编号 layers filters kernel_size strides padding regularizers activation
1 Conv2D 64 3 1 same l2(0.01) relu
2 Conv2D 64 3 1 same None relu
3 MaxPooling2D - 2 2 - - -
4 Conv2D 64 3 1 same None relu
5 MaxPooling2D - 2 2 - - -
6 Conv2D 64 3 1 same None relu
7 MaxPooling2D - 2 2 - - -
8 Conv2D 64 3 1 same None relu
9 Conv2D 1 3 1 same None relu
10 GlobalAveragePooling2D - - - - - -
11 Activation - - - - - sigmoid

Decision tree model

The inputs of this model are image size, laplacian score and sober score. And the model's deep is set to 3

Stacking model

The inputs of this model are the scores of CNN model and decision tree model. And the model's deep is set to 3 too.

Rules for sample selection

Blurred image classification mainly serves the back-end OCR service, so the judgment of blurring is mainly based on the degree of text clarity. Here are the rules for sample selection.

  1. Clear: The image of less than 2 blurred positions in the text blocks is clear.
  2. Blur: More than 50% of the blurred positions in the text blocks are labeled as blurred.
  3. If the left text blocks are clear (such as operator fields), then it is not included in the statistical range of text block. If most of the left text blocks is blurred, all the left text blocks are added to the statistical range.
  4. Images with complex backgrounds or not business licenses will not be filtered as training samples.

Q&A

How to use the model simply

First, put blurred images into data/input/License/Test/Bad License and put clear images into data/input/License/Test/Good License .

Second, run the following command.

$ cd src && python3.6 main.py test_stacking

Then the command line will show you the performance of the model in your data set.

How to install python dependency packages

Just type the following command.

$ pip3.6 install -r requrements.txt

How to start the blurred image detection service

First, edit the file src/config.py and set your THRIFT_HOST, THRIFT_PORT, THRIFT_NUM_WORKS.

Second, run the following command.

$ cd src && python3.6 main.py server

How to test the started service

First, put blurred images into data/input/License/Test/Bad License and put clear images into data/input/License/Test/Good License .

Second, run the following command.

$ cd src && python3.6 main.py client

How to Design Client Interface

See docs and you will find something you want.

How to train the model with your data set

First, put blurred images into data/input/License/Train/Bad License and put clear images into data/input/License/Train/Good License .

Second, run the following command.

$ cd src && python3.6 main.py train_all

How to use docker

Fist, edit the file src/config.py and set your THRIFT_HOST, THRIFT_PORT, THRIFT_NUM_WORKS

Second, edit the file Makefile and delete the lines docker tag ${base_name} ${remote_base}; docker push ${remote_base}

Third, build the base docker image.

$ make build_base_image

Fourth, run the following command.

$ make up

Then, the service will start automatically.

Other problems

Don't worry, I've commented on the code in detail. If you encounter any training problem, please feel free to contact me.

blurredimagedetection's People

Contributors

jasonsey avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.