mindspore/model_zoo/official/cv/cnn_direction_model
panfengfeng d72feda64b fix cnn efficientnet bugs 2021-02-07 17:37:35 +08:00
..
scripts fix cnn efficientnet bugs 2021-02-07 17:37:35 +08:00
src copyright fixing 2021-01-20 11:28:31 -05:00
README.md copyright fixing 2021-01-20 11:28:31 -05:00
eval.py copyright fixing 2021-01-20 11:28:31 -05:00
requirements.txt cnn direction model 2020-12-02 14:56:38 -05:00
train.py fix cnn efficientnet bugs 2021-02-07 17:37:35 +08:00

README.md

Contents

CNN-Direction-Model Description

CNN Direction Model is a model designed to perform binary classification of text images on whether the text in the image is going from left-to-right or right-to-left.

Model Architecture

CNN Direction Model's composition consists of 1 convolutional layer and 4 residual blocks for feature extraction. The feature extraction stage is then followed by 3 dense layers to perform the classification.

Dataset

Dataset used: FSNS (French Street Name Signs)

  • Dataset size~200GB~1M 150*600 colored images with a label indicating the text within the image.

    • Train200GB1M, images
    • Test4GB24,404 images
  • Data formatbinary files

    • NoteData will be processed in dataset.py
  • Download the dataset, the recommended directory structure to have is as follows:

Annotations for training and testing should be in test_annot and train_annot. Training and Testing images should be in train and test.

├─test
│
└─test_annot
│
└─train
│
└─train_annot
  • After downloading the data and converting it to it's raw format (.txt for annotations and .jpg, .jpeg, or .png for the images), add the image and annotations paths to the src/config.py file then cd to src and run:
python create_mindrecord.py

This will create two folders: train and test in the target directory you specify in config.py.

Environment Requirements

Quick Start

After installing MindSpore via the official website, you can start training and evaluation as follows:

# enter script dir, train CNNDirectionModel
sh run_standalone_train.sh [DATASET_PATH] [PRETRAINED_CKPT_PATH](optional)
# enter script dir, evaluate CNNDirectionModel
sh run_standalone_train.sh [DATASET_PATH] [PRETRAINED_CKPT_PATH]

Script Description

Script and Sample Code

├── cv
    ├── cnn_direction_model
        ├── README.md                    // descriptions about cnn_direction_model
        ├── requirements.txt             // packages needed
        ├── scripts
        │   ├──run_distribute_train_ascend.sh          // distributed training in ascend
        │   ├──run_standalone_eval_ascend.sh             //  evaluate in ascend
        │   ├──run_standalone_train_ascend.sh          //  train standalone in ascend
        ├── src
        │   ├──dataset.py             // creating dataset
        │   ├──cnn_direction_model.py              // cnn_direction_model architecture
        │   ├──config.py            // parameter configuration
        │   ├──create_mindrecord.py            // convert raw data to mindrecords
        ├── train.py               // training script
        ├── eval.py               //  evaluation script

Script Parameters

Major parameters in config.py as follows:

--data_root_train: The path to the raw training data images for conversion to mindrecord script.
--data_root_test: The path to the raw test data images for conversion to mindrecord script.
--test_annotation_file: The path to the raw training annotation file.
--train_annotation_file: The path to the raw test annotation file.
--mindrecord_dir: The path to which create_mindrecord.py uses to save the resulting mindrecords for training and testing.
--epoch_size: Total training epochs.
--batch_size: Training batch size.
--im_size_h: Image height used as input to the model.
--im_size_w: Image width used as input the model.

Training Process

Training

  • running on Ascend

    sh run_standalone_train_ascend.sh path-to-train-mindrecords pre-trained-chkpt(optional)
    

    The model checkpoint will be saved script/train.

Evaluation Process

Evaluation

Before running the command below, please check the checkpoint path used for evaluation.

  • running on Ascend

    sh run_standalone_eval_ascend.sh path-to-test-mindrecords trained-chkpt-path
    

Results of evaluation will be printed after evaluation process is completed.

Model Description

Performance

Evaluation Performance

Parameters Ascend
Resource Ascend 910; CPU 2.60GHz, 192cores; Memory, 755G
uploaded Date 01/15/2021 (month/day/year)
MindSpore Version 1.1
Dataset FSNS
Training Parameters epoch=1, steps=104,477, batch_size = 20, lr=1e-07
Optimizer Adam
Loss Function Softmax Cross Entropy
outputs top 1 accuracy
Overall accuracy 91.72%
Speed 583 ms/step
Total time 17 hours

Description of Random Situation

In train.py, we set some seeds before training.

ModelZoo Homepage

Please check the official homepage.