diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 7f0f3ad..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,46 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. - -Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at vishal27.rs@outlook.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 175d5f6..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,21 +0,0 @@ -Contributing -============ - -If you would like to contribute code, documentation, or other assets you can do so through GitHub by forking the repository and sending a pull request (PR). You can also simply report issues (bugs), but please search for any previous reports first. - -*When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible.* - -File an Issue -------------- -You can report bugs and feature requests to [GitHub Issues](https://github.com/Abhinaay/Hamara-Paryatan-Katai-Jahar/issues). As mentioned please look for a similar existing issue before submitting a new one. -Label issues with the corrsponding [labels](https://github.com/Abhinaay/Hamara-Paryatan-Katai-Jahar/labels) - -How to Submit a Pull Request ----------------------------- -Pull requests are highly appreciated! Please follow the simple guidelines below. - -1. Fork the repository to your personal GitHub account. -1. Create a topic branch for every separate change you make. The branch should have a short but explanatory name, such as "AddedEmailColumn". -1. Apply your changes, committing at logical breaks. Make sure your changes are well-tested. -1. Push your branch to your personal account and [create a pull request](https://help.github.com/articles/using-pull-requests/). -1. Watch for comments or acceptance on your PR. The PR can be updated by just pushing to the original branch. diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 2a34b45..0000000 --- a/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,21 +0,0 @@ - - -### Contains - -Brief description of what the PR does like "Fixes #12345" - -### How to test - -Brief description of how to test / confirm this PR before merging - -### Outstanding before merging - -If anything. You can use neat checkboxes! Feel free to delete if not needed - -- [ ] Make corresponding updates in comments diff --git a/checkpoint b/checkpoint new file mode 100644 index 0000000..febd7d5 --- /dev/null +++ b/checkpoint @@ -0,0 +1,2 @@ +model_checkpoint_path: "model.ckpt" +all_model_checkpoint_paths: "model.ckpt" diff --git a/detection.py b/detection.py new file mode 100644 index 0000000..25dfc98 --- /dev/null +++ b/detection.py @@ -0,0 +1,90 @@ + +import numpy as np +import tensorflow as tf +import cv2 +import time +import msvcrt + + +video='TownCentreXVID.avi' + +class DetectorAPI: + def __init__(self, path_to_ckpt): + self.path_to_ckpt = path_to_ckpt + + self.detection_graph = tf.Graph() + with self.detection_graph.as_default(): + od_graph_def = tf.compat.v1.GraphDef() + with tf.io.gfile.GFile(self.path_to_ckpt, 'rb') as fid: + serialized_graph = fid.read() + od_graph_def.ParseFromString(serialized_graph) + tf.import_graph_def(od_graph_def, name='') + + self.default_graph = self.detection_graph.as_default() + self.sess = tf.compat.v1.Session(graph=self.detection_graph) + + # Definite input and output Tensors for detection_graph + self.image_tensor = self.detection_graph.get_tensor_by_name('image_tensor:0') + # Each box represents a part of the image where a particular object was detected. + self.detection_boxes = self.detection_graph.get_tensor_by_name('detection_boxes:0') + # Each score represent how level of confidence for each of the objects. + # Score is shown on the result image, together with the class label. + self.detection_scores = self.detection_graph.get_tensor_by_name('detection_scores:0') + self.detection_classes = self.detection_graph.get_tensor_by_name('detection_classes:0') + self.num_detections = self.detection_graph.get_tensor_by_name('num_detections:0') + + def processFrame(self, image): + # Expand dimensions since the trained_model expects images to have shape: [1, None, None, 3] + image_np_expanded = np.expand_dims(image, axis=0) + # Actual detection. + start_time = time.time() + (boxes, scores, classes, num) = self.sess.run( + [self.detection_boxes, self.detection_scores, self.detection_classes, self.num_detections], + feed_dict={self.image_tensor: image_np_expanded}) + end_time = time.time() + + #print("Elapsed Time:", end_time-start_time) + + im_height, im_width,_ = image.shape + boxes_list = [None for i in range(boxes.shape[1])] + for i in range(boxes.shape[1]): + boxes_list[i] = (int(boxes[0,i,0] * im_height), + int(boxes[0,i,1]*im_width), + int(boxes[0,i,2] * im_height), + int(boxes[0,i,3]*im_width)) + + return boxes_list, scores[0].tolist(), [int(x) for x in classes[0].tolist()], int(num[0]) + + def close(self): + self.sess.close() + self.default_graph.close() + +if __name__ == "__main__": + model_path = 'frozen_inference_graph.pb' + odapi = DetectorAPI(path_to_ckpt=model_path) + threshold = 0.7 + cap = cv2.VideoCapture(video) + print("Press ESC key to exit the program ") + while True: + r, img = cap.read() + img = cv2.resize(img, (1280, 720)) + + boxes, scores, classes, num = odapi.processFrame(img) + # Visualization of the results of a detection. + count=0 + for i in range(len(boxes)): + # Class 1 represents human + if classes[i] == 1 and scores[i] > threshold: + box = boxes[i] + cv2.rectangle(img,(box[1],box[0]),(box[3],box[2]),(255,0,255),2) + count+=1 + print("NO of Humans are",count) + + cv2.imshow("preview", img) + if cv2.waitKey(10) & 0xff==ord('q'): + break + + + cv2.destroyAllWindows() + cap.release() + print("BYEBYE") diff --git a/frozen_inference_graph.pb b/frozen_inference_graph.pb new file mode 100644 index 0000000..e0f7580 Binary files /dev/null and b/frozen_inference_graph.pb differ diff --git a/model.ckpt.data-00000-of-00001 b/model.ckpt.data-00000-of-00001 new file mode 100644 index 0000000..af3f42e Binary files /dev/null and b/model.ckpt.data-00000-of-00001 differ diff --git a/model.ckpt.index b/model.ckpt.index new file mode 100644 index 0000000..cf790e0 Binary files /dev/null and b/model.ckpt.index differ diff --git a/model.ckpt.meta b/model.ckpt.meta new file mode 100644 index 0000000..b9f0cdf Binary files /dev/null and b/model.ckpt.meta differ diff --git a/pipeline.config b/pipeline.config new file mode 100644 index 0000000..f5ec9dc --- /dev/null +++ b/pipeline.config @@ -0,0 +1,134 @@ +model { + faster_rcnn { + num_classes: 90 + image_resizer { + keep_aspect_ratio_resizer { + min_dimension: 600 + max_dimension: 1024 + } + } + feature_extractor { + type: "faster_rcnn_inception_v2" + 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: 100 + 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.300000011921 + iou_threshold: 0.600000023842 + max_detections_per_class: 100 + max_total_detections: 100 + } + 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.000199999994948 + schedule { + step: 0 + learning_rate: 0.000199999994948 + } + schedule { + step: 900000 + learning_rate: 1.99999994948e-05 + } + schedule { + step: 1200000 + learning_rate: 1.99999999495e-06 + } + } + } + momentum_optimizer_value: 0.899999976158 + } + use_moving_average: false + } + gradient_clipping_by_norm: 10.0 + fine_tune_checkpoint: "PATH_TO_BE_CONFIGURED/model.ckpt" + from_detection_checkpoint: true + num_steps: 200000 +} +train_input_reader { + label_map_path: "PATH_TO_BE_CONFIGURED/mscoco_label_map.pbtxt" + tf_record_input_reader { + input_path: "PATH_TO_BE_CONFIGURED/mscoco_train.record" + } +} +eval_config { + num_examples: 8000 + max_evals: 10 + use_moving_averages: false +} +eval_input_reader { + label_map_path: "PATH_TO_BE_CONFIGURED/mscoco_label_map.pbtxt" + shuffle: false + num_readers: 1 + tf_record_input_reader { + input_path: "PATH_TO_BE_CONFIGURED/mscoco_val.record" + } +} diff --git a/saved_model/saved_model.pb b/saved_model/saved_model.pb new file mode 100644 index 0000000..500ac7b Binary files /dev/null and b/saved_model/saved_model.pb differ