vinay0410 / Pedestrian_Detection

Detects Pedestrians in images using HOG as a feature extractor and SVM for classification
GNU General Public License v3.0
73 stars 24 forks source link

train my own model #2

Closed lykhahaha closed 5 years ago

lykhahaha commented 5 years ago

hi vinay0410: thanks for your work, but how can I train my own model ? Is there any requirments for your dataset?

vinay0410 commented 5 years ago

Hi @lykhahaha , I used INRIA dataset for training, and the train.py file is written according to this dataset. I used fixed sized positive images of 64x128 for training and the same size window for hard negative mining. The code assumes, that positive images are in train/pos and negative images are in train/neg. https://github.com/vinay0410/Pedestrian_Detection/blob/625c1830255555376038fb092b488688c9c0e50e/train.py#L9-L10

https://github.com/vinay0410/Pedestrian_Detection/blob/625c1830255555376038fb092b488688c9c0e50e/train.py#L15-L17

I recommend using the same or similar dataset, but if you plan to use a bigger dataset, I would recommend using bigger networks like faster_rcnn, ssd, yolo, etc.

I have some scripts for training them, if you want them just let them know. Some pre-trained models are available here The first one is person only, and I used this tool for evaluation.

lykhahaha commented 5 years ago

hi vinay0410: Thanks for your replay. This is very helpful to me. And I need those training scripts, can you share them with me?

vinay0410 commented 5 years ago

Hi @lykhahaha , I used Tensorflow Object Detection API for training.

Below is the config file for training faster_rcnn based on resnet.

model {
  faster_rcnn {
    num_classes: 1
    image_resizer {
      keep_aspect_ratio_resizer {
        min_dimension: 200
        max_dimension: 900
      }
    }
    feature_extractor {
      type: "faster_rcnn_resnet101"
      first_stage_features_stride: 16
    }
    first_stage_anchor_generator {
      grid_anchor_generator {
        height_stride: 16
        width_stride: 16
        scales: 0.25
        scales: 0.5
        scales: 1.0
        scales: 2.0
        aspect_ratios: 0.5
        aspect_ratios: 1.0
        aspect_ratios: 2.0
      }
    }
    first_stage_box_predictor_conv_hyperparams {
      op: CONV
      regularizer {
        l2_regularizer {
          weight: 0.0
        }
      }
      initializer {
        truncated_normal_initializer {
          stddev: 0.00999999977648
        }
      }
    }
    first_stage_nms_score_threshold: 0.0
    first_stage_nms_iou_threshold: 0.699999988079
    first_stage_max_proposals: 300
    first_stage_localization_loss_weight: 2.0
    first_stage_objectness_loss_weight: 1.0
    initial_crop_size: 14
    maxpool_kernel_size: 2
    maxpool_stride: 2
    second_stage_box_predictor {
      mask_rcnn_box_predictor {
        fc_hyperparams {
          op: FC
          regularizer {
            l2_regularizer {
              weight: 0.0
            }
          }
          initializer {
            variance_scaling_initializer {
              factor: 1.0
              uniform: true
              mode: FAN_AVG
            }
          }
        }
        use_dropout: false
        dropout_keep_probability: 1.0
      }
    }
    second_stage_post_processing {
      batch_non_max_suppression {
        score_threshold: 0.0
        iou_threshold: 0.600000023842
        max_detections_per_class: 100
        max_total_detections: 300
      }
      score_converter: SOFTMAX
    }
    second_stage_localization_loss_weight: 2.0
    second_stage_classification_loss_weight: 1.0
  }
}
train_config {
  batch_size: 1
  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  optimizer {
    momentum_optimizer {
      learning_rate {
        manual_step_learning_rate {
          initial_learning_rate: 0.000300000014249
          schedule {
            step: 0
            learning_rate: 0.000300000014249
          }
          schedule {
            step: 900000
            learning_rate: 2.99999992421e-05
          }
          schedule {
            step: 1200000
            learning_rate: 3.00000010611e-06
          }
        }
      }
      momentum_optimizer_value: 0.899999976158
    }
    use_moving_average: false
  }
  gradient_clipping_by_norm: 10.0
  fine_tune_checkpoint: "../../faster_rcnn_resnet101_coco_2018_01_28/model.ckpt"
  from_detection_checkpoint: true
  num_steps: 200000
}
train_input_reader {
  label_map_path: "../../ILSVRC2013/data/person.pbtxt"
  tf_record_input_reader {
    input_path: "../../ILSVRC2013/data/person_train_ILSVRC2013.record"
  }
}
eval_config {
  use_moving_averages: false
}

If you are not familiar with TensorFlow Object Detection API and need more help with how to proceed with training, just reply with your doubts.

lykhahaha commented 5 years ago

Hi @vinay0410 :+1: Your reply has helped me a lot, thank you again.I will try it right away.

lykhahaha commented 5 years ago

Hi @vinay0410 : I have a try for the INRIA dataset training. The positive images are in 'INRIAPerson/Train/pos/' and the negative images are in 'INRIAPerson/Train/neg/' . when I run the train.py, it got some issues:

ValueError: setting an array element with a sequence. in line157 clf.fit(X, Y)

such as: Traceback (most recent call last): File "G:/PycharmProjects/Pedestrian_Detection_hog_svm/Pedestrian_Detection-master/train.py", line 157, in clf.fit(X, Y) File "D:\anaconda_software\envs\py27\lib\site-packages\sklearn\svm\classes.py", line 229, in fit Images Read and Shuffled Training Started accept_large_sparse=False) File "D:\anaconda_software\envs\py27\lib\site-packages\sklearn\utils\validation.py", line 756, in check_X_y estimator=estimator) File "D:\anaconda_software\envs\py27\lib\site-packages\sklearn\utils\validation.py", line 527, in check_array array = np.asarray(array, dtype=dtype, order=order) File "D:\anaconda_software\envs\py27\lib\site-packages\numpy\core\numeric.py", line 501, in asarray return array(a, dtype, copy=False, order=order) ValueError: setting an array element with a sequence.

vinay0410 commented 5 years ago

Did, you get an output, stating the number of images read, similar to below https://github.com/vinay0410/Pedestrian_Detection/blob/625c1830255555376038fb092b488688c9c0e50e/train.py#L136-L138 Please post all of the output you get ?

lykhahaha commented 5 years ago

yeah,I got :

D:\anaconda_software\envs\py27\python.exe G:/PycharmProjects/Pedestrian_Detection_hog_svm/Pedestrian_Detection-master/train.py Total Positive Images : 614 Total Negative Images : 1218 Reading Images libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: Images Read and Shuffled Training Started Traceback (most recent call last): File "G:/PycharmProjects/Pedestrian_Detection_hog_svm/Pedestrian_Detection-master/train.py", line 159, in clf.fit(X, Y) File "D:\anaconda_software\envs\py27\lib\site-packages\sklearn\svm\classes.py", line 229, in fit accept_large_sparse=False) File "D:\anaconda_software\envs\py27\lib\site-packages\sklearn\utils\validation.py", line 756, in check_X_y estimator=estimator) File "D:\anaconda_software\envs\py27\lib\site-packages\sklearn\utils\validation.py", line 527, in check_array array = np.asarray(array, dtype=dtype, order=order) File "D:\anaconda_software\envs\py27\lib\site-packages\numpy\core\numeric.py", line 501, in asarray return array(a, dtype, copy=False, order=order) ValueError: setting an array element with a sequence. iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile

Process finished with exit code 1

vinay0410 commented 5 years ago

Hi @lykhahaha , I have fixed training. There were issues in the dataset, since it contained very old and broken png files. Also, there were some issues in the code too. For training, please refer the updated Readme and let me know if any errors occur. They probably won't, also please read the Note on Training if you have less RAM in your system.

Thanks for pointing this out !!

lykhahaha commented 5 years ago

Hi @vinay0410 : After my two days of debugging, I finally got the perfect result. It is the reason for the data set. But your new code solves this problem. Thanks again!

vinay0410 commented 5 years ago

I would also like to mention that the new code has better accuracy than previous one. Previous training code had a F1 score of 0.77 on the test dataset, while the new one has an F1 score of 0.87 on the test dataset.

On 31-Dec-2018, at 7:48 AM, lykhahaha notifications@github.com wrote:

Hi @vinay0410 : After my two days of debugging, I finally got the perfect result. It is the reason for the data set. But your new code solves this problem. Thanks again!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

lykhahaha commented 5 years ago

Wow, it’s incredible, great.

vinay0410 commented 5 years ago

Closing, since resolved by 8ca11ca351047c5eb3e7477f57c19bcfe16fd64b

TrungKhoaLe commented 4 years ago

libpng warning: iCCP: known incorrect sRGB profile How does it affect the accuracy of the detection algorithm guys? I met the same problem here, and I'm working around on it to solve the issue.

vinay0410 commented 4 years ago

Hi @TrungKhoaLe , Please read the readme carefully. Some of the png files in INRIA dataset are old/broken. Therefore sudo sh fixpng.sh is necessary to fix these broken images.

Since, these images are broken, they can return incorrect RGB values, when read using OpenCV in this line

Charanjit5145 commented 3 years ago

i am getting the same error at clf1.fit(X,Y)

Charanjit5145 commented 3 years ago

Hi @vinay0410 : After my two days of debugging, I finally got the perfect result. It is the reason for the data set. But your new code solves this problem. Thanks again!

hii can you guide me with the clf1.fit(X,Y) error