Code Monkey home page Code Monkey logo

character-finder's Introduction

Character Finder

Prerequisites

  • Make sure you have the prerequisites for the Object Detection API installed. The directions for installations can be found here
For Santa Claus
  • Download the training images in character-finder/characters directory and evaluation images in the characterfinder/eval_image directory

This only downloads the images for Santa Claus.

Run the following commands

 # Unzip the contents
 # From character-finder/characters
 unzip santa.zip  
 # From character-finder/eval_images
 unzip santa.zip
 
 # From character-finder/
 python change_csv.py
 # This will change the path in the already existing csvs to point to the images in the correct directory
 
For Other Characters
  • Make a new directory in the character-finder/characters folder and name it the character. For example
    mkdir characters/foobar
    Similarly do the same for the evaluation images
    mkdir eval_images/foobar

  • Save all training images for that character in characters/foobar and the evaluation images in eval\_images/foobar

  • Next step is to get bounding box imformation about the characters and store it in a csv which will later be converted to tf.record file. Done for both training and evaluation images.

  • Run the following command

     # For Training Images
     python detect_labels.py --annotation_file PATH_TO_CSV --images characters/
     # For Evaluation Images
     python detect_labels.py --annotation_file PATH_TO_CSV --images eval_images/
    

Note: Already existing train.csv and eval.csv have bounding box information for images of Santa Claus

  • Label the images by clicking on the top left of the characters face first and then on the bottom right

  • Modify the characters_label_map.pbtext file depending on number of characters. For example

     item {
         id: 1
         name: foobar1
     }
     item {
         id: 2
         name: foobar2
     }
    

Generating record files

  • After generating csv, generate the record files
    # Generate training record
    python --csv_input PATH_TO_TRAIN_CSV --output_path PATH_TO_TRAIN.record --label_map_path characters_label_map.pbtext 
     # Generate evaluation record
     python --csv_input PATH_TO_EVAL_CSV --output_path PATH_TO_EVAL.record --label_map_path characters_label_map.pbtext 

Training

For training, construct an object-detection training pipeline.

  • Use any of the config files present in object_detection/samples/configs/ as basis

  • Changes in the .config file:

    1. Adjust the number of classes depending on the number of characters training on 2 It is recommended to train the model from a pre-trained checkpoint. Tensorflow provides several pre-trained checkpoints which can be found here.
      Change the
      fine_tune_checkpoint: "PATH_TO_BE_CONFIGURED/model.ckpt" to point to the checkpoint to be used
    2. In the following Code snippet
      train_input_reader: {
        tf_record_input_reader {
          input_path: "PATH_TO_BE_CONFIGURED/train.record"
        }
        label_map_path: "characters_label_map.pbtxt"
      }
      
      Change the input_path: "PATH_TO_BE_CONFIGURED/train.record" to point to the full path of the train.record file created in the previous step and the label_map_path: "PATH_TO_BE_CONFIGURED/characters_label_map.pbtxt" to point to the full path of the label map.
    3. In the following Code snippet
      eval_input_reader: {
        tf_record_input_reader {
      	    input_path: "PATH_TO_BE_CONFIGURED/eval.record"
        }
        label_map_path: "PATH_TO_BE_CONFIGURED/characters_label_map.pbtxt"
        shuffle: false
        num_readers: 1
        num_epochs: 1
      }
      
      Change the input_path: "PATH_TO_BE_CONFIGURED/eval.record" to point to the full path of the eval.record file created in the previous step and the label_map_path: "PATH_TO_BE_CONFIGURED/characters_label_map.pbtxt" to point to the full path of the label map.
  • Run the training job

     python object_detection/train.py --logtostderr --train_dir PATH_TO_SAVE_CHECKPOINTS --pipeline_config_path PATH_TO_CONFIG_FILE
    
  • It is advised to run the evaluation job simultaneously with the training.

     python object_detection/eval.py --logtostderr --checkpoint_dir PATH_TO_CHECKPOINT_DIR --eval_dir PATH_TO_EVAL_DIR --pipeline_config_path PATH_TO_CONFIG_FILE
    
  • Visualise the training and evaluation by running the folowing command

     tensorboard --logdir PATH_TO_CHECKPOINT_DIR
    

Exporting the model

  • To export the model, choose a checkpoint # to export. For example to export checkpoint no. 130912
     python object_detection/export_inference_graph --input_type image_tensor --pipeline_congif_path PATH_TO_CONFIG_FILE --trained_checkpoint_prefix PATH_TO_CHECKPOINT/model.ckpt-130912 --output_directory PATH_TO_EXPORT_MODEL
    

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.