Code Monkey home page Code Monkey logo

rectinet's Introduction

PWC

A Gated and Bifurcated Stacked U-Net Module for Document Image Dewarping

Capturing images of documents is one of the easiest and most used methods of recording them. These images however, being captured with the help of handheld devices, often lead to undesirable distortions that are hard to remove. We propose a supervised Gated and Bifurcated Stacked U-Net module to predict a dewarping grid and create a distortion free image from the input. While the network is trained on synthetically warped document images, results are calculated on the basis of real world images. The novelty in our methods exists not only in a bifurcation of the U-Net to help eliminate the intermingling of the grid coordinates, but also in the use of a gated network which adds boundary and other minute line level details to the model. The end-to-end pipeline proposed by us achieves state-of-the-art performance on the DocUNet dataset after being trained on just 8 percent of the data used in previous methods.


Screenshot

Demo

Open In Colab

Requirements

Required packages:

  • torch (>1.4.0)
  • torchvision (>0.6.0)
  • numpy (>1.18.4)

To install all required packages, use pip install -r requirements.txt

Training the model

Required Directory Structure:


.
+-- data_gen
|   +-- .
|   +-- image
|   +-- label
|   +-- image_test
+-- model_save
|   +-- .
+-- loader
|   +-- .
|   +-- __init__.py
|   +-- dataset.py
+-- predict
|   +-- .
|   +-- model_pred.py
|   +-- predict.py
+-- unets
|   +-- .
|   +-- __init__.py
|   +-- Punet.py
|   +-- Sunet.py
+-- utils
|   +-- .
|   +-- __init.py
|   +-- GCN.py
|   +-- plot_me.py
|   +-- utils_model.py
+-- model.py
+-- train.py

  • Run: python3 train.py --batch-size 16
  • For custom location of training data run: python3 train.py --batch-size 16 --data-path PATH_TO_DATA
  • For more parameters run: python3 train.py -help

Dense Grid Prediction and Image Unwarp

  • In same directory: mkdir save
  • Navigate to predict directory cd predict/
    • For predicting single image: python3 predict.py --save-path ../save --img-path IMAGE_PATH --model-path ../model_save/SAVED_MODEL_PATH --multi=False
    • For predicting many image in a folder: python3 predict.py --save-path ../save --img-path IMAGE_FOLDER_PATH --model-path ../model_save/SAVED_MODEL_PATH --multi=True
  • For more parameters: python3 predict.py -help

Generating data

For generating your own dataset, follow this repository. Do note, they use pkl to save the ground truth dense grid while I make use of npz. To get save arrays as npz, just change the way the grid is saved in the generation code.

Note:

  • Please note that we used Matlab 2018b for implementing SSIM (Structural Similarity Index) and MS-SSIM ( Multi-Scale Structural Similarity Index) values. Matlab 2020a, however, uses a different SSIM implementation. Do take that into consideration while comparing your results with the values in our paper.
  • Please use the 'Discussion' option to ask questions about the code instead of raising an issue -- unless it has something to do with an error in the code.

Loading pre-trained Model

  • Download model weights here
  • Save under model_save folder
  • Run: python3 predict.py --save-path save --img-path IMAGE_PATH --model-path model_save/weights.pt --multi=False

Citation

If you use this code please consider citing :

@misc{b2020gated,
    title={A Gated and Bifurcated Stacked U-Net Module for Document Image Dewarping},
    author={Hmrishav Bandyopadhyay and Tanmoy Dasgupta and Nibaran Das and Mita Nasipuri},
    year={2020},
    eprint={2007.09824},
    archivePrefix={arXiv},
    primaryClass={cs.CV}
}

Todo

  • Upload pre-trained weights for predictions
  • Upload Images for Evaluation
  • Increase code readability

rectinet's People

Contributors

hmrishavbandy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

rectinet's Issues

Dataset

Can you add some sample datasets and how it is arranged?

Question about Models

Hi!
I have tried to run your code, but after training the data, I have some questions about the Models.
The project provieded two model, the first one is in the model.py and the second one is in the model_pred.py. When I tried to run the predict.py, it asserted missing keys in state_dict. I checked the code and found different models used in train.py and predict.py.
I guess the code following is trying to import the intersection of two state dict;
File "predict.py", line 108, "state_dict = {k: v for k, v in state_dict.items() if k in model_dict}"
I can predict with the pre_trained model provided, but failed in the model trained by myself. This Block may not work well.

I want to know the difference between the two models and why the project use two model for train and prediect respectively?

About data loading

I I have downloaded the data you provided, but in the dataset.py In, label is. Npz format, but I didn't find this format in the data you provided. Can you tell me how to apply the downloaded data to the code you provided?

Structure of dataset

I am having trouble understanding the directory structure. I have generated the images using the AGUN repository you have linked. However, I am just trying to understand how to use those images in the directory structure. Like which images go in the image folder of datagen ? And which is the label .npz file required.

utils_model does not have any object named initialize_weights

When trying to run train.py I am getting the error that cannot import initialize_weights. On checking the utils_model.py file in utils folder I am finding that there is no function or class named initialize_weights. Is this an error in the branch or something?

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.