├── .gitignore
├── README.md
├── attendance.txt
├── classifier
├── FaceClassifier.py
├── __init__.py
└── trained_classifier.pkl
├── demo_face_detect.py
├── demo_face_recognition.py
├── detection
├── FaceDetector.py
├── FaceDetector_tiny.py
├── __init__.py
├── configs
│ ├── face.pbtxt
│ ├── faster_rcnn_inception_resnet_v2_large.config
│ ├── faster_rcnn_inception_resnet_v2_small.config
│ ├── mask_rcnn_small.config
│ ├── pipeline.config
│ ├── ssdlite_mobilenet_v2.config
│ └── ssdlite_mobilenet_v2_small.config
├── inference_video_face.py
├── protos
│ ├── __init__.py
│ ├── face_label_map.pbtxt
│ └── string_int_label_map_pb2.py
└── utils
│ ├── __init__.py
│ ├── label_map_util.py
│ └── visualization_utils_color.py
├── example
├── detect_face.py
└── get_face_descriptor.py
├── facenet
├── .gitignore
├── .project
├── .pydevproject
├── .pylintrc
├── .travis.yml
├── LICENSE.md
├── README.md
├── __init__.py
├── contributed
│ ├── __init__.py
│ ├── batch_represent.py
│ ├── cluster.py
│ ├── clustering.py
│ ├── export_embeddings.py
│ ├── face.py
│ ├── predict.py
│ └── real_time_face_recognition.py
├── data
│ ├── learning_rate_retrain_tripletloss.txt
│ ├── learning_rate_schedule_classifier_casia.txt
│ ├── learning_rate_schedule_classifier_msceleb.txt
│ ├── learning_rate_schedule_classifier_vggface2.txt
│ └── pairs.txt
├── requirements.txt
├── src
│ ├── __init__.py
│ ├── align
│ │ ├── __init__.py
│ │ ├── align_dataset_mtcnn.py
│ │ ├── det1.npy
│ │ ├── det2.npy
│ │ ├── det3.npy
│ │ └── detect_face.py
│ ├── calculate_filtering_metrics.py
│ ├── classifier.py
│ ├── compare.py
│ ├── decode_msceleb_dataset.py
│ ├── download_and_extract.py
│ ├── facenet.py
│ ├── freeze_graph.py
│ ├── generative
│ │ ├── __init__.py
│ │ ├── calculate_attribute_vectors.py
│ │ ├── models
│ │ │ ├── __init__.py
│ │ │ ├── dfc_vae.py
│ │ │ ├── dfc_vae_large.py
│ │ │ ├── dfc_vae_resnet.py
│ │ │ └── vae_base.py
│ │ ├── modify_attribute.py
│ │ └── train_vae.py
│ ├── lfw.py
│ ├── models
│ │ ├── __init__.py
│ │ ├── dummy.py
│ │ ├── inception_resnet_v1.py
│ │ ├── inception_resnet_v2.py
│ │ ├── mobilenet
│ │ │ ├── README.md
│ │ │ ├── __init__.py
│ │ │ ├── conv_blocks.py
│ │ │ ├── mobilenet.py
│ │ │ ├── mobilenet_example.ipynb
│ │ │ ├── mobilenet_v2.py
│ │ │ └── mobilenet_v2_test.py
│ │ ├── mobilenet_v2.py
│ │ └── squeezenet.py
│ ├── train_softmax.py
│ ├── train_softmax_estimator.py
│ ├── train_tripletloss.py
│ └── validate_on_lfw.py
├── test
│ ├── batch_norm_test.py
│ ├── center_loss_test.py
│ ├── restore_test.py
│ ├── train_test.py
│ └── triplet_loss_test.py
├── tmp
│ ├── __init__.py
│ ├── align_dataset.m
│ ├── align_dataset.py
│ ├── align_dlib.py
│ ├── cacd2000_split_identities.py
│ ├── dataset_read_speed.py
│ ├── deepdream.py
│ ├── detect_face_v1.m
│ ├── detect_face_v2.m
│ ├── download_vgg_face_dataset.py
│ ├── funnel_dataset.py
│ ├── invariance_test.txt
│ ├── mnist_center_loss.py
│ ├── mnist_noise_labels.py
│ ├── mtcnn.py
│ ├── mtcnn_test.py
│ ├── mtcnn_test_pnet_dbg.py
│ ├── network.py
│ ├── nn2.py
│ ├── nn3.py
│ ├── nn4.py
│ ├── nn4_small2_v1.py
│ ├── random_test.py
│ ├── rename_casia_directories.py
│ ├── seed_test.py
│ ├── select_triplets_test.py
│ ├── test1.py
│ ├── test_align.py
│ ├── test_invariance_on_lfw.py
│ ├── vggface16.py
│ ├── vggverydeep19.py
│ ├── visualize.py
│ ├── visualize_vgg_model.py
│ └── visualize_vggface.py
└── util
│ └── plot_learning_curves.m
├── g3docs
├── Experimentation.md
├── avatar.png
├── face_recognition_pipeline.md
├── facenet.md
├── facenet_train_pipeline.md
├── getting-started.md
├── installing_dependencies.md
├── layers_usage.md
├── model-zoo.md
├── object_detection_pipeline.md
└── slim_usage.md
├── generating_more_images.py
├── install_scripts
├── 1-setup-environment.sh
├── 2-conda.sh
├── 3-tf-object-detection.sh
├── 4-misc-pip.sh
├── requirments.txt
└── zshrc-exports
├── mtcnn-face
└── face-recognition
│ ├── README.md
│ ├── data_augmentation.py
│ ├── dataset_creation.py
│ └── face_detection.py
├── object_detection
├── .ipynb_checkpoints
│ ├── metrics-checkpoint.csv
│ └── object_detection_tutorial-checkpoint.ipynb
├── README.md
├── __init__.py
├── anchor_generators
│ ├── __init__.py
│ ├── grid_anchor_generator.py
│ ├── grid_anchor_generator_test.py
│ ├── multiple_grid_anchor_generator.py
│ ├── multiple_grid_anchor_generator_test.py
│ ├── multiscale_grid_anchor_generator.py
│ └── multiscale_grid_anchor_generator_test.py
├── api_README.md
├── box_coders
│ ├── __init__.py
│ ├── faster_rcnn_box_coder.py
│ ├── faster_rcnn_box_coder_test.py
│ ├── keypoint_box_coder.py
│ ├── keypoint_box_coder_test.py
│ ├── mean_stddev_box_coder.py
│ ├── mean_stddev_box_coder_test.py
│ ├── square_box_coder.py
│ └── square_box_coder_test.py
├── builders
│ ├── __init__.py
│ ├── anchor_generator_builder.py
│ ├── anchor_generator_builder_test.py
│ ├── box_coder_builder.py
│ ├── box_coder_builder_test.py
│ ├── box_predictor_builder.py
│ ├── box_predictor_builder_test.py
│ ├── dataset_builder.py
│ ├── dataset_builder_test.py
│ ├── graph_rewriter_builder.py
│ ├── graph_rewriter_builder_test.py
│ ├── hyperparams_builder.py
│ ├── hyperparams_builder_test.py
│ ├── image_resizer_builder.py
│ ├── image_resizer_builder_test.py
│ ├── input_reader_builder.py
│ ├── input_reader_builder_test.py
│ ├── losses_builder.py
│ ├── losses_builder_test.py
│ ├── matcher_builder.py
│ ├── matcher_builder_test.py
│ ├── model_builder.py
│ ├── model_builder_test.py
│ ├── optimizer_builder.py
│ ├── optimizer_builder_test.py
│ ├── post_processing_builder.py
│ ├── post_processing_builder_test.py
│ ├── preprocessor_builder.py
│ ├── preprocessor_builder_test.py
│ ├── region_similarity_calculator_builder.py
│ └── region_similarity_calculator_builder_test.py
├── constants.py
├── core
│ ├── __init__.py
│ ├── anchor_generator.py
│ ├── balanced_positive_negative_sampler.py
│ ├── balanced_positive_negative_sampler_test.py
│ ├── batcher.py
│ ├── batcher_test.py
│ ├── box_coder.py
│ ├── box_coder_test.py
│ ├── box_list.py
│ ├── box_list_ops.py
│ ├── box_list_ops_test.py
│ ├── box_list_test.py
│ ├── box_predictor.py
│ ├── box_predictor_test.py
│ ├── data_decoder.py
│ ├── data_parser.py
│ ├── keypoint_ops.py
│ ├── keypoint_ops_test.py
│ ├── losses.py
│ ├── losses_test.py
│ ├── matcher.py
│ ├── matcher_test.py
│ ├── minibatch_sampler.py
│ ├── minibatch_sampler_test.py
│ ├── model.py
│ ├── post_processing.py
│ ├── post_processing_test.py
│ ├── prefetcher.py
│ ├── prefetcher_test.py
│ ├── preprocessor.py
│ ├── preprocessor_cache.py
│ ├── preprocessor_test.py
│ ├── region_similarity_calculator.py
│ ├── region_similarity_calculator_test.py
│ ├── standard_fields.py
│ ├── target_assigner.py
│ └── target_assigner_test.py
├── data_decoders
│ ├── __init__.py
│ ├── tf_example_decoder.py
│ └── tf_example_decoder_test.py
├── dataset_tools
│ ├── __init__.py
│ ├── check_validity.py
│ ├── create_coco_tf_record.py
│ ├── create_coco_tf_record_test.py
│ ├── create_kitti_tf_record.py
│ ├── create_kitti_tf_record_test.py
│ ├── create_oid_tf_record.py
│ ├── create_pascal_tf_record.py
│ ├── create_pascal_tf_record_test.py
│ ├── create_pet_tf_record.py
│ ├── create_tf_records_faces.py
│ ├── create_tf_records_satelite.py
│ ├── download_and_preprocess_mscoco.sh
│ ├── oid_tfrecord_creation.py
│ └── oid_tfrecord_creation_test.py
├── eval.py
├── eval_util.py
├── eval_util_test.py
├── evaluator.py
├── export_inference_graph.py
├── export_latest_inference_graph.py
├── exporter.py
├── exporter_test.py
├── faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28
│ ├── checkpoint
│ └── pipeline.config
├── faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28_tf_14
│ ├── checkpoint
│ └── pipeline.config
├── g3doc
│ ├── configuring_jobs.md
│ ├── defining_your_own_model.md
│ ├── detection_model_zoo.md
│ ├── evaluation_protocols.md
│ ├── exporting_models.md
│ ├── faq.md
│ ├── installation.md
│ ├── instance_segmentation.md
│ ├── oid_inference_and_evaluation.md
│ ├── preparing_inputs.md
│ ├── running_locally.md
│ ├── running_notebook.md
│ ├── running_on_cloud.md
│ ├── running_pets.md
│ └── using_your_own_dataset.md
├── inference
│ ├── __init__.py
│ ├── cell_images_run.py
│ ├── data_infer_batch.py
│ ├── data_infer_batch_test.py
│ ├── detection_inference.py
│ ├── detection_inference_test.py
│ ├── faster_rcnn_batch
│ │ ├── 104001000FB77500.sh
│ │ ├── 1040010018255600.sh
│ │ ├── 104001002F3A8700.sh
│ │ ├── 10400100305A7E00.sh
│ │ └── run.sh
│ ├── infer_detections.py
│ ├── infer_detections_batch.py
│ ├── mask_rcnn_batch
│ │ ├── 104001000FB77500.sh
│ │ ├── 1040010010608200.sh
│ │ ├── 1040010018255600.sh
│ │ ├── 104001002F3A8700.sh
│ │ ├── 10400100305A7E00.sh
│ │ └── run.sh
│ ├── queue-runners.py
│ ├── random_1.py
│ ├── run.sh
│ ├── run_data_infer_batch_test.sh
│ ├── run_inference_image.py
│ └── sat_batch_infer.py
├── inputs.py
├── inputs_test.py
├── matchers
│ ├── __init__.py
│ ├── argmax_matcher.py
│ ├── argmax_matcher_test.py
│ ├── bipartite_matcher.py
│ └── bipartite_matcher_test.py
├── meta_architectures
│ ├── __init__.py
│ ├── faster_rcnn_meta_arch.py
│ ├── faster_rcnn_meta_arch_test.py
│ ├── faster_rcnn_meta_arch_test_lib.py
│ ├── rfcn_meta_arch.py
│ ├── rfcn_meta_arch_test.py
│ ├── ssd_meta_arch.py
│ └── ssd_meta_arch_test.py
├── metrics.csv
├── metrics
│ ├── __init__.py
│ ├── coco_evaluation.py
│ ├── coco_evaluation_test.py
│ ├── coco_tools.py
│ ├── coco_tools_test.py
│ ├── offline_eval_map_corloc.py
│ ├── offline_eval_map_corloc_test.py
│ ├── offline_per_image_eval_map_corloc.py
│ ├── tf_example_parser.py
│ └── tf_example_parser_test.py
├── model_hparams.py
├── model_lib.py
├── model_lib_test.py
├── model_main.py
├── model_tpu_main.py
├── models
│ ├── __init__.py
│ ├── embedded_ssd_mobilenet_v1_feature_extractor.py
│ ├── embedded_ssd_mobilenet_v1_feature_extractor_test.py
│ ├── faster_rcnn_inception_resnet_v2_feature_extractor.py
│ ├── faster_rcnn_inception_resnet_v2_feature_extractor_test.py
│ ├── faster_rcnn_inception_v2_feature_extractor.py
│ ├── faster_rcnn_inception_v2_feature_extractor_test.py
│ ├── faster_rcnn_mobilenet_v1_feature_extractor.py
│ ├── faster_rcnn_mobilenet_v1_feature_extractor_test.py
│ ├── faster_rcnn_nas_feature_extractor.py
│ ├── faster_rcnn_nas_feature_extractor_test.py
│ ├── faster_rcnn_pnas_feature_extractor.py
│ ├── faster_rcnn_pnas_feature_extractor_test.py
│ ├── faster_rcnn_resnet_v1_feature_extractor.py
│ ├── faster_rcnn_resnet_v1_feature_extractor_test.py
│ ├── faster_rcnn_xception_feature_extractor.py
│ ├── faster_rcnn_xception_feature_extractor_test.py
│ ├── feature_map_generators.py
│ ├── feature_map_generators_test.py
│ ├── ssd_feature_extractor_test.py
│ ├── ssd_inception_v2_feature_extractor.py
│ ├── ssd_inception_v2_feature_extractor_test.py
│ ├── ssd_inception_v3_feature_extractor.py
│ ├── ssd_inception_v3_feature_extractor_test.py
│ ├── ssd_mobilenet_v1_feature_extractor.py
│ ├── ssd_mobilenet_v1_feature_extractor_test.py
│ ├── ssd_mobilenet_v2_feature_extractor.py
│ ├── ssd_mobilenet_v2_feature_extractor_test.py
│ ├── ssd_resnet_v1_fpn_feature_extractor.py
│ ├── ssd_resnet_v1_fpn_feature_extractor_test.py
│ └── ssd_resnet_v1_fpn_feature_extractor_testbase.py
├── object_detection_tutorial.ipynb
├── protos
│ ├── __init__.py
│ ├── anchor_generator.proto
│ ├── anchor_generator_pb2.py
│ ├── argmax_matcher.proto
│ ├── argmax_matcher_pb2.py
│ ├── bipartite_matcher.proto
│ ├── bipartite_matcher_pb2.py
│ ├── box_coder.proto
│ ├── box_coder_pb2.py
│ ├── box_predictor.proto
│ ├── box_predictor_pb2.py
│ ├── eval.proto
│ ├── eval_pb2.py
│ ├── faster_rcnn.proto
│ ├── faster_rcnn_box_coder.proto
│ ├── faster_rcnn_box_coder_pb2.py
│ ├── faster_rcnn_pb2.py
│ ├── graph_rewriter.proto
│ ├── graph_rewriter_pb2.py
│ ├── grid_anchor_generator.proto
│ ├── grid_anchor_generator_pb2.py
│ ├── hyperparams.proto
│ ├── hyperparams_pb2.py
│ ├── image_resizer.proto
│ ├── image_resizer_pb2.py
│ ├── input_reader.proto
│ ├── input_reader_pb2.py
│ ├── keypoint_box_coder.proto
│ ├── keypoint_box_coder_pb2.py
│ ├── losses.proto
│ ├── losses_pb2.py
│ ├── matcher.proto
│ ├── matcher_pb2.py
│ ├── mean_stddev_box_coder.proto
│ ├── mean_stddev_box_coder_pb2.py
│ ├── model.proto
│ ├── model_pb2.py
│ ├── multiscale_anchor_generator.proto
│ ├── multiscale_anchor_generator_pb2.py
│ ├── optimizer.proto
│ ├── optimizer_pb2.py
│ ├── pipeline.proto
│ ├── pipeline_pb2.py
│ ├── post_processing.proto
│ ├── post_processing_pb2.py
│ ├── preprocessor.proto
│ ├── preprocessor_pb2.py
│ ├── region_similarity_calculator.proto
│ ├── region_similarity_calculator_pb2.py
│ ├── square_box_coder.proto
│ ├── square_box_coder_pb2.py
│ ├── ssd.proto
│ ├── ssd_anchor_generator.proto
│ ├── ssd_anchor_generator_pb2.py
│ ├── ssd_pb2.py
│ ├── string_int_label_map.proto
│ ├── string_int_label_map_pb2.py
│ ├── train.proto
│ └── train_pb2.py
├── samples
│ ├── cloud
│ │ └── cloud.yml
│ └── configs
│ │ ├── embedded_ssd_mobilenet_v1_coco.config
│ │ ├── faster_rcnn_inception_resnet_v2_atrous_coco.config
│ │ ├── faster_rcnn_inception_resnet_v2_atrous_cosine_lr_coco.config
│ │ ├── faster_rcnn_inception_resnet_v2_atrous_oid.config
│ │ ├── faster_rcnn_inception_resnet_v2_atrous_pets.config
│ │ ├── faster_rcnn_inception_resnet_v2_satellite.config
│ │ ├── faster_rcnn_inception_v2_coco.config
│ │ ├── faster_rcnn_inception_v2_pets.config
│ │ ├── faster_rcnn_nas_coco.config
│ │ ├── faster_rcnn_resnet101_atrous_coco.config
│ │ ├── faster_rcnn_resnet101_ava_v2.1.config
│ │ ├── faster_rcnn_resnet101_coco.config
│ │ ├── faster_rcnn_resnet101_kitti.config
│ │ ├── faster_rcnn_resnet101_pets.config
│ │ ├── faster_rcnn_resnet101_voc07.config
│ │ ├── faster_rcnn_resnet152_coco.config
│ │ ├── faster_rcnn_resnet152_pets.config
│ │ ├── faster_rcnn_resnet50_coco.config
│ │ ├── faster_rcnn_resnet50_pets.config
│ │ ├── mask_rcnn_inception_resnet_v2_atrous_coco.config
│ │ ├── mask_rcnn_inception_v2_coco.config
│ │ ├── mask_rcnn_resnet101_atrous_coco.config
│ │ ├── mask_rcnn_resnet101_pets.config
│ │ ├── mask_rcnn_resnet50_atrous_coco.config
│ │ ├── rfcn_resnet101_coco.config
│ │ ├── rfcn_resnet101_pets.config
│ │ ├── ssd_inception_v2_coco.config
│ │ ├── ssd_inception_v2_pets.config
│ │ ├── ssd_inception_v3_pets.config
│ │ ├── ssd_mobilenet_v1_coco.config
│ │ ├── ssd_mobilenet_v1_focal_loss_coco.config
│ │ ├── ssd_mobilenet_v1_focal_loss_pets.config
│ │ ├── ssd_mobilenet_v1_pets.config
│ │ ├── ssd_mobilenet_v2_coco.config
│ │ ├── ssdlite_mobilenet_v1_coco.config
│ │ └── ssdlite_mobilenet_v2_coco.config
├── test.py
├── test_images
│ ├── get_images.sh
│ └── image_info.txt
├── train.py
├── trainer.py
├── trainer_test.py
├── utils
│ ├── __init__.py
│ ├── category_util.py
│ ├── category_util_test.py
│ ├── config_util.py
│ ├── config_util_test.py
│ ├── context_manager.py
│ ├── context_manager_test.py
│ ├── dataset_util.py
│ ├── dataset_util_test.py
│ ├── examine_graph.py
│ ├── export_faster_rcnn_incpetion_v2_atrous.sh
│ ├── json_utils.py
│ ├── json_utils_test.py
│ ├── label_map_util.py
│ ├── label_map_util_test.py
│ ├── learning_schedules.py
│ ├── learning_schedules_test.py
│ ├── metrics.py
│ ├── metrics_test.py
│ ├── np_box_list.py
│ ├── np_box_list_ops.py
│ ├── np_box_list_ops_test.py
│ ├── np_box_list_test.py
│ ├── np_box_mask_list.py
│ ├── np_box_mask_list_ops.py
│ ├── np_box_mask_list_ops_test.py
│ ├── np_box_mask_list_test.py
│ ├── np_box_ops.py
│ ├── np_box_ops_test.py
│ ├── np_mask_ops.py
│ ├── np_mask_ops_test.py
│ ├── object_detection_evaluation.py
│ ├── object_detection_evaluation_test.py
│ ├── ops.py
│ ├── ops_test.py
│ ├── per_image_custom_evaluation.py
│ ├── per_image_evaluation.py
│ ├── per_image_evaluation_test.py
│ ├── per_image_vrd_evaluation.py
│ ├── per_image_vrd_evaluation_test.py
│ ├── shape_utils.py
│ ├── shape_utils_test.py
│ ├── static_shape.py
│ ├── static_shape_test.py
│ ├── test_case.py
│ ├── test_utils.py
│ ├── test_utils_test.py
│ ├── variables_helper.py
│ ├── variables_helper_test.py
│ ├── visualization_utils.py
│ └── visualization_utils_test.py
├── visualisation_configs
│ ├── eval.config
│ ├── faster_rcnn
│ │ └── input_reader.config
│ └── mask_rcnn
│ │ └── input_reader.config
└── visualise_outputs.py
├── pycocotools
├── __init__.py
├── _mask.c
├── _mask.cpython-35m-x86_64-linux-gnu.so
├── _mask.cpython-36m-x86_64-linux-gnu.so
├── _mask.pyx
├── coco.py
├── coco.py.bak
├── cocoeval.py
├── cocoeval.py.bak
└── mask.py
├── recognition
├── FaceRecognition.py
├── __init__.py
├── facenet.py
└── model
│ ├── det1.npy
│ ├── det2.npy
│ └── det3.npy
├── register_face.py
├── rot_and_flip.py
├── slim
├── BUILD
├── README.md
├── WORKSPACE
├── __init__.py
├── datasets
│ ├── __init__.py
│ ├── build_imagenet_data.py
│ ├── cifar10.py
│ ├── dataset_factory.py
│ ├── dataset_utils.py
│ ├── download_and_convert_cifar10.py
│ ├── download_and_convert_flowers.py
│ ├── download_and_convert_imagenet.sh
│ ├── download_and_convert_mnist.py
│ ├── download_imagenet.sh
│ ├── flowers.py
│ ├── imagenet.py
│ ├── imagenet_2012_validation_synset_labels.txt
│ ├── imagenet_lsvrc_2015_synsets.txt
│ ├── imagenet_metadata.txt
│ ├── mnist.py
│ ├── preprocess_imagenet_validation_data.py
│ └── process_bounding_boxes.py
├── deployment
│ ├── __init__.py
│ ├── model_deploy.py
│ └── model_deploy_test.py
├── download_and_convert_data.py
├── eval_image_classifier.py
├── export_inference_graph.py
├── export_inference_graph_test.py
├── nets
│ ├── __init__.py
│ ├── alexnet.py
│ ├── alexnet_test.py
│ ├── cifarnet.py
│ ├── cyclegan.py
│ ├── cyclegan_test.py
│ ├── dcgan.py
│ ├── dcgan_test.py
│ ├── inception.py
│ ├── inception_resnet_v2.py
│ ├── inception_resnet_v2_layers.py
│ ├── inception_resnet_v2_layers_test.py
│ ├── inception_resnet_v2_test.py
│ ├── inception_utils.py
│ ├── inception_v1.py
│ ├── inception_v1_test.py
│ ├── inception_v2.py
│ ├── inception_v2_test.py
│ ├── inception_v3.py
│ ├── inception_v3_test.py
│ ├── inception_v4.py
│ ├── inception_v4_test.py
│ ├── lenet.py
│ ├── mobilenet
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── conv_blocks.py
│ │ ├── mobilenet.py
│ │ ├── mobilenet_example.ipynb
│ │ ├── mobilenet_v2.py
│ │ └── mobilenet_v2_test.py
│ ├── mobilenet_v1.md
│ ├── mobilenet_v1.py
│ ├── mobilenet_v1_eval.py
│ ├── mobilenet_v1_test.py
│ ├── mobilenet_v1_train.py
│ ├── nasnet
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── nasnet.py
│ │ ├── nasnet_test.py
│ │ ├── nasnet_utils.py
│ │ ├── nasnet_utils_test.py
│ │ ├── pnasnet.py
│ │ └── pnasnet_test.py
│ ├── nets_factory.py
│ ├── nets_factory_test.py
│ ├── overfeat.py
│ ├── overfeat_test.py
│ ├── pix2pix.py
│ ├── pix2pix_test.py
│ ├── resnet_utils.py
│ ├── resnet_v1.py
│ ├── resnet_v1_test.py
│ ├── resnet_v2.py
│ ├── resnet_v2_test.py
│ ├── vgg.py
│ ├── vgg_test.py
│ ├── xception.py
│ └── xception_test.py
├── preprocessing
│ ├── __init__.py
│ ├── cifarnet_preprocessing.py
│ ├── inception_preprocessing.py
│ ├── lenet_preprocessing.py
│ ├── preprocessing_factory.py
│ └── vgg_preprocessing.py
├── scripts
│ ├── export_mobilenet.sh
│ ├── finetune_inception_resnet_v2_on_flowers.sh
│ ├── finetune_inception_v1_on_flowers.sh
│ ├── finetune_inception_v3_on_flowers.sh
│ ├── finetune_resnet_v1_50_on_flowers.sh
│ ├── train_cifarnet_on_cifar10.sh
│ └── train_lenet_on_mnist.sh
├── setup.py
├── slim_walkthrough.ipynb
└── train_image_classifier.py
├── train_face_classify.py
├── train_with_npy.py
└── utils
└── explore_graph.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 |
5 | # Pictures
6 | *.jpg
7 | media/*.png
8 |
9 |
10 | # Only weights are those of SSD Mobilenet
11 | *.ckptl
12 | *.h5
13 | *.config
14 |
15 | classifier/*.pkl
16 | classifier/new_classifiers/*.pkl
17 |
18 | detection/model/*.pb
19 | recognition/model/*.pb
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Face Recognition
2 |
3 | Computer Vision and Intelligence Group, IIT Madras
4 |
5 | 
6 |
7 | We implement an experimental setup with face detection and recognition. This has been used for our purposes with the following aims:
8 |
9 | * Swapping multiple detectors and feature extractors for facenet.
10 | * Multi GPU and distributed support
11 | * Frozen graph support with quantisation.
12 |
13 | Primarily, we use this in two use cases:
14 |
15 | * High accuracy: SSD or FRCNN detectors with Inception-Resnet feature extractors.
16 | * CPU optimised FPS: SSDlite mobilenet with mobilenet V2 extractors (this is covered in *getting started*).
17 |
18 | We have experimented with multiple classifiers for error free student identification.
19 |
20 | ## Sample Results
21 |
22 | 
23 |
24 | ## Contents
25 |
26 | * [Getting Started](g3docs/getting-started.md)
27 | * [Model Zoo](g3docs/model-zoo.md)
28 | * [Installing Dependencies](g3docs/installing_dependencies.md)
29 |
30 | ### Facenet Docs
31 |
32 | * [David Sandberg's Implementation](g3docs/facenet.md)
33 | * [Retraining Facenet](g3docs/facenet_train_pipeline.md)
34 | * [Recognition with Facenet](g3docs/facenet_recognition_pipeline.md)
35 | * [Facenet Wiki](g3docs/facenet)
36 |
37 | ### Object Detection Experimental Setup
38 |
39 | * [Object Detection Pipeline](g3docs/object_detection_pipeline.md)
40 |
41 | ## To Do
42 |
43 | * [ ] TF-Estimator based scalable train file.
44 | * [x] SSDLite based detector
45 | * [x] Mobilenet models for facenet
46 | * [x] Angular, Focal and triplet losses.
47 | * [ ] Inference on Singular Videos.
48 | * [ ] DALI, Tensor RT for faster inference.
49 | * [ ] S3D support for detection.
50 | * [ ] Experiments with weight tying.
51 | * [ ] Results Section
52 | * [ ] Take a look at https://github.com/alexattia/ExtendedTinyFaces for large scale face detection.
53 |
54 | ## Dependencies
55 |
56 | * Python 3.4+
57 | * Tensorflow 1.7+
58 | * Opencv 3.3.1+
59 |
60 | ## Pipeline
61 | Image -> FaceDetection -> CroppedFace -> FaceRecognition -> Descriptor(128D) -> FaceClassifier -> Name
62 |
63 | ## Credits
64 |
65 | ## FaceRecognition(FaceNet)
66 |
67 | TensorFlow implementation of the face recognizer described in the paper "FaceNet: A Unified Embedding for Face Recognition and Clustering".
68 | Ref. [https://github.com/davidsandberg/facenet](https://github.com/davidsandberg/facenet)
69 |
70 |
71 |
--------------------------------------------------------------------------------
/attendance.txt:
--------------------------------------------------------------------------------
1 | Please register
2 |
--------------------------------------------------------------------------------
/classifier/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/classifier/__init__.py
--------------------------------------------------------------------------------
/classifier/trained_classifier.pkl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/classifier/trained_classifier.pkl
--------------------------------------------------------------------------------
/demo_face_detect.py:
--------------------------------------------------------------------------------
1 | '''
2 | CVI, IITM 2018
3 |
4 | Demo for face detection. Runs given model specification for detecting faces.
5 |
6 | Args:
7 | * detection model: detection model to use.
8 | SSDMobilenet and SSDlite_Mobilenet_v2 (default) are the avaliable choices.
9 | The latter is more accurate and yields larger FPS.
10 | See training details for descriptions on mAP and metrics.
11 |
12 | * camera: which port to use for opencv's Videocapture object.
13 | 0 is the usual for webcameras, USB cameras are listed as 1,2...
14 |
15 | Example:
16 |
17 | python demo_face_detect.py
18 | --detection_model ssdlite_v2
19 | --camera 1
20 | '''
21 |
22 | import cv2
23 | import time
24 | import numpy as np
25 | from detection.FaceDetector import FaceDetector
26 | import argparse
27 |
28 | parser=argparse.ArgumentParser()
29 |
30 | parser.add_argument("--detection_model",default="ssdlite_v2",
31 | choices=["ssdlite_v2","ssd_mobilenet"],help="detection model to use")
32 |
33 | # Camera
34 | parser.add_argument("--camera",default=0,
35 | type=int,help="Camera to use | 0 webcam | 1 usb camera. Can be different if lack of drivers.")
36 |
37 | args=parser.parse_args()
38 |
39 | if args.detection_model=="ssdlite_v2":
40 | detect_ckpt = './model/ssdlite_v2.pb'
41 | elif args.detection_model=="ssd_mobilenet":
42 | detect_ckpt = './model/ssd_mobilenet.pb'
43 |
44 | face_detector = FaceDetector(PATH_TO_CKPT=detect_ckpt)
45 | video_capture = cv2.VideoCapture(args.camera)
46 |
47 | print('Start Recognition!')
48 | prevTime = 0
49 |
50 | while True:
51 | ret, frame = video_capture.read()
52 | frame = cv2.resize(frame, (0, 0), fx=0.4, fy=0.4) # resize frame (optional)
53 |
54 | curTime = time.time() # calc fps
55 | find_results = []
56 |
57 | frame = frame[:, :, 0:3]
58 | boxes, scores = face_detector.detect(frame)
59 | face_boxes = boxes[np.argwhere(scores>0.3).reshape(-1)]
60 | face_scores = scores[np.argwhere(scores>0.3).reshape(-1)]
61 | print('Detected_FaceNum: %d' % len(face_boxes))
62 |
63 | if len(face_boxes) > 0:
64 | for i in range(len(face_boxes)):
65 | box = face_boxes[i]
66 | cv2.rectangle(frame, (box[1], box[0]), (box[3], box[2]), (0, 255, 0), 2)
67 |
68 | # plot result idx under box
69 | text_x = box[1]
70 | text_y = box[2] + 20
71 | cv2.putText(frame, 'Score: %2.3f' % face_scores[i], (text_x, text_y), cv2.FONT_HERSHEY_COMPLEX_SMALL,
72 | 1, (0, 0, 255), thickness=1, lineType=2)
73 | else:
74 | print('Unable to align')
75 |
76 | sec = curTime - prevTime
77 | prevTime = curTime
78 | fps = 1 / (sec)
79 | str = 'FPS: %2.3f' % fps
80 | text_fps_x = len(frame[0]) - 150
81 | text_fps_y = 20
82 | cv2.putText(frame, str, (text_fps_x, text_fps_y),
83 | cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (0, 0, 0), thickness=1, lineType=2)
84 |
85 | cv2.imshow('Video', frame)
86 |
87 | if cv2.waitKey(1) & 0xFF == ord('q'):
88 | break
89 |
90 | video_capture.release()
91 | cv2.destroyAllWindows()
92 |
93 |
--------------------------------------------------------------------------------
/detection/FaceDetector.py:
--------------------------------------------------------------------------------
1 | import os
2 | import time
3 | import numpy as np
4 | import tensorflow as tf
5 |
6 | BASE_DIR = os.path.dirname(__file__) + '/'
7 |
8 | # Path to frozen detection graph. This is the actual model that is used for the object detection.
9 | # List of the strings that is used to add correct label for each box.
10 |
11 | class FaceDetector:
12 | def __init__(self,PATH_TO_CKPT = './model/ssdlite_v2.pb',\
13 | PATH_TO_LABELS = './protos/face_label_map.pbtxt'):
14 | # Load models
15 | self.detection_graph = tf.Graph()
16 | self.sess = tf.Session(graph=self.detection_graph)
17 | with self.detection_graph.as_default():
18 | od_graph_def = tf.GraphDef()
19 | with tf.gfile.GFile(BASE_DIR + PATH_TO_CKPT, 'rb') as fid:
20 | serialized_graph = fid.read()
21 | od_graph_def.ParseFromString(serialized_graph)
22 | tf.import_graph_def(od_graph_def, name='')
23 |
24 | self.image_tensor = self.detection_graph.get_tensor_by_name('image_tensor:0')
25 | # Each box represents a part of the image where a particular object was detected.
26 | self.boxes = self.detection_graph.get_tensor_by_name('detection_boxes:0')
27 | # Each score represent how level of confidence for each of the objects.
28 | # Score is shown on the result image, together with the class label.
29 | self.scores = self.detection_graph.get_tensor_by_name('detection_scores:0')
30 | self.classes = self.detection_graph.get_tensor_by_name('detection_classes:0')
31 | self.num_detections = self.detection_graph.get_tensor_by_name('num_detections:0')
32 |
33 | def __del__(self):
34 | self.sess.close()
35 |
36 | def detect(self, image):
37 | # the array based representation of the image will be used later in order to prepare the
38 | # result image with boxes and labels on it.
39 | # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
40 | image_expanded = np.expand_dims(image, axis=0)
41 |
42 | # Actual detection.
43 | start_time = time.time()
44 | (boxes, scores, classes, num_detections) = self.sess.run(
45 | [self.boxes, self.scores, self.classes, self.num_detections],
46 | feed_dict={self.image_tensor: image_expanded})
47 | elapsed_time = time.time() - start_time
48 | print('inference time cost: {}'.format(elapsed_time))
49 |
50 | # Ratio to real position
51 | boxes[0, :, [0, 2]] = (boxes[0, :, [0, 2]]*image.shape[0])
52 | boxes[0, :, [1, 3]] = (boxes[0, :, [1, 3]]*image.shape[1])
53 | return np.squeeze(boxes).astype(int), np.squeeze(scores)
--------------------------------------------------------------------------------
/detection/FaceDetector_tiny.py:
--------------------------------------------------------------------------------
1 | import os
2 | import time
3 | import numpy as np
4 | import tensorflow as tf
5 |
6 | BASE_DIR = os.path.dirname(__file__) + '/'
7 |
8 | # Path to frozen detection graph. This is the actual model that is used for the object detection.
9 | # List of the strings that is used to add correct label for each box.
10 |
11 | class FaceDetector:
12 | def __init__(self,PATH_TO_CKPT = './model/tiny_face.pkl',\
13 | PATH_TO_LABELS = './protos/face_label_map.pbtxt'):
14 | # Load models
15 | self.detection_graph = tf.Graph()
16 | self.sess = tf.Session(graph=self.detection_graph)
17 | with self.detection_graph.as_default():
18 | od_graph_def = tf.GraphDef()
19 | with tf.gfile.GFile(BASE_DIR + PATH_TO_CKPT, 'rb') as fid:
20 | serialized_graph = fid.read()
21 | od_graph_def.ParseFromString(serialized_graph)
22 | tf.import_graph_def(od_graph_def, name='')
23 |
24 | self.image_tensor = self.detection_graph.get_tensor_by_name('image_tensor:0')
25 | # Each box represents a part of the image where a particular object was detected.
26 | self.boxes = self.detection_graph.get_tensor_by_name('detection_boxes:0')
27 | # Each score represent how level of confidence for each of the objects.
28 | # Score is shown on the result image, together with the class label.
29 | self.scores = self.detection_graph.get_tensor_by_name('detection_scores:0')
30 | self.classes = self.detection_graph.get_tensor_by_name('detection_classes:0')
31 | self.num_detections = self.detection_graph.get_tensor_by_name('num_detections:0')
32 |
33 | def __del__(self):
34 | self.sess.close()
35 |
36 | def detect(self, image):
37 | # the array based representation of the image will be used later in order to prepare the
38 | # result image with boxes and labels on it.
39 | # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
40 | image_expanded = np.expand_dims(image, axis=0)
41 |
42 | # Actual detection.
43 | start_time = time.time()
44 | (boxes, scores, classes, num_detections) = self.sess.run(
45 | [self.boxes, self.scores, self.classes, self.num_detections],
46 | feed_dict={self.image_tensor: image_expanded})
47 | elapsed_time = time.time() - start_time
48 | print('inference time cost: {}'.format(elapsed_time))
49 |
50 | # Ratio to real position
51 | boxes[0, :, [0, 2]] = (boxes[0, :, [0, 2]]*image.shape[0])
52 | boxes[0, :, [1, 3]] = (boxes[0, :, [1, 3]]*image.shape[1])
53 | return np.squeeze(boxes).astype(int), np.squeeze(scores)
--------------------------------------------------------------------------------
/detection/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/detection/__init__.py
--------------------------------------------------------------------------------
/detection/configs/face.pbtxt:
--------------------------------------------------------------------------------
1 | item {
2 | id: 1
3 | name: 'face'
4 | }
5 |
--------------------------------------------------------------------------------
/detection/protos/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/detection/protos/__init__.py
--------------------------------------------------------------------------------
/detection/protos/face_label_map.pbtxt:
--------------------------------------------------------------------------------
1 | item {
2 | id: 2
3 | name: 'background'
4 | }
5 |
6 | item {
7 | id: 1
8 | name: 'face'
9 | }
10 |
--------------------------------------------------------------------------------
/detection/utils/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/detection/utils/__init__.py
--------------------------------------------------------------------------------
/example/detect_face.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | from detection.FaceDetector import FaceDetector
4 |
5 | face_detector = FaceDetector()
6 | image_files = ['./media/train_classfier/ayush/IMG_2945.JPG', './media/train_classfier/ayush/IMG_2946.JPG']
7 | for input_str in image_files:
8 | # input_str = input('input image file: ')
9 | # if input_str == 'exit':
10 | # break
11 |
12 | img = cv2.imread(input_str)
13 | boxes, scores = face_detector.detect(img)
14 | face_boxes = boxes[np.argwhere(scores>0.3)]
15 | print(face_boxes)
16 | print(len(face_boxes))
17 | # for box in face_boxes:
18 | cv2.rectangle(img, (face_boxes[1], face_boxes[0]), (face_boxes[3], face_boxes[2]), (0, 255, 0), 2)
19 |
20 | cv2.imshow('image', img)
21 | cv2.waitKey(0)
22 | cv2.destroyAllWindows()
23 |
--------------------------------------------------------------------------------
/example/get_face_descriptor.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy as np
3 | from recognition.FaceRecognition import FaceRecognition
4 | from detection.FaceDetector import FaceDetector
5 |
6 | face_detector = FaceDetector()
7 | face_recognition = FaceRecognition()
8 | image_files = ['./media/1.jpg', './media/2.jpg']
9 | for input_str in image_files:
10 |
11 | img = cv2.imread(input_str)
12 | boxes, scores = face_detector.detect(img)
13 | face_boxes = boxes[np.argwhere(scores>0.5).squeeze()]
14 | print('Number of face in image:', len(face_boxes))
15 | for box in face_boxes:
16 | cropped_face = img[box[0]:box[2], box[1]:box[3], :]
17 | cropped_face = cv2.resize(cropped_face, (160, 160), interpolation=cv2.INTER_AREA)
18 |
19 | print('Face descriptor:')
20 | print(face_recognition.recognize(cropped_face), '\n')
21 | cv2.imshow('image', cropped_face)
22 | cv2.waitKey(0)
23 | cv2.destroyAllWindows()
24 |
--------------------------------------------------------------------------------
/facenet/.gitignore:
--------------------------------------------------------------------------------
1 | led / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | env/
12 | build/
13 | develop-eggs/
14 | dist/
15 | downloads/
16 | eggs/
17 | .eggs/
18 | lib/
19 | lib64/
20 | parts/
21 | sdist/
22 | var/
23 | wheels/
24 | *.egg-info/
25 | .installed.cfg
26 | *.egg
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *,cover
47 | .hypothesis/
48 |
49 | # Translations
50 | *.mo
51 | *.pot
52 |
53 | # Django stuff:
54 | *.log
55 | local_settings.py
56 |
57 | # Flask stuff:
58 | instance/
59 | .webassets-cache
60 |
61 | # Scrapy stuff:
62 | .scrapy
63 |
64 | # Sphinx documentation
65 | docs/_build/
66 |
67 | # PyBuilder
68 | target/
69 |
70 | # Jupyter Notebook
71 | .ipynb_checkpoints
72 |
73 | # pyenv
74 | .python-version
75 |
76 | # celery beat schedule file
77 | celerybeat-schedule
78 |
79 | # dotenv
80 | .env
81 |
82 | # virtualenv
83 | .venv
84 | venv/
85 | ENV/
86 |
87 | # Spyder project settings
88 | .spyderproject
89 |
90 | # Rope project settings
91 | .ropeproject
92 |
93 | # PyCharm project setting
94 | .idea
95 |
--------------------------------------------------------------------------------
/facenet/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | facenet
4 |
5 |
6 |
7 |
8 |
9 | org.python.pydev.PyDevBuilder
10 |
11 |
12 |
13 |
14 |
15 | org.python.pydev.pythonNature
16 |
17 |
18 |
--------------------------------------------------------------------------------
/facenet/.pydevproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | /${PROJECT_DIR_NAME}
5 | /${PROJECT_DIR_NAME}/src
6 |
7 | python 2.7
8 | Default
9 |
10 |
--------------------------------------------------------------------------------
/facenet/.travis.yml:
--------------------------------------------------------------------------------
1 | language: python
2 | sudo: required
3 | python:
4 | - "2.7"
5 | - "3.5"
6 | # command to install dependencies
7 | install:
8 | # numpy not using wheel to avoid problem described in
9 | # https://github.com/tensorflow/tensorflow/issues/6968
10 | - pip install --no-binary numpy --upgrade numpy
11 | - pip install -r requirements.txt
12 | # command to run tests
13 | script:
14 | - export PYTHONPATH=./src:./src/models:./src/align
15 | - python -m unittest discover -s test --pattern=*.py 1>&2
16 | dist: trusty
17 |
18 |
--------------------------------------------------------------------------------
/facenet/LICENSE.md:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 David Sandberg
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/facenet/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/facenet/__init__.py
--------------------------------------------------------------------------------
/facenet/contributed/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/facenet/contributed/__init__.py
--------------------------------------------------------------------------------
/facenet/data/learning_rate_retrain_tripletloss.txt:
--------------------------------------------------------------------------------
1 | # Learning rate schedule
2 | # Maps an epoch number to a learning rate
3 | 0: 0.1
4 | 300: 0.01
5 | 400: 0.001
6 | 1000: 0.0001
--------------------------------------------------------------------------------
/facenet/data/learning_rate_schedule_classifier_casia.txt:
--------------------------------------------------------------------------------
1 | # Learning rate schedule
2 | # Maps an epoch number to a learning rate
3 | 0: 0.05
4 | 60: 0.005
5 | 80: 0.0005
6 | 91: -1
7 |
--------------------------------------------------------------------------------
/facenet/data/learning_rate_schedule_classifier_msceleb.txt:
--------------------------------------------------------------------------------
1 | # Learning rate schedule
2 | # Maps an epoch number to a learning rate
3 | 0: 0.1
4 | 150: 0.01
5 | 180: 0.001
6 | 251: 0.0001
--------------------------------------------------------------------------------
/facenet/data/learning_rate_schedule_classifier_vggface2.txt:
--------------------------------------------------------------------------------
1 | # Learning rate schedule
2 | # Maps an epoch number to a learning rate
3 | 0: 0.05
4 | 100: 0.005
5 | 200: 0.0005
6 | 276: -1
--------------------------------------------------------------------------------
/facenet/requirements.txt:
--------------------------------------------------------------------------------
1 | tensorflow==1.15.2
2 | scipy
3 | scikit-learn
4 | opencv-python
5 | h5py
6 | matplotlib
7 | Pillow
8 | requests
9 | psutil
10 |
--------------------------------------------------------------------------------
/facenet/src/__init__.py:
--------------------------------------------------------------------------------
1 | # flake8: noqa
2 |
3 |
--------------------------------------------------------------------------------
/facenet/src/align/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/facenet/src/align/__init__.py
--------------------------------------------------------------------------------
/facenet/src/align/det1.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/facenet/src/align/det1.npy
--------------------------------------------------------------------------------
/facenet/src/align/det2.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/facenet/src/align/det2.npy
--------------------------------------------------------------------------------
/facenet/src/align/det3.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/facenet/src/align/det3.npy
--------------------------------------------------------------------------------
/facenet/src/download_and_extract.py:
--------------------------------------------------------------------------------
1 | import requests
2 | import zipfile
3 | import os
4 |
5 | model_dict = {
6 | 'lfw-subset': '1B5BQUZuJO-paxdN8UclxeHAR1WnR_Tzi',
7 | '20170131-234652': '0B5MzpY9kBtDVSGM0RmVET2EwVEk',
8 | '20170216-091149': '0B5MzpY9kBtDVTGZjcWkzT3pldDA',
9 | '20170512-110547': '0B5MzpY9kBtDVZ2RpVDYwWmxoSUk',
10 | '20180402-114759': '1EXPBSXwTaqrSC0OhUdXNmKSh9qJUQ55-'
11 | }
12 |
13 | def download_and_extract_file(model_name, data_dir):
14 | file_id = model_dict[model_name]
15 | destination = os.path.join(data_dir, model_name + '.zip')
16 | if not os.path.exists(destination):
17 | print('Downloading file to %s' % destination)
18 | download_file_from_google_drive(file_id, destination)
19 | with zipfile.ZipFile(destination, 'r') as zip_ref:
20 | print('Extracting file to %s' % data_dir)
21 | zip_ref.extractall(data_dir)
22 |
23 | def download_file_from_google_drive(file_id, destination):
24 |
25 | URL = "https://drive.google.com/uc?export=download"
26 |
27 | session = requests.Session()
28 |
29 | response = session.get(URL, params = { 'id' : file_id }, stream = True)
30 | token = get_confirm_token(response)
31 |
32 | if token:
33 | params = { 'id' : file_id, 'confirm' : token }
34 | response = session.get(URL, params = params, stream = True)
35 |
36 | save_response_content(response, destination)
37 |
38 | def get_confirm_token(response):
39 | for key, value in response.cookies.items():
40 | if key.startswith('download_warning'):
41 | return value
42 |
43 | return None
44 |
45 | def save_response_content(response, destination):
46 | CHUNK_SIZE = 32768
47 |
48 | with open(destination, "wb") as f:
49 | for chunk in response.iter_content(CHUNK_SIZE):
50 | if chunk: # filter out keep-alive new chunks
51 | f.write(chunk)
52 |
--------------------------------------------------------------------------------
/facenet/src/generative/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/facenet/src/generative/__init__.py
--------------------------------------------------------------------------------
/facenet/src/generative/models/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/facenet/src/generative/models/__init__.py
--------------------------------------------------------------------------------
/facenet/src/generative/models/vae_base.py:
--------------------------------------------------------------------------------
1 | # MIT License
2 | #
3 | # Copyright (c) 2017 David Sandberg
4 | #
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy
6 | # of this software and associated documentation files (the "Software"), to deal
7 | # in the Software without restriction, including without limitation the rights
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | # copies of the Software, and to permit persons to whom the Software is
10 | # furnished to do so, subject to the following conditions:
11 | #
12 | # The above copyright notice and this permission notice shall be included in all
13 | # copies or substantial portions of the Software.
14 | #
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | # SOFTWARE.
22 |
23 | """Base class for variational autoencoders containing an encoder and a decoder
24 | """
25 |
26 | from __future__ import absolute_import
27 | from __future__ import division
28 | from __future__ import print_function
29 |
30 | import tensorflow as tf
31 |
32 | class Vae(object):
33 |
34 | def __init__(self, latent_variable_dim, image_size):
35 | self.latent_variable_dim = latent_variable_dim
36 | self.image_size = image_size
37 | self.batch_norm_params = {
38 | # Decay for the moving averages.
39 | 'decay': 0.995,
40 | # epsilon to prevent 0s in variance.
41 | 'epsilon': 0.001,
42 | # force in-place updates of mean and variance estimates
43 | 'updates_collections': None,
44 | # Moving averages ends up in the trainable variables collection
45 | 'variables_collections': [ tf.GraphKeys.TRAINABLE_VARIABLES ],
46 | }
47 |
48 | def encoder(self, images, is_training):
49 | # Must be overridden in implementation classes
50 | raise NotImplementedError
51 |
52 | def decoder(self, latent_var, is_training):
53 | # Must be overridden in implementation classes
54 | raise NotImplementedError
55 |
56 | def get_image_size(self):
57 | return self.image_size
58 |
--------------------------------------------------------------------------------
/facenet/src/models/__init__.py:
--------------------------------------------------------------------------------
1 | # flake8: noqa
2 |
3 |
--------------------------------------------------------------------------------
/facenet/src/models/dummy.py:
--------------------------------------------------------------------------------
1 | """Dummy model used only for testing
2 | """
3 |
4 | from __future__ import absolute_import
5 | from __future__ import division
6 | from __future__ import print_function
7 |
8 | import tensorflow as tf
9 | import tensorflow.contrib.slim as slim
10 | import numpy as np
11 |
12 | def inference(images, keep_probability, phase_train=True, # @UnusedVariable
13 | bottleneck_layer_size=128, bottleneck_layer_activation=None, weight_decay=0.0, reuse=None): # @UnusedVariable
14 | batch_norm_params = {
15 | # Decay for the moving averages.
16 | 'decay': 0.995,
17 | # epsilon to prevent 0s in variance.
18 | 'epsilon': 0.001,
19 | # force in-place updates of mean and variance estimates
20 | 'updates_collections': None,
21 | # Moving averages ends up in the trainable variables collection
22 | 'variables_collections': [ tf.GraphKeys.TRAINABLE_VARIABLES ],
23 | }
24 |
25 | with slim.arg_scope([slim.conv2d, slim.fully_connected],
26 | weights_initializer=tf.truncated_normal_initializer(stddev=0.1),
27 | weights_regularizer=slim.l2_regularizer(weight_decay),
28 | normalizer_fn=slim.batch_norm,
29 | normalizer_params=batch_norm_params):
30 | size = np.prod(images.get_shape()[1:].as_list())
31 | net = slim.fully_connected(tf.reshape(images, (-1,size)), bottleneck_layer_size, activation_fn=None,
32 | scope='Bottleneck', reuse=False)
33 | return net, None
34 |
--------------------------------------------------------------------------------
/facenet/src/models/mobilenet/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/facenet/src/models/mobilenet/__init__.py
--------------------------------------------------------------------------------
/facenet/test/batch_norm_test.py:
--------------------------------------------------------------------------------
1 | # MIT License
2 | #
3 | # Copyright (c) 2016 David Sandberg
4 | #
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy
6 | # of this software and associated documentation files (the "Software"), to deal
7 | # in the Software without restriction, including without limitation the rights
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | # copies of the Software, and to permit persons to whom the Software is
10 | # furnished to do so, subject to the following conditions:
11 | #
12 | # The above copyright notice and this permission notice shall be included in all
13 | # copies or substantial portions of the Software.
14 | #
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | # SOFTWARE.
22 |
23 | import unittest
24 | import tensorflow as tf
25 | import models
26 | import numpy as np
27 | import numpy.testing as testing
28 |
29 | class BatchNormTest(unittest.TestCase):
30 |
31 |
32 | @unittest.skip("Skip batch norm test case")
33 | def testBatchNorm(self):
34 |
35 | tf.set_random_seed(123)
36 |
37 | x = tf.placeholder(tf.float32, [None, 20, 20, 10], name='input')
38 | phase_train = tf.placeholder(tf.bool, name='phase_train')
39 |
40 | # generate random noise to pass into batch norm
41 | #x_gen = tf.random_normal([50,20,20,10])
42 |
43 | bn = models.network.batch_norm(x, phase_train)
44 |
45 | init = tf.global_variables_initializer()
46 | sess = tf.Session(config=tf.ConfigProto())
47 | sess.run(init)
48 |
49 | with sess.as_default():
50 |
51 | #generate a constant variable to pass into batch norm
52 | y = np.random.normal(0, 1, size=(50,20,20,10))
53 |
54 | feed_dict = {x: y, phase_train: True}
55 | sess.run(bn, feed_dict=feed_dict)
56 |
57 | feed_dict = {x: y, phase_train: False}
58 | y1 = sess.run(bn, feed_dict=feed_dict)
59 | y2 = sess.run(bn, feed_dict=feed_dict)
60 |
61 | testing.assert_almost_equal(y1, y2, 10, 'Output from two forward passes with phase_train==false should be equal')
62 |
63 |
64 | if __name__ == "__main__":
65 | unittest.main()
66 |
--------------------------------------------------------------------------------
/facenet/test/triplet_loss_test.py:
--------------------------------------------------------------------------------
1 | # MIT License
2 | #
3 | # Copyright (c) 2016 David Sandberg
4 | #
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy
6 | # of this software and associated documentation files (the "Software"), to deal
7 | # in the Software without restriction, including without limitation the rights
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | # copies of the Software, and to permit persons to whom the Software is
10 | # furnished to do so, subject to the following conditions:
11 | #
12 | # The above copyright notice and this permission notice shall be included in all
13 | # copies or substantial portions of the Software.
14 | #
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | # SOFTWARE.
22 |
23 | import unittest
24 | import tensorflow as tf
25 | import numpy as np
26 | import facenet
27 |
28 | class DemuxEmbeddingsTest(unittest.TestCase):
29 |
30 | def testDemuxEmbeddings(self):
31 | batch_size = 3*12
32 | embedding_size = 16
33 | alpha = 0.2
34 |
35 | with tf.Graph().as_default():
36 |
37 | embeddings = tf.placeholder(tf.float64, shape=(batch_size, embedding_size), name='embeddings')
38 | anchor, positive, negative = tf.unstack(tf.reshape(embeddings, [-1,3,embedding_size]), 3, 1)
39 | triplet_loss = facenet.triplet_loss(anchor, positive, negative, alpha)
40 |
41 | sess = tf.Session()
42 | with sess.as_default():
43 | np.random.seed(seed=666)
44 | emb = np.random.uniform(size=(batch_size, embedding_size))
45 | tf_triplet_loss = sess.run(triplet_loss, feed_dict={embeddings:emb})
46 |
47 | pos_dist_sqr = np.sum(np.square(emb[0::3,:]-emb[1::3,:]),1)
48 | neg_dist_sqr = np.sum(np.square(emb[0::3,:]-emb[2::3,:]),1)
49 | np_triplet_loss = np.mean(np.maximum(0.0, pos_dist_sqr - neg_dist_sqr + alpha))
50 |
51 | np.testing.assert_almost_equal(tf_triplet_loss, np_triplet_loss, decimal=5, err_msg='Triplet loss is incorrect')
52 |
53 | if __name__ == "__main__":
54 | unittest.main()
55 |
--------------------------------------------------------------------------------
/facenet/tmp/__init__.py:
--------------------------------------------------------------------------------
1 | # flake8: noqa
2 |
3 |
--------------------------------------------------------------------------------
/facenet/tmp/cacd2000_split_identities.py:
--------------------------------------------------------------------------------
1 | import shutil
2 | import argparse
3 | import os
4 | import sys
5 |
6 | def main(args):
7 | src_path_exp = os.path.expanduser(args.src_path)
8 | dst_path_exp = os.path.expanduser(args.dst_path)
9 | if not os.path.exists(dst_path_exp):
10 | os.makedirs(dst_path_exp)
11 | files = os.listdir(src_path_exp)
12 | for f in files:
13 | file_name = '.'.join(f.split('.')[0:-1])
14 | x = file_name.split('_')
15 | dir_name = '_'.join(x[1:-1])
16 | class_dst_path = os.path.join(dst_path_exp, dir_name)
17 | if not os.path.exists(class_dst_path):
18 | os.makedirs(class_dst_path)
19 | src_file_path = os.path.join(src_path_exp, f)
20 | dst_file = os.path.join(class_dst_path, f)
21 | print('%s -> %s' % (src_file_path, dst_file))
22 | shutil.copyfile(src_file_path, dst_file)
23 |
24 | def parse_arguments(argv):
25 | parser = argparse.ArgumentParser()
26 |
27 | parser.add_argument('src_path', type=str, help='Path to the source directory.')
28 | parser.add_argument('dst_path', type=str, help='Path to the destination directory.')
29 | return parser.parse_args(argv)
30 |
31 | if __name__ == '__main__':
32 | main(parse_arguments(sys.argv[1:]))
33 |
--------------------------------------------------------------------------------
/facenet/tmp/dataset_read_speed.py:
--------------------------------------------------------------------------------
1 | import facenet
2 | import argparse
3 | import sys
4 | import time
5 | import numpy as np
6 |
7 | def main(args):
8 |
9 | dataset = facenet.get_dataset(args.dir)
10 | paths, _ = facenet.get_image_paths_and_labels(dataset)
11 | t = np.zeros((len(paths)))
12 | x = time.time()
13 | for i, path in enumerate(paths):
14 | start_time = time.time()
15 | with open(path, mode='rb') as f:
16 | _ = f.read()
17 | duration = time.time() - start_time
18 | t[i] = duration
19 | if i % 1000 == 0 or i==len(paths)-1:
20 | print('File %d/%d Total time: %.2f Avg: %.3f Std: %.3f' % (i, len(paths), time.time()-x, np.mean(t[0:i])*1000, np.std(t[0:i])*1000))
21 |
22 |
23 | def parse_arguments(argv):
24 | parser = argparse.ArgumentParser()
25 | parser.add_argument('dir', type=str,
26 | help='Directory with dataset to test')
27 | return parser.parse_args(argv)
28 |
29 |
30 | if __name__ == '__main__':
31 | main(parse_arguments(sys.argv[1:]))
32 |
--------------------------------------------------------------------------------
/facenet/tmp/invariance_test.txt:
--------------------------------------------------------------------------------
1 | Accuracy: 0.860±0.009
2 | Accuracy: 0.861±0.008
3 | Accuracy: 0.870±0.011
4 | Accuracy: 0.885±0.012
5 | Accuracy: 0.896±0.013
6 | Accuracy: 0.899±0.015
7 | Accuracy: 0.887±0.011
8 | Accuracy: 0.885±0.011
9 | Accuracy: 0.890±0.011
10 | Accuracy: 0.910±0.014
11 | Accuracy: 0.918±0.012
12 | Accuracy: 0.904±0.013
13 | Accuracy: 0.895±0.012
14 | Accuracy: 0.884±0.018
15 | Accuracy: 0.891±0.012
16 | Accuracy: 0.891±0.008
17 | Accuracy: 0.889±0.009
18 | Accuracy: 0.871±0.012
19 | Accuracy: 0.844±0.012
20 | Accuracy: 0.835±0.016
21 | Accuracy: 0.823±0.015
22 | Hoffset: Accuracy:
23 | -30.0000 0.8600
24 | -27.0000 0.8607
25 | -24.0000 0.8697
26 | -21.0000 0.8848
27 | -18.0000 0.8963
28 | -15.0000 0.8992
29 | -12.0000 0.8865
30 | -9.0000 0.8853
31 | -6.0000 0.8900
32 | -3.0000 0.9097
33 | 0.0000 0.9182
34 | 3.0000 0.9040
35 | 6.0000 0.8953
36 | 9.0000 0.8843
37 | 12.0000 0.8905
38 | 15.0000 0.8913
39 | 18.0000 0.8888
40 | 21.0000 0.8708
41 | 24.0000 0.8440
42 | 27.0000 0.8348
43 | 30.0000 0.8233
44 | Accuracy: 0.823±0.014
45 | Accuracy: 0.800±0.010
46 | Accuracy: 0.800±0.015
47 | Accuracy: 0.818±0.018
48 | Accuracy: 0.852±0.012
49 | Accuracy: 0.864±0.011
50 | Accuracy: 0.844±0.016
51 | Accuracy: 0.851±0.014
52 | Accuracy: 0.875±0.012
53 | Accuracy: 0.898±0.010
54 | Accuracy: 0.918±0.012
55 | Accuracy: 0.886±0.015
56 | Accuracy: 0.849±0.012
57 | Accuracy: 0.812±0.015
58 | Accuracy: 0.780±0.012
59 | Accuracy: 0.787±0.012
60 | Accuracy: 0.755±0.016
61 | Accuracy: 0.709±0.010
62 | Accuracy: 0.676±0.017
63 | Accuracy: 0.653±0.011
64 | Accuracy: 0.648±0.016
65 | Voffset: Accuracy:
66 | -30.0000 0.8230
67 | -27.0000 0.7997
68 | -24.0000 0.7995
69 | -21.0000 0.8183
70 | -18.0000 0.8523
71 | -15.0000 0.8638
72 | -12.0000 0.8442
73 | -9.0000 0.8507
74 | -6.0000 0.8755
75 | -3.0000 0.8982
76 | 0.0000 0.9182
77 | 3.0000 0.8862
78 | 6.0000 0.8493
79 | 9.0000 0.8118
80 | 12.0000 0.7803
81 | 15.0000 0.7868
82 | 18.0000 0.7548
83 | 21.0000 0.7093
84 | 24.0000 0.6763
85 | 27.0000 0.6533
86 | 30.0000 0.6483
87 |
--------------------------------------------------------------------------------
/facenet/tmp/mtcnn.py:
--------------------------------------------------------------------------------
1 | # MIT License
2 | #
3 | # Copyright (c) 2016 David Sandberg
4 | #
5 | # Permission is hereby granted, free of charge, to any person obtaining a copy
6 | # of this software and associated documentation files (the "Software"), to deal
7 | # in the Software without restriction, including without limitation the rights
8 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | # copies of the Software, and to permit persons to whom the Software is
10 | # furnished to do so, subject to the following conditions:
11 | #
12 | # The above copyright notice and this permission notice shall be included in all
13 | # copies or substantial portions of the Software.
14 | #
15 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | # SOFTWARE.
22 |
23 | from __future__ import absolute_import
24 | from __future__ import division
25 | from __future__ import print_function
26 |
27 | import tensorflow as tf
28 | import align.detect_face
29 | from scipy import misc
30 |
31 | with tf.Graph().as_default():
32 |
33 | sess = tf.Session()
34 | with sess.as_default():
35 | with tf.variable_scope('pnet'):
36 | data = tf.placeholder(tf.float32, (None,None,None,3), 'input')
37 | pnet = align.detect_face.PNet({'data':data})
38 | pnet.load('../../data/det1.npy', sess)
39 | with tf.variable_scope('rnet'):
40 | data = tf.placeholder(tf.float32, (None,24,24,3), 'input')
41 | rnet = align.detect_face.RNet({'data':data})
42 | rnet.load('../../data/det2.npy', sess)
43 | with tf.variable_scope('onet'):
44 | data = tf.placeholder(tf.float32, (None,48,48,3), 'input')
45 | onet = align.detect_face.ONet({'data':data})
46 | onet.load('../../data/det3.npy', sess)
47 |
48 | pnet_fun = lambda img : sess.run(('pnet/conv4-2/BiasAdd:0', 'pnet/prob1:0'), feed_dict={'pnet/input:0':img})
49 | rnet_fun = lambda img : sess.run(('rnet/conv5-2/conv5-2:0', 'rnet/prob1:0'), feed_dict={'rnet/input:0':img})
50 | onet_fun = lambda img : sess.run(('onet/conv6-2/conv6-2:0', 'onet/conv6-3/conv6-3:0', 'onet/prob1:0'), feed_dict={'onet/input:0':img})
51 |
52 | minsize = 20 # minimum size of face
53 | threshold = [ 0.6, 0.7, 0.7 ] # three steps's threshold
54 | factor = 0.709 # scale factor
55 |
56 | source_path = '/home/david/datasets/casia/CASIA-maxpy-clean/0000045/002.jpg'
57 | img = misc.imread(source_path)
58 |
59 | bounding_boxes, points = align.detect_face.detect_face(img, minsize, pnet_fun, rnet_fun, onet_fun, threshold, factor)
60 |
61 | print('Bounding box: %s' % bounding_boxes)
62 |
63 |
64 |
--------------------------------------------------------------------------------
/facenet/tmp/rename_casia_directories.py:
--------------------------------------------------------------------------------
1 | import shutil
2 | import argparse
3 | import os
4 | import sys
5 |
6 | def main(args):
7 |
8 | identity_map = {}
9 | with open(os.path.expanduser(args.map_file_name), "r") as f:
10 | for line in f:
11 | fields = line.split(' ')
12 | dir_name = fields[0]
13 | class_name = fields[1].replace('\n', '').replace('\r', '')
14 | if class_name not in identity_map.values():
15 | identity_map[dir_name] = class_name
16 | else:
17 | print('Duplicate class names: %s' % class_name)
18 |
19 | dataset_path_exp = os.path.expanduser(args.dataset_path)
20 | dirs = os.listdir(dataset_path_exp)
21 | for f in dirs:
22 | old_path = os.path.join(dataset_path_exp, f)
23 | if f in identity_map:
24 | new_path = os.path.join(dataset_path_exp, identity_map[f])
25 | if os.path.isdir(old_path):
26 | print('Renaming %s to %s' % (old_path, new_path))
27 | shutil.move(old_path, new_path)
28 |
29 | def parse_arguments(argv):
30 | parser = argparse.ArgumentParser()
31 |
32 | parser.add_argument('map_file_name', type=str, help='Name of the text file that contains the directory to class name mappings.')
33 | parser.add_argument('dataset_path', type=str, help='Path to the dataset directory.')
34 | return parser.parse_args(argv)
35 |
36 | if __name__ == '__main__':
37 | main(parse_arguments(sys.argv[1:]))
38 |
--------------------------------------------------------------------------------
/facenet/tmp/select_triplets_test.py:
--------------------------------------------------------------------------------
1 | import facenet
2 | import numpy as np
3 | import tensorflow as tf
4 |
5 | FLAGS = tf.app.flags.FLAGS
6 |
7 | tf.app.flags.DEFINE_integer('people_per_batch', 45,
8 | """Number of people per batch.""")
9 | tf.app.flags.DEFINE_integer('alpha', 0.2,
10 | """Positive to negative triplet distance margin.""")
11 |
12 |
13 | embeddings = np.zeros((1800,128))
14 |
15 | np.random.seed(123)
16 | for ix in range(embeddings.shape[0]):
17 | for jx in range(embeddings.shape[1]):
18 | rnd = 1.0*np.random.randint(1,2**32)/2**32
19 | embeddings[ix][jx] = rnd
20 |
21 |
22 | emb_array = embeddings
23 | image_data = np.zeros((1800,96,96,3))
24 |
25 |
26 | num_per_class = [40 for i in range(45)]
27 |
28 |
29 | np.random.seed(123)
30 | apn, nrof_random_negs, nrof_triplets = facenet.select_triplets(emb_array, num_per_class, image_data)
31 |
--------------------------------------------------------------------------------
/facenet/tmp/test1.py:
--------------------------------------------------------------------------------
1 | print('Hello world')
2 |
--------------------------------------------------------------------------------
/facenet/tmp/test_align.py:
--------------------------------------------------------------------------------
1 | import facenet
2 | import os
3 | import matplotlib.pyplot as plt
4 | import numpy as np
5 |
6 |
7 | def main():
8 | image_size = 96
9 | old_dataset = '/home/david/datasets/facescrub/fs_aligned_new_oean/'
10 | new_dataset = '/home/david/datasets/facescrub/facescrub_110_96/'
11 | eq = 0
12 | num = 0
13 | l = []
14 | dataset = facenet.get_dataset(old_dataset)
15 | for cls in dataset:
16 | new_class_dir = os.path.join(new_dataset, cls.name)
17 | for image_path in cls.image_paths:
18 | try:
19 | filename = os.path.splitext(os.path.split(image_path)[1])[0]
20 | new_filename = os.path.join(new_class_dir, filename+'.png')
21 | #print(image_path)
22 | if os.path.exists(new_filename):
23 | a = facenet.load_data([image_path, new_filename], False, False, image_size, do_prewhiten=False)
24 | if np.array_equal(a[0], a[1]):
25 | eq+=1
26 | num+=1
27 | err = np.sum(np.square(np.subtract(a[0], a[1])))
28 | #print(err)
29 | l.append(err)
30 | if err>2000:
31 | fig = plt.figure(1)
32 | p1 = fig.add_subplot(121)
33 | p1.imshow(a[0])
34 | p2 = fig.add_subplot(122)
35 | p2.imshow(a[1])
36 | print('%6.1f: %s\n' % (err, new_filename))
37 | pass
38 | else:
39 | pass
40 | #print('File not found: %s' % new_filename)
41 | except:
42 | pass
43 | if __name__ == '__main__':
44 | main()
45 |
--------------------------------------------------------------------------------
/facenet/tmp/visualize_vggface.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import tensorflow as tf
3 | import matplotlib.pyplot as plt
4 | import tmp.vggface16
5 |
6 | def main():
7 |
8 | sess = tf.Session()
9 |
10 | t_input = tf.placeholder(np.float32, name='input') # define the input tensor
11 | image_mean = 117.0
12 | t_preprocessed = tf.expand_dims(t_input-image_mean, 0)
13 |
14 | # Build the inference graph
15 | nodes = tmp.vggface16.load('data/vgg_face.mat', t_preprocessed)
16 |
17 | img_noise = np.random.uniform(size=(224,224,3)) + 117.0
18 |
19 | # Picking some internal layer. Note that we use outputs before applying the ReLU nonlinearity
20 | # to have non-zero gradients for features with negative initial activations.
21 | layer = 'conv5_3'
22 | channel = 140 # picking some feature channel to visualize
23 | img = render_naive(sess, t_input, nodes[layer][:,:,:,channel], img_noise)
24 | showarray(img)
25 |
26 | def showarray(a):
27 | a = np.uint8(np.clip(a, 0, 1)*255)
28 | plt.imshow(a)
29 | plt.show()
30 |
31 | def visstd(a, s=0.1):
32 | '''Normalize the image range for visualization'''
33 | return (a-a.mean())/max(a.std(), 1e-4)*s + 0.5
34 |
35 | def render_naive(sess, t_input, t_obj, img0, iter_n=20, step=1.0):
36 | t_score = tf.reduce_mean(t_obj) # defining the optimization objective
37 | t_grad = tf.gradients(t_score, t_input)[0] # behold the power of automatic differentiation!
38 |
39 | img = img0.copy()
40 | for _ in range(iter_n):
41 | g, _ = sess.run([t_grad, t_score], {t_input:img})
42 | # normalizing the gradient, so the same step size should work
43 | g /= g.std()+1e-8 # for different layers and networks
44 | img += g*step
45 | return visstd(img)
46 |
47 |
48 | if __name__ == '__main__':
49 | main()
50 |
--------------------------------------------------------------------------------
/g3docs/Experimentation.md:
--------------------------------------------------------------------------------
1 | # Detection
2 | We have experimented with different detection models with validation on the hard set of WIDER dataset (S.O.T.A mAP is 46.4) :
3 |
4 | ## Experimenting with detection models
5 |
6 | | Model | mAP | Iterations trained |
7 | | ------------- | ------------- |
8 | | SSDlite mobilenet v2| 32.7 | 100k |
9 | | SSDlite mobilenet | 33.4 | 110k |
10 | | SSDlite mobilenet with scaling and interpolation| 38.6 | 110k |
11 | | FRCNN Resnet50| 40.8 | 120k |
12 | | FRCNN inception v3 | 43.9 | 120k|
13 |
14 | # Recoginition
15 | Faster R-CNN Resnet50 model has been used for recognition.
16 | ## Data augmentation
17 | To prevent the model from overfitting, we implemented multiple data augmentation techniques :
18 | * Flips
19 | * Rotations
20 | * Brightness adjustments: Images of different brightness levels were generated using the Gamma correction/Power Law transform.
21 |
22 | ## Classification
23 | We first extracted facenet embeddings for a dataset of 1110 images with 8 classes.
24 | We have mainly experimented with the following classifiers :
25 | * SVMs
26 | * K-Nearest Neighbours
27 | * Random forests
28 | * Classification using L2
29 |
30 | We used of ensemble of SVMs (RBF,linear and poly), K-NNs ( k=5 and k=7) and random forests for the final output.
31 |
32 |
--------------------------------------------------------------------------------
/g3docs/avatar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/g3docs/avatar.png
--------------------------------------------------------------------------------
/g3docs/face_recognition_pipeline.md:
--------------------------------------------------------------------------------
1 | # Face Recognition Pipeline
2 |
3 | ## Adding users
4 |
5 | ```
6 | python train_face_classify.py
7 | ```
8 |
9 | takes images under `media/train_classifier/` with each folder as a subject. Add all subject photos in the same folder.
10 |
11 | ## Running recognition
12 |
13 | ```
14 | python demo_face_recognition.py
15 | ```
16 |
17 | Uses cv2.Videocapture(0) as default. Non-Queue version
18 |
19 | ## Running detection only.
20 |
21 | ```
22 | python demo_face_detect.py
23 | ```
24 |
25 | Uses cv2.Videocapture(0) as default. Non-Queue version
--------------------------------------------------------------------------------
/g3docs/facenet_train_pipeline.md:
--------------------------------------------------------------------------------
1 | # Facenet train Pipeline
2 |
3 | Dataset: [VGGFace 2](http://www.robots.ox.ac.uk/~vgg/data/vgg_face2/)
4 |
5 | `export PYTHONPATH=facenet/src`
6 |
7 | ## /media/ssd1/face/datasets structure
8 |
9 | Tree
10 | ```
11 | /media/ssd1/face/dataset
12 | |-- lfw-deepfunneled
13 | |-- lfw_mtcnnalign
14 | |-- test
15 | |-- train
16 | |-- train_mtcnnalign
17 | ```
18 |
19 | test, train refer to VGGFace 2
20 | [LFW](http://vis-www.cs.umass.edu/lfw/) is used for benchmarking. Deepfunneled branch used.
21 | Total number of images: 13233 (LFW Deepfunneled).
22 |
23 | ## Dataset structure
24 | It is assumed that the training dataset is arranged as below, i.e. where each class is a sub-directory containing the training examples belonging to that class.
25 |
26 | ```
27 | Aaron_Eckhart
28 | Aaron_Eckhart_0001.jpg
29 |
30 | Aaron_Guiel
31 | Aaron_Guiel_0001.jpg
32 |
33 | Aaron_Patterson
34 | Aaron_Patterson_0001.jpg
35 |
36 | Aaron_Peirsol
37 | Aaron_Peirsol_0001.jpg
38 | Aaron_Peirsol_0002.jpg
39 | Aaron_Peirsol_0003.jpg
40 | Aaron_Peirsol_0004.jpg
41 | ...
42 | ```
43 |
44 | ## Face alignment
45 |
46 | ```
47 | for N in {1..8}; do \
48 | python facenet/src/align/align_dataset_mtcnn.py \
49 | /media/ssd1/face/dataset/train/ \
50 | /media/ssd1/face/dataset/train_mtcnnalign \
51 | --image_size 182 \
52 | --margin 44 \
53 | --random_order \
54 | --gpu_memory_fraction 0.25 \
55 | & done
56 | ```
57 |
58 | ### For LFW (Eval purposes)
59 |
60 | python facenet/src/align/align_dataset_mtcnn.py \
61 | /media/ssd1/face/dataset/lfw-deepfunneled \
62 | /media/ssd1/face/dataset/lfw_mtcnnalign \
63 | --image_size 182 \
64 | --margin 44 \
65 | --random_order \
66 | --gpu_memory_fraction 1
67 |
68 | ## Model (checkpoint storage) structure
69 |
70 | /
71 |
72 | ## Classifier Training (Softmax loss)
73 |
74 | ```
75 | python facenet/src/train_softmax.py \
76 | --logs_base_dir /media/ssd1/face/facenet/logs \
77 | --models_base_dir /media/ssd1/face/facenet/models \
78 | --data_dir /media/ssd1/face/dataset/train_mtcnnalign \
79 | --image_size 160 \
80 | --model_def models.mobilenet_v2 \
81 | --lfw_dir /media/ssd1/face/dataset/lfw_mtcnnalign/ \
82 | --optimizer ADAM \
83 | --learning_rate -1 \
84 | --max_nrof_epochs 500 \
85 | --batch_size 90 \
86 | --keep_probability 0.4 \
87 | --random_flip \
88 | --use_fixed_image_standardization \
89 | --learning_rate_schedule_file facenet/data/learning_rate_schedule_classifier_vggface2.txt \
90 | --weight_decay 5e-4 \
91 | --embedding_size 512 \
92 | --lfw_distance_metric 1 \
93 | --lfw_use_flipped_images \
94 | --lfw_subtract_mean \
95 | --validation_set_split_ratio 0.01 \
96 | --validate_every_n_epochs 5
97 | ```
98 |
99 | ### Distance Metrics
100 |
101 |
102 |
--------------------------------------------------------------------------------
/g3docs/getting-started.md:
--------------------------------------------------------------------------------
1 | ## Usage
2 |
3 | ### Basic Usage
4 |
5 | These set of instructions are for running the trained models.
6 |
7 | #### Step 1:
8 |
9 | Install all required dependencies by running (does not include tensorflow, opencv3):
10 | `pip install -r requirements.txt`
11 |
12 | #### Step 2:
13 |
14 | Place subjects as seperate folders under `media/train_image_classifier`.
15 |
16 | There needs to be a minimum of two subjects.
17 |
18 | Download the following models from here:
19 |
20 | * [SSD Mobilenet v1](https://github.com/yeephycho/tensorflow-face-detection/blob/master/model/frozen_inference_graph_face.pb)
21 |
22 | * [SSDLite mobilenet](https://drive.google.com/open?id=1k6ZXrgo4f0tU18tqlMLjN5tTb_6mwnsS): Place under detection/model/ssdlite_v2.pb [This can be customised].
23 |
24 | * [Facenet Mobilenet](https://drive.google.com/open?id=1sBHIXC66tdKlj7pd9zxaEpxcGJmC5NA1): Place the frozen_inference.pb under detection/model/mobilenet_v2.pb [This can be customised].
25 |
26 | * [Facenet Inception_ Resnet_v1](https://drive.google.com/open?id=1S98bS1bQM9BuxXqmwJAGS6SNkMz_Rzj0): Place the frozen_inference.pb under detection/model/inception_resnet_v1.pb [This can be customised].
27 |
28 | #### Step 3:
29 |
30 | Run
31 | `python train_face_classify.py` (mobilenet)
32 |
33 | `python train_face_classify.py --recognition_model inception_resnet_v1`
34 |
35 | For non-standard flags, run as:
36 |
37 | ```
38 | python train_face_classify.py [-h]
39 | [--recognition_model {inception_resnet_v1,mobilenet_v2,inception_resnet_v2}]
40 | [--detection_model {ssdlite_v2,ssd_mobilenet}]
41 | [--trained_classifier TRAINED_CLASSIFIER]
42 | [--classifier {SVM,KNN}]
43 | [--embedding_size {128,512}]
44 |
45 | optional arguments:
46 | -h, --help show this help message and exit
47 | --recognition_model {inception_resnet_v1,mobilenet_v2,inception_resnet_v2}
48 | --detection_model {ssdlite_v2,ssd_mobilenet}
49 | detection model to use
50 | --trained_classifier TRAINED_CLASSIFIER
51 | trained classifier to use
52 | --classifier {SVM,KNN}
53 | trained classifier to use
54 | --embedding_size {128,512}
55 | Embedding Size
56 | ```
57 |
58 | #### Step 4:
59 |
60 | Run
61 |
62 | `python demo_face_recognition.py (mobilenet)`
63 |
64 |
65 | `python train_face_classify.py --recognition_model inception_resnet_v1` (inception_resnet)
66 |
--------------------------------------------------------------------------------
/g3docs/installing_dependencies.md:
--------------------------------------------------------------------------------
1 | # README
2 |
3 | Install Scripts
4 |
5 | ## Script-wise Description
6 |
7 | * 1-setup-environment.sh : Set's up zsh environment with appropriate path links.
8 | * 2-conda.sh : Set up two conda environments, `py27` and `py35` (3.5).
9 | * 3-tf-object-detection.sh : Installs additonal dependencies for the object detection pipeline.
10 | * 4-misc-pip.sh: Install addtional dependencies for satellite render.
11 |
12 | -----
13 |
14 | # Using a non-standard tensorflow installation
15 |
16 | If building from scource, comment out `line 4` in `3-tf-object-detection.sh`:
17 |
18 | ```
19 | pip install --upgrade tensorflow-gpu
20 | ```
21 |
22 | Recommended: tf > 1.6rc
23 |
--------------------------------------------------------------------------------
/g3docs/model-zoo.md:
--------------------------------------------------------------------------------
1 | ## Model Zoo
2 |
3 | All associated weight files may be found [here](
4 | https://drive.google.com/drive/folders/1KIm781ON9FmifTjZ1BMUaWlSlzaZGqQj?usp=sharing) .
5 |
6 | In specific, for the detector, we provide the following models:
7 |
8 | Place detector model protobuf's (frozen graphs) under `detector/models/`.
9 |
10 |
11 | Place recognition model protobuf's (frozen graphs) under `recognition/models/`.
--------------------------------------------------------------------------------
/generating_more_images.py:
--------------------------------------------------------------------------------
1 |
2 |
3 | from keras.preprocessing.image import ImageDataGenerator
4 | import imgaug
5 | import numpy as np
6 | import cv2
7 | import tensorflow as tf
8 | import os
9 | from skimage import transform
10 |
11 | def adjust_gamma(image, gamma=1.0):
12 | # build a lookup table mapping the pixel values [0, 255] to
13 | # their adjusted gamma values
14 | invGamma = 1.0 / gamma
15 | table = np.array([((i / 255.0) ** invGamma) * 255
16 | for i in np.arange(0, 256)]).astype("uint8")
17 |
18 |
19 | return cv2.LUT(image, table)
20 |
21 |
22 | path='add source file path here'
23 | path2='add destination file path here'
24 |
25 | i=0
26 | for filename in os.listdir(path):
27 | original=cv2.imread(os.path.join(path,filename))
28 | if original is None :
29 | break
30 | original=cv2.resize(original,(400,400))
31 | for gamma in np.arange(0.5, 2, 0.5):
32 | # ignore when gamma is 1 (there will be no change to the image)
33 |
34 | # apply gamma correction and show the images
35 | gamma = gamma if gamma > 0 else 0.1
36 | adjusted = adjust_gamma(original, gamma=gamma)
37 | cv2.putText(adjusted, "g={}".format(gamma), (10, 30),cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 3)
38 | cv2.imwrite(os.path.join(path2,'{}_gamma_{}.jpeg'.format(i,gamma)),adjusted)
39 | i+=1
40 | #cv2.imshow("Images", adjusted)
41 | #cv2.waitKey(0)
42 |
43 |
44 |
--------------------------------------------------------------------------------
/install_scripts/2-conda.sh:
--------------------------------------------------------------------------------
1 | source ~/.zshrc
2 |
3 | conda update conda -y
4 | conda clean --all -y
5 | conda install ipython -y
6 |
7 | # conda create --name py35 python=3.5 numpy scipy matplotlib
8 | conda install libgcc -y
9 | conda create --name py27 python=2.7 numpy scipy matplotlib scikit-learn scikit-image jupyter notebook pandas h5py -y
10 | conda create --name py35 python=3.5 numpy scipy matplotlib scikit-learn scikit-image jupyter notebook pandas h5py -y
11 | pip install numpy scipy matplotlsib scikit-learn scikit-image jupyter notebook pandas h5py
12 | sed -i.bak "/anaconda3/d" ~/.zshrc
13 | echo "export PATH=/opt/anaconda3/envs/py27/bin:\$PATH" >> ~/.zshrc
14 | echo "export PATH=/opt/anaconda3/bin:\$PATH" >> ~/.zshrc
15 | source ~/.zshrc
16 |
17 | pip install autopep8 scdl org-e youtube-dl
18 | echo "alias ydl=\"youtube-dl -f 140 --add-metadata --metadata-from-title \\\"%(artist)s - %(title)s\\\" -o \\\"%(title)s.%(ext)s\\\"\"" >> ~/.bash_aliases
19 |
20 | jupyter notebook --generate-config
21 | {
22 | echo ""
23 | echo "c.NotebookApp.browser = u'firefox'"
24 | } >> ~/.jupyter/jupyter_notebook_config.py
25 |
26 | conda info --envs
27 |
28 | echo "*************************** NOTICE ***************************"
29 | echo "If you ever mess up your anaconda installation somehow, do"
30 | echo "\$ conda remove anaconda matplotlib mkl mkl-service nomkl openblas"
31 | echo "\$ conda clean --all"
32 | echo "Do this for each environment as well as your root. Then reinstall all except nomkl. Nvidia will now be installed"
33 |
34 | echo ""
35 | echo ""
36 | echo "*************************** NOTICE ***************************"
37 | echo "Python2.7 and 3.5 environments have been created. To activate them hit "
38 | echo "$ source activate py27"
39 | echo "or"
40 | echo "$ source activate py35"
41 |
42 | ## If you want to install the bleeding edge Nvidia drivers, uncomment the next set of lines
43 | # echo "Now choose gdm3 as your default display manager. Hit Enter"
44 | # read temp
45 |
46 | # sudo add-apt-repository ppa:graphics-drivers/ppa -y
47 | # sudo apt-get update
48 | # sudo ubuntu-drivers autoinstall
49 | # echo "The PC will restart now. Check if your display is working, as your display driver would have been updated. Hit [Enter]"
50 | # echo "Also, when installing CUDA next, ********don't******* install display drivers."
51 | # echo "In case your drivers don't work, purge gdm3 and use lightdm (sudo apt-get purge lightdm && sudo dpkg-reconfigure gdm3)"
52 | # read temp
53 | # sudo reboot
54 |
55 | echo "The script has finished"
56 |
--------------------------------------------------------------------------------
/install_scripts/3-tf-object-detection.sh:
--------------------------------------------------------------------------------
1 | source activate py35
2 |
3 | # Comment out if using non-standard tensorflow gpu configuration or a source build
4 | pip install --upgrade tensorflow-gpu
5 |
6 | sudo apt-get install protobuf-compiler python-pil python-lxml python-tk
7 | pip install Cython
8 | pip install matplotlib
9 |
10 | # COCO API Metrics
11 | git clone https://github.com/cocodataset/cocoapi.git
12 | cd cocoapi/PythonAPI
13 | make
14 | cp -r pycocotools /models/research/
15 |
16 | # From root folder
17 | protoc object_detection/protos/*.proto --python_out=.
18 |
--------------------------------------------------------------------------------
/install_scripts/4-misc-pip.sh:
--------------------------------------------------------------------------------
1 | # Other dependencies
2 | pip install -r install_scripts/requirements.txt
3 |
4 | # For Rtree dependencies
5 | sudo apt-get install libspatialindex-dev
6 |
--------------------------------------------------------------------------------
/install_scripts/requirments.txt:
--------------------------------------------------------------------------------
1 | Rtree
2 | Shapely
3 | fastkml
4 | lxml
5 |
--------------------------------------------------------------------------------
/install_scripts/zshrc-exports:
--------------------------------------------------------------------------------
1 | # Bazel Install
2 | source /home/user/.bazel/bin/bazel-complete.bash
3 | export PATH="$PATH:$HOME/bin"
4 |
5 | # Tensorboard locale issues (with utf 8)
6 | export LC_ALL=C
7 |
8 | # CUPTI Export
9 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/extras/CUPTI/lib64
10 |
11 | # NVIDIA
12 | export PATH=$PATH:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
13 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/nvidia/lib:/usr/local/nvidia/lib64
14 |
15 | # TF Slim linkages, Conda paths
16 | export PATH=/opt/anaconda3/envs/py27/bin:$PATH
17 | export PATH=/opt/anaconda3/bin:$PATH
18 | export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim
19 |
20 | # Lazy Git
21 | function lazygit() {
22 | git add .
23 | git add -u
24 | git commit -a -m "$1"
25 | git push
26 | }
27 |
--------------------------------------------------------------------------------
/mtcnn-face/face-recognition/README.md:
--------------------------------------------------------------------------------
1 | # MTCNN - face detection
2 |
3 | Follow the installation procedures given in the Facenet repo to install the modules required. Download the pretrained model from the repo.
4 |
5 | Have a dataset with different faces in different sub-directories.
6 |
7 | Training
8 | --------
9 |
10 | ```bash
11 | python facenet/src/custom_face_detection.py TRAIN --batch_size 16 --min_nrof_images_per_class 40
12 | ```
13 |
14 | Classification
15 | ---
16 |
17 | ```bash
18 | python facenet/src/custom_face_detection.py CLASSIFY --batch_size 16 --min_nrof_images_per_class 40
19 | ```
20 |
21 |
22 | Live face recognition
23 | ---
24 |
25 | ```bash
26 | python facenet/src/custom_face_detection.py LIVE dataset_aug models/20180402-114759.pb models/lfw_classifier.pkl
27 | ```
28 |
29 | Datset Creation
30 | ---
31 |
32 | This code can be used to create the dataset. Enter the name of the participant and live window appears. Press `s` to save the image in the directory.
33 |
34 | ```bash
35 | python dataset_creation.py
36 | ```
37 |
38 | Data Augmentation
39 | ---
40 |
41 | Enter the path of the folder of images you would like to augment.
42 | Default destination directory will be `dataset_aug`
43 |
44 | ```bash
45 | python data_augmentation.py
46 | ```
--------------------------------------------------------------------------------
/mtcnn-face/face-recognition/dataset_creation.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import os
3 | import cv2
4 | import sys
5 | from mtcnn.mtcnn import MTCNN
6 | import numpy as np
7 | FACE_SIZE = 160
8 | def align_face(image, l_eye, r_eye, desiredLeftEye = (0.35,0.35),desiredFaceWidth = FACE_SIZE, desiredFaceHeight = FACE_SIZE):
9 | dY = r_eye[1] - l_eye[1]
10 | dX = r_eye[0] - l_eye[0]
11 | angle = np.degrees(np.arctan2(dY, dX))
12 | desiredRightEyeX = 1.0 - desiredLeftEye[0]
13 | dist = np.sqrt((dX ** 2) + (dY ** 2))
14 | desiredDist = (desiredRightEyeX - desiredLeftEye[0])
15 | desiredDist *= desiredFaceWidth
16 | scale = desiredDist / dist
17 | eyesCenter = tuple((np.array(l_eye) + np.array(r_eye))//2)
18 | print (eyesCenter)
19 | print (angle)
20 | print (scale)
21 | M = cv2.getRotationMatrix2D(tuple(eyesCenter), angle, scale)
22 | tX = desiredFaceWidth*0.5
23 | tY = desiredFaceHeight*desiredLeftEye[1]
24 | M[0,2] += (tX - eyesCenter[0])
25 | M[1,2] += (tY - eyesCenter[1])
26 | (w, h) = (desiredFaceWidth, desiredFaceHeight)
27 | output = cv2.warpAffine(image, M, (w, h), flags=cv2.INTER_CUBIC)
28 | return output
29 |
30 | detector = MTCNN()
31 |
32 | cap = cv2.VideoCapture(0)
33 | while True:
34 | print ("Enter the name of the participant")
35 | name = input()
36 | os.makedirs("dataset/" + name, exist_ok=True)
37 | path = "dataset/" + name
38 | u = 0
39 | while True:
40 | ret, frame = cap.read()
41 | face = (detector.detect_faces(frame))
42 | fc = frame.copy()
43 |
44 | if len(face) > 0:
45 | for idx,f in enumerate(face):
46 | # print (f)
47 | b = f['box']
48 | cv2.rectangle(fc, (b[0], b[1]), (b[0]+b[2], b[1]+b[3]), (0,255,0))
49 | face_crop = frame[b[1]:b[1]+b[3], b[0]:b[0]+b[2]]
50 | face_crop = cv2.resize(face_crop, (FACE_SIZE, FACE_SIZE))
51 | l_eye = np.array(f['keypoints']['left_eye'])
52 | r_eye = np.array(f['keypoints']['right_eye'])
53 |
54 | # face_crop_align = align_face(fc,l_eye, r_eye)
55 | cv2.putText(fc, "Human Face", (b[0], b[1]),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0,255,0), 2)
56 | # cv2.imshow("iamge", np.hstack((face_crop, face_crop_align)))
57 | k = cv2.waitKey(1) & 0xFF
58 | cv2.imshow("frame_", fc)
59 | if k == ord('s'):
60 | # print ("entered")
61 | cv2.imwrite(path+"/"+str(u)+".jpg",frame)
62 | # cv2.imwrite(path+"/"+str(u)+".jpg", frame)
63 | u = u + 1
64 | print (r"Image No:" + str(u), end = "\r")
65 | elif k == 27:
66 | cv2.destroyAllWindows()
67 | break
--------------------------------------------------------------------------------
/mtcnn-face/face-recognition/face_detection.py:
--------------------------------------------------------------------------------
1 | from mtcnn.mtcnn import MTCNN
2 | import cv2
3 |
4 | cap = cv2.VideoCapture(0)
5 | detector = MTCNN()
6 | while True:
7 | ret, frame = cap.read()
8 | face = (detector.detect_faces(frame))
9 | if len(face) > 0:
10 | for f in face:
11 | b = f['box']
12 | cv2.rectangle(frame, (b[0], b[1]), (b[0]+b[2], b[1]+b[3]), (0,255,0))
13 | cv2.imshow("iamge", frame)
14 | cv2.waitKey(10)
--------------------------------------------------------------------------------
/object_detection/.ipynb_checkpoints/metrics-checkpoint.csv:
--------------------------------------------------------------------------------
1 | PascalBoxes_Precision/mAP@0.5IOU,1.0
2 | PascalBoxes_PerformanceByCategory/AP@0.5IOU/mobile_tower,1.0
3 | WeightedPascalBoxes_Precision/mAP@0.5IOU,1.0
4 | WeightedPascalBoxes_PerformanceByCategory/AP@0.5IOU/mobile_tower,1.0
5 | OpenImagesV2_Precision/mAP@0.5IOU,1.0
6 | OpenImagesV2_PerformanceByCategory/AP@0.5IOU/mobile_tower,1.0
7 | DetectionBoxes_Precision/mAP,0.49999999999999994
8 | DetectionBoxes_Precision/mAP@.50IOU,0.9999999999999999
9 | DetectionBoxes_Precision/mAP@.75IOU,0.0
10 | DetectionBoxes_Precision/mAP (small),0.49999999999999994
11 | DetectionBoxes_Precision/mAP (medium),-1.0
12 | DetectionBoxes_Precision/mAP (large),-1.0
13 | DetectionBoxes_Recall/AR@1,0.5
14 | DetectionBoxes_Recall/AR@10,0.5
15 | DetectionBoxes_Recall/AR@100,0.5
16 | DetectionBoxes_Recall/AR@100 (small),0.5
17 | DetectionBoxes_Recall/AR@100 (medium),-1.0
18 | DetectionBoxes_Recall/AR@100 (large),-1.0
19 |
--------------------------------------------------------------------------------
/object_detection/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/__init__.py
--------------------------------------------------------------------------------
/object_detection/anchor_generators/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/anchor_generators/__init__.py
--------------------------------------------------------------------------------
/object_detection/box_coders/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/box_coders/__init__.py
--------------------------------------------------------------------------------
/object_detection/box_coders/mean_stddev_box_coder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Mean stddev box coder.
17 |
18 | This box coder use the following coding schema to encode boxes:
19 | rel_code = (box_corner - anchor_corner_mean) / anchor_corner_stddev.
20 | """
21 | from object_detection.core import box_coder
22 | from object_detection.core import box_list
23 |
24 |
25 | class MeanStddevBoxCoder(box_coder.BoxCoder):
26 | """Mean stddev box coder."""
27 |
28 | def __init__(self, stddev=0.01):
29 | """Constructor for MeanStddevBoxCoder.
30 |
31 | Args:
32 | stddev: The standard deviation used to encode and decode boxes.
33 | """
34 | self._stddev = stddev
35 |
36 | @property
37 | def code_size(self):
38 | return 4
39 |
40 | def _encode(self, boxes, anchors):
41 | """Encode a box collection with respect to anchor collection.
42 |
43 | Args:
44 | boxes: BoxList holding N boxes to be encoded.
45 | anchors: BoxList of N anchors.
46 |
47 | Returns:
48 | a tensor representing N anchor-encoded boxes
49 |
50 | Raises:
51 | ValueError: if the anchors still have deprecated stddev field.
52 | """
53 | box_corners = boxes.get()
54 | if anchors.has_field('stddev'):
55 | raise ValueError("'stddev' is a parameter of MeanStddevBoxCoder and "
56 | "should not be specified in the box list.")
57 | means = anchors.get()
58 | return (box_corners - means) / self._stddev
59 |
60 | def _decode(self, rel_codes, anchors):
61 | """Decode.
62 |
63 | Args:
64 | rel_codes: a tensor representing N anchor-encoded boxes.
65 | anchors: BoxList of anchors.
66 |
67 | Returns:
68 | boxes: BoxList holding N bounding boxes
69 |
70 | Raises:
71 | ValueError: if the anchors still have deprecated stddev field and expects
72 | the decode method to use stddev value from that field.
73 | """
74 | means = anchors.get()
75 | if anchors.has_field('stddev'):
76 | raise ValueError("'stddev' is a parameter of MeanStddevBoxCoder and "
77 | "should not be specified in the box list.")
78 | box_corners = rel_codes * self._stddev + means
79 | return box_list.BoxList(box_corners)
80 |
--------------------------------------------------------------------------------
/object_detection/box_coders/mean_stddev_box_coder_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.box_coder.mean_stddev_boxcoder."""
17 |
18 | import tensorflow as tf
19 |
20 | from object_detection.box_coders import mean_stddev_box_coder
21 | from object_detection.core import box_list
22 |
23 |
24 | class MeanStddevBoxCoderTest(tf.test.TestCase):
25 |
26 | def testGetCorrectRelativeCodesAfterEncoding(self):
27 | box_corners = [[0.0, 0.0, 0.5, 0.5], [0.0, 0.0, 0.5, 0.5]]
28 | boxes = box_list.BoxList(tf.constant(box_corners))
29 | expected_rel_codes = [[0.0, 0.0, 0.0, 0.0], [-5.0, -5.0, -5.0, -3.0]]
30 | prior_means = tf.constant([[0.0, 0.0, 0.5, 0.5], [0.5, 0.5, 1.0, 0.8]])
31 | priors = box_list.BoxList(prior_means)
32 |
33 | coder = mean_stddev_box_coder.MeanStddevBoxCoder(stddev=0.1)
34 | rel_codes = coder.encode(boxes, priors)
35 | with self.test_session() as sess:
36 | rel_codes_out = sess.run(rel_codes)
37 | self.assertAllClose(rel_codes_out, expected_rel_codes)
38 |
39 | def testGetCorrectBoxesAfterDecoding(self):
40 | rel_codes = tf.constant([[0.0, 0.0, 0.0, 0.0], [-5.0, -5.0, -5.0, -3.0]])
41 | expected_box_corners = [[0.0, 0.0, 0.5, 0.5], [0.0, 0.0, 0.5, 0.5]]
42 | prior_means = tf.constant([[0.0, 0.0, 0.5, 0.5], [0.5, 0.5, 1.0, 0.8]])
43 | priors = box_list.BoxList(prior_means)
44 |
45 | coder = mean_stddev_box_coder.MeanStddevBoxCoder(stddev=0.1)
46 | decoded_boxes = coder.decode(rel_codes, priors)
47 | decoded_box_corners = decoded_boxes.get()
48 | with self.test_session() as sess:
49 | decoded_out = sess.run(decoded_box_corners)
50 | self.assertAllClose(decoded_out, expected_box_corners)
51 |
52 |
53 | if __name__ == '__main__':
54 | tf.test.main()
55 |
--------------------------------------------------------------------------------
/object_detection/builders/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/builders/__init__.py
--------------------------------------------------------------------------------
/object_detection/builders/graph_rewriter_builder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Functions for quantized training and evaluation."""
16 |
17 | import tensorflow as tf
18 |
19 |
20 | def build(graph_rewriter_config, is_training):
21 | """Returns a function that modifies default graph based on options.
22 |
23 | Args:
24 | graph_rewriter_config: graph_rewriter_pb2.GraphRewriter proto.
25 | is_training: whether in training of eval mode.
26 | """
27 | def graph_rewrite_fn():
28 | """Function to quantize weights and activation of the default graph."""
29 | if (graph_rewriter_config.quantization.weight_bits != 8 or
30 | graph_rewriter_config.quantization.activation_bits != 8):
31 | raise ValueError('Only 8bit quantization is supported')
32 |
33 | # Quantize the graph by inserting quantize ops for weights and activations
34 | if is_training:
35 | tf.contrib.quantize.create_training_graph(
36 | input_graph=tf.get_default_graph(),
37 | quant_delay=graph_rewriter_config.quantization.delay)
38 | else:
39 | tf.contrib.quantize.create_eval_graph(input_graph=tf.get_default_graph())
40 |
41 | tf.contrib.layers.summarize_collection('quant_vars')
42 | return graph_rewrite_fn
43 |
--------------------------------------------------------------------------------
/object_detection/builders/graph_rewriter_builder_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Tests for graph_rewriter_builder."""
16 | import mock
17 | import tensorflow as tf
18 | from object_detection.builders import graph_rewriter_builder
19 | from object_detection.protos import graph_rewriter_pb2
20 |
21 |
22 | class QuantizationBuilderTest(tf.test.TestCase):
23 |
24 | def testQuantizationBuilderSetsUpCorrectTrainArguments(self):
25 | with mock.patch.object(
26 | tf.contrib.quantize, 'create_training_graph') as mock_quant_fn:
27 | with mock.patch.object(tf.contrib.layers,
28 | 'summarize_collection') as mock_summarize_col:
29 | graph_rewriter_proto = graph_rewriter_pb2.GraphRewriter()
30 | graph_rewriter_proto.quantization.delay = 10
31 | graph_rewriter_proto.quantization.weight_bits = 8
32 | graph_rewriter_proto.quantization.activation_bits = 8
33 | graph_rewrite_fn = graph_rewriter_builder.build(
34 | graph_rewriter_proto, is_training=True)
35 | graph_rewrite_fn()
36 | _, kwargs = mock_quant_fn.call_args
37 | self.assertEqual(kwargs['input_graph'], tf.get_default_graph())
38 | self.assertEqual(kwargs['quant_delay'], 10)
39 | mock_summarize_col.assert_called_with('quant_vars')
40 |
41 | def testQuantizationBuilderSetsUpCorrectEvalArguments(self):
42 | with mock.patch.object(tf.contrib.quantize,
43 | 'create_eval_graph') as mock_quant_fn:
44 | with mock.patch.object(tf.contrib.layers,
45 | 'summarize_collection') as mock_summarize_col:
46 | graph_rewriter_proto = graph_rewriter_pb2.GraphRewriter()
47 | graph_rewriter_proto.quantization.delay = 10
48 | graph_rewrite_fn = graph_rewriter_builder.build(
49 | graph_rewriter_proto, is_training=False)
50 | graph_rewrite_fn()
51 | _, kwargs = mock_quant_fn.call_args
52 | self.assertEqual(kwargs['input_graph'], tf.get_default_graph())
53 | mock_summarize_col.assert_called_with('quant_vars')
54 |
55 |
56 | if __name__ == '__main__':
57 | tf.test.main()
58 |
--------------------------------------------------------------------------------
/object_detection/builders/matcher_builder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """A function to build an object detection matcher from configuration."""
17 |
18 | from object_detection.matchers import argmax_matcher
19 | from object_detection.matchers import bipartite_matcher
20 | from object_detection.protos import matcher_pb2
21 |
22 |
23 | def build(matcher_config):
24 | """Builds a matcher object based on the matcher config.
25 |
26 | Args:
27 | matcher_config: A matcher.proto object containing the config for the desired
28 | Matcher.
29 |
30 | Returns:
31 | Matcher based on the config.
32 |
33 | Raises:
34 | ValueError: On empty matcher proto.
35 | """
36 | if not isinstance(matcher_config, matcher_pb2.Matcher):
37 | raise ValueError('matcher_config not of type matcher_pb2.Matcher.')
38 | if matcher_config.WhichOneof('matcher_oneof') == 'argmax_matcher':
39 | matcher = matcher_config.argmax_matcher
40 | matched_threshold = unmatched_threshold = None
41 | if not matcher.ignore_thresholds:
42 | matched_threshold = matcher.matched_threshold
43 | unmatched_threshold = matcher.unmatched_threshold
44 | return argmax_matcher.ArgMaxMatcher(
45 | matched_threshold=matched_threshold,
46 | unmatched_threshold=unmatched_threshold,
47 | negatives_lower_than_unmatched=matcher.negatives_lower_than_unmatched,
48 | force_match_for_each_row=matcher.force_match_for_each_row,
49 | use_matmul_gather=matcher.use_matmul_gather)
50 | if matcher_config.WhichOneof('matcher_oneof') == 'bipartite_matcher':
51 | matcher = matcher_config.bipartite_matcher
52 | return bipartite_matcher.GreedyBipartiteMatcher(matcher.use_matmul_gather)
53 | raise ValueError('Empty matcher.')
54 |
--------------------------------------------------------------------------------
/object_detection/builders/region_similarity_calculator_builder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Builder for region similarity calculators."""
17 |
18 | from object_detection.core import region_similarity_calculator
19 | from object_detection.protos import region_similarity_calculator_pb2
20 |
21 |
22 | def build(region_similarity_calculator_config):
23 | """Builds region similarity calculator based on the configuration.
24 |
25 | Builds one of [IouSimilarity, IoaSimilarity, NegSqDistSimilarity] objects. See
26 | core/region_similarity_calculator.proto for details.
27 |
28 | Args:
29 | region_similarity_calculator_config: RegionSimilarityCalculator
30 | configuration proto.
31 |
32 | Returns:
33 | region_similarity_calculator: RegionSimilarityCalculator object.
34 |
35 | Raises:
36 | ValueError: On unknown region similarity calculator.
37 | """
38 |
39 | if not isinstance(
40 | region_similarity_calculator_config,
41 | region_similarity_calculator_pb2.RegionSimilarityCalculator):
42 | raise ValueError(
43 | 'region_similarity_calculator_config not of type '
44 | 'region_similarity_calculator_pb2.RegionsSimilarityCalculator')
45 |
46 | similarity_calculator = region_similarity_calculator_config.WhichOneof(
47 | 'region_similarity')
48 | if similarity_calculator == 'iou_similarity':
49 | return region_similarity_calculator.IouSimilarity()
50 | if similarity_calculator == 'ioa_similarity':
51 | return region_similarity_calculator.IoaSimilarity()
52 | if similarity_calculator == 'neg_sq_dist_similarity':
53 | return region_similarity_calculator.NegSqDistSimilarity()
54 |
55 | raise ValueError('Unknown region similarity calculator.')
56 |
57 |
--------------------------------------------------------------------------------
/object_detection/builders/region_similarity_calculator_builder_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for region_similarity_calculator_builder."""
17 |
18 | import tensorflow as tf
19 |
20 | from google.protobuf import text_format
21 | from object_detection.builders import region_similarity_calculator_builder
22 | from object_detection.core import region_similarity_calculator
23 | from object_detection.protos import region_similarity_calculator_pb2 as sim_calc_pb2
24 |
25 |
26 | class RegionSimilarityCalculatorBuilderTest(tf.test.TestCase):
27 |
28 | def testBuildIoaSimilarityCalculator(self):
29 | similarity_calc_text_proto = """
30 | ioa_similarity {
31 | }
32 | """
33 | similarity_calc_proto = sim_calc_pb2.RegionSimilarityCalculator()
34 | text_format.Merge(similarity_calc_text_proto, similarity_calc_proto)
35 | similarity_calc = region_similarity_calculator_builder.build(
36 | similarity_calc_proto)
37 | self.assertTrue(isinstance(similarity_calc,
38 | region_similarity_calculator.IoaSimilarity))
39 |
40 | def testBuildIouSimilarityCalculator(self):
41 | similarity_calc_text_proto = """
42 | iou_similarity {
43 | }
44 | """
45 | similarity_calc_proto = sim_calc_pb2.RegionSimilarityCalculator()
46 | text_format.Merge(similarity_calc_text_proto, similarity_calc_proto)
47 | similarity_calc = region_similarity_calculator_builder.build(
48 | similarity_calc_proto)
49 | self.assertTrue(isinstance(similarity_calc,
50 | region_similarity_calculator.IouSimilarity))
51 |
52 | def testBuildNegSqDistSimilarityCalculator(self):
53 | similarity_calc_text_proto = """
54 | neg_sq_dist_similarity {
55 | }
56 | """
57 | similarity_calc_proto = sim_calc_pb2.RegionSimilarityCalculator()
58 | text_format.Merge(similarity_calc_text_proto, similarity_calc_proto)
59 | similarity_calc = region_similarity_calculator_builder.build(
60 | similarity_calc_proto)
61 | self.assertTrue(isinstance(similarity_calc,
62 | region_similarity_calculator.
63 | NegSqDistSimilarity))
64 |
65 |
66 | if __name__ == '__main__':
67 | tf.test.main()
68 |
--------------------------------------------------------------------------------
/object_detection/constants.py:
--------------------------------------------------------------------------------
1 | '''
2 | Hold all relevant configuration constants for satellite imagery.
3 |
4 | '''
5 |
6 | # original images
7 | PATH_RAW_DATA="/media/ssd1/cell_data/v5/"
8 |
9 | # Pb TXT for classes
10 | CLASSES_DICT=
11 |
12 | # TF records
13 | PATH_DATA="/media/ssd1/sat_data/"
14 |
15 | # TEST TF Record
16 | PATH_TEST_DATA="/media/ssd1/sat_data/satellite_test.record"
17 |
18 | # checkpoints
19 | PATH_CHECKPOINTS="/home/user/checkpoint"
20 |
21 | # Models
22 | PATH_MODELS="object_detection/models/satellite/"
23 |
24 | # INFERENCE_FRCNN
25 | PATH_FRCNN_INFERENCE="/media/ssd1/sat_data_inferences/faster_rcnn/large/detections.tfrecord"
26 |
--------------------------------------------------------------------------------
/object_detection/core/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/object_detection/core/box_coder_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.core.box_coder."""
17 |
18 | import tensorflow as tf
19 |
20 | from object_detection.core import box_coder
21 | from object_detection.core import box_list
22 |
23 |
24 | class MockBoxCoder(box_coder.BoxCoder):
25 | """Test BoxCoder that encodes/decodes using the multiply-by-two function."""
26 |
27 | def code_size(self):
28 | return 4
29 |
30 | def _encode(self, boxes, anchors):
31 | return 2.0 * boxes.get()
32 |
33 | def _decode(self, rel_codes, anchors):
34 | return box_list.BoxList(rel_codes / 2.0)
35 |
36 |
37 | class BoxCoderTest(tf.test.TestCase):
38 |
39 | def test_batch_decode(self):
40 | mock_anchor_corners = tf.constant(
41 | [[0, 0.1, 0.2, 0.3], [0.2, 0.4, 0.4, 0.6]], tf.float32)
42 | mock_anchors = box_list.BoxList(mock_anchor_corners)
43 | mock_box_coder = MockBoxCoder()
44 |
45 | expected_boxes = [[[0.0, 0.1, 0.5, 0.6], [0.5, 0.6, 0.7, 0.8]],
46 | [[0.1, 0.2, 0.3, 0.4], [0.7, 0.8, 0.9, 1.0]]]
47 |
48 | encoded_boxes_list = [mock_box_coder.encode(
49 | box_list.BoxList(tf.constant(boxes)), mock_anchors)
50 | for boxes in expected_boxes]
51 | encoded_boxes = tf.stack(encoded_boxes_list)
52 | decoded_boxes = box_coder.batch_decode(
53 | encoded_boxes, mock_box_coder, mock_anchors)
54 |
55 | with self.test_session() as sess:
56 | decoded_boxes_result = sess.run(decoded_boxes)
57 | self.assertAllClose(expected_boxes, decoded_boxes_result)
58 |
59 |
60 | if __name__ == '__main__':
61 | tf.test.main()
62 |
--------------------------------------------------------------------------------
/object_detection/core/data_decoder.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Interface for data decoders.
17 |
18 | Data decoders decode the input data and return a dictionary of tensors keyed by
19 | the entries in core.reader.Fields.
20 | """
21 | from abc import ABCMeta
22 | from abc import abstractmethod
23 |
24 |
25 | class DataDecoder(object):
26 | """Interface for data decoders."""
27 | __metaclass__ = ABCMeta
28 |
29 | @abstractmethod
30 | def decode(self, data):
31 | """Return a single image and associated labels.
32 |
33 | Args:
34 | data: a string tensor holding a serialized protocol buffer corresponding
35 | to data for a single image.
36 |
37 | Returns:
38 | tensor_dict: a dictionary containing tensors. Possible keys are defined in
39 | reader.Fields.
40 | """
41 | pass
42 |
--------------------------------------------------------------------------------
/object_detection/core/data_parser.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Interface for data parsers.
16 |
17 | Data parser parses input data and returns a dictionary of numpy arrays
18 | keyed by the entries in standard_fields.py. Since the parser parses records
19 | to numpy arrays (materialized tensors) directly, it is used to read data for
20 | evaluation/visualization; to parse the data during training, DataDecoder should
21 | be used.
22 | """
23 | from abc import ABCMeta
24 | from abc import abstractmethod
25 |
26 |
27 | class DataToNumpyParser(object):
28 | __metaclass__ = ABCMeta
29 |
30 | @abstractmethod
31 | def parse(self, input_data):
32 | """Parses input and returns a numpy array or a dictionary of numpy arrays.
33 |
34 | Args:
35 | input_data: an input data
36 |
37 | Returns:
38 | A numpy array or a dictionary of numpy arrays or None, if input
39 | cannot be parsed.
40 | """
41 | pass
42 |
--------------------------------------------------------------------------------
/object_detection/core/prefetcher.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Provides functions to prefetch tensors to feed into models."""
17 | import tensorflow as tf
18 |
19 |
20 | def prefetch(tensor_dict, capacity):
21 | """Creates a prefetch queue for tensors.
22 |
23 | Creates a FIFO queue to asynchronously enqueue tensor_dicts and returns a
24 | dequeue op that evaluates to a tensor_dict. This function is useful in
25 | prefetching preprocessed tensors so that the data is readily available for
26 | consumers.
27 |
28 | Example input pipeline when you don't need batching:
29 | ----------------------------------------------------
30 | key, string_tensor = slim.parallel_reader.parallel_read(...)
31 | tensor_dict = decoder.decode(string_tensor)
32 | tensor_dict = preprocessor.preprocess(tensor_dict, ...)
33 | prefetch_queue = prefetcher.prefetch(tensor_dict, capacity=20)
34 | tensor_dict = prefetch_queue.dequeue()
35 | outputs = Model(tensor_dict)
36 | ...
37 | ----------------------------------------------------
38 |
39 | For input pipelines with batching, refer to core/batcher.py
40 |
41 | Args:
42 | tensor_dict: a dictionary of tensors to prefetch.
43 | capacity: the size of the prefetch queue.
44 |
45 | Returns:
46 | a FIFO prefetcher queue
47 | """
48 | names = list(tensor_dict.keys())
49 | dtypes = [t.dtype for t in tensor_dict.values()]
50 | shapes = [t.get_shape() for t in tensor_dict.values()]
51 | prefetch_queue = tf.PaddingFIFOQueue(capacity, dtypes=dtypes,
52 | shapes=shapes,
53 | names=names,
54 | name='prefetch_queue')
55 | enqueue_op = prefetch_queue.enqueue(tensor_dict)
56 | tf.train.queue_runner.add_queue_runner(tf.train.queue_runner.QueueRunner(
57 | prefetch_queue, [enqueue_op]))
58 | tf.summary.scalar('queue/%s/fraction_of_%d_full' % (prefetch_queue.name,
59 | capacity),
60 | tf.to_float(prefetch_queue.size()) * (1. / capacity))
61 | return prefetch_queue
62 |
--------------------------------------------------------------------------------
/object_detection/data_decoders/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/data_decoders/__init__.py
--------------------------------------------------------------------------------
/object_detection/dataset_tools/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/dataset_tools/__init__.py
--------------------------------------------------------------------------------
/object_detection/dataset_tools/check_validity.py:
--------------------------------------------------------------------------------
1 | '''
2 | Perform vailidity tests on given satellite data
3 |
4 | '''
5 |
6 | import numpy as np
7 | import os
8 | import six.moves.urllib as urllib
9 | import sys
10 | import tensorflow as tf
11 |
12 | from matplotlib import pyplot as plt
13 | from PIL import Image
14 | import re
15 |
16 | import constants
17 |
--------------------------------------------------------------------------------
/object_detection/faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28/checkpoint:
--------------------------------------------------------------------------------
1 | model_checkpoint_path: "model.ckpt"
2 | all_model_checkpoint_paths: "model.ckpt"
3 |
--------------------------------------------------------------------------------
/object_detection/faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28_tf_14/checkpoint:
--------------------------------------------------------------------------------
1 | model_checkpoint_path: "model.ckpt"
2 | all_model_checkpoint_paths: "model.ckpt"
3 |
--------------------------------------------------------------------------------
/object_detection/g3doc/exporting_models.md:
--------------------------------------------------------------------------------
1 | # Exporting a trained model for inference
2 |
3 | After your model has been trained, you should export it to a Tensorflow
4 | graph proto. A checkpoint will typically consist of three files:
5 |
6 | * model.ckpt-${CHECKPOINT_NUMBER}.data-00000-of-00001
7 | * model.ckpt-${CHECKPOINT_NUMBER}.index
8 | * model.ckpt-${CHECKPOINT_NUMBER}.meta
9 |
10 | After you've identified a candidate checkpoint to export, run the following
11 | command from tensorflow/models/research:
12 |
13 | ``` bash
14 | # From tensorflow/models/research/
15 | python object_detection/export_inference_graph.py \
16 | --input_type image_tensor \
17 | --pipeline_config_path ${PIPELINE_CONFIG_PATH} \
18 | --trained_checkpoint_prefix ${TRAIN_PATH} \
19 | --output_directory ${EXPORT_DIR}
20 | ```
21 |
22 | Afterwards, you should see the directory ${EXPORT_DIR} containing the following:
23 |
24 | * output_inference_graph.pb, the frozen graph format of the exported model
25 | * saved_model/, a directory containing the saved model format of the exported model
26 | * model.ckpt.*, the model checkpoints used for exporting
27 | * checkpoint, a file specifying to restore included checkpoint files
28 |
--------------------------------------------------------------------------------
/object_detection/g3doc/faq.md:
--------------------------------------------------------------------------------
1 | # Frequently Asked Questions
2 |
3 | ## Q: AttributeError: 'module' object has no attribute 'BackupHandler'
4 | A: This BackupHandler (tf.contrib.slim.tfexample_decoder.BackupHandler) was
5 | introduced in tensorflow 1.5.0 so runing with earlier versions may cause this
6 | issue. It now has been replaced by
7 | object_detection.data_decoders.tf_example_decoder.BackupHandler. Whoever sees
8 | this issue should be able to resolve it by syncing your fork to HEAD.
9 | Same for LookupTensor.
10 |
11 | ## Q: AttributeError: 'module' object has no attribute 'LookupTensor'
12 | A: Similar to BackupHandler, syncing your fork to HEAD should make it work.
13 |
14 | ## Q: Why can't I get the inference time as reported in model zoo?
15 | A: The inference time reported in model zoo is mean time of testing hundreds of
16 | images with an internal machine. As mentioned in
17 | [Tensorflow detection model zoo](detection_model_zoo.md), this speed depends
18 | highly on one's specific hardware configuration and should be treated more as
19 | relative timing.
20 |
--------------------------------------------------------------------------------
/object_detection/g3doc/preparing_inputs.md:
--------------------------------------------------------------------------------
1 | # Preparing Inputs
2 |
3 | Tensorflow Object Detection API reads data using the TFRecord file format. Two
4 | sample scripts (`create_pascal_tf_record.py` and `create_pet_tf_record.py`) are
5 | provided to convert from the PASCAL VOC dataset and Oxford-IIIT Pet dataset to
6 | TFRecords.
7 |
8 | ## Generating the PASCAL VOC TFRecord files.
9 |
10 | The raw 2012 PASCAL VOC data set is located
11 | [here](http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar).
12 | To download, extract and convert it to TFRecords, run the following commands
13 | below:
14 |
15 | ```bash
16 | # From tensorflow/models/research/
17 | wget http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
18 | tar -xvf VOCtrainval_11-May-2012.tar
19 | python object_detection/dataset_tools/create_pascal_tf_record.py \
20 | --label_map_path=object_detection/data/pascal_label_map.pbtxt \
21 | --data_dir=VOCdevkit --year=VOC2012 --set=train \
22 | --output_path=pascal_train.record
23 | python object_detection/dataset_tools/create_pascal_tf_record.py \
24 | --label_map_path=object_detection/data/pascal_label_map.pbtxt \
25 | --data_dir=VOCdevkit --year=VOC2012 --set=val \
26 | --output_path=pascal_val.record
27 | ```
28 |
29 | You should end up with two TFRecord files named `pascal_train.record` and
30 | `pascal_val.record` in the `tensorflow/models/research/` directory.
31 |
32 | The label map for the PASCAL VOC data set can be found at
33 | `object_detection/data/pascal_label_map.pbtxt`.
34 |
35 | ## Generating the Oxford-IIIT Pet TFRecord files.
36 |
37 | The Oxford-IIIT Pet data set is located
38 | [here](http://www.robots.ox.ac.uk/~vgg/data/pets/). To download, extract and
39 | convert it to TFRecrods, run the following commands below:
40 |
41 | ```bash
42 | # From tensorflow/models/research/
43 | wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/images.tar.gz
44 | wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/annotations.tar.gz
45 | tar -xvf annotations.tar.gz
46 | tar -xvf images.tar.gz
47 | python object_detection/dataset_tools/create_pet_tf_record.py \
48 | --label_map_path=object_detection/data/pet_label_map.pbtxt \
49 | --data_dir=`pwd` \
50 | --output_dir=`pwd`
51 | ```
52 |
53 | You should end up with two TFRecord files named `pet_train.record` and
54 | `pet_val.record` in the `tensorflow/models/research/` directory.
55 |
56 | The label map for the Pet dataset can be found at
57 | `object_detection/data/pet_label_map.pbtxt`.
58 |
--------------------------------------------------------------------------------
/object_detection/g3doc/running_locally.md:
--------------------------------------------------------------------------------
1 | # Running Locally
2 |
3 | This page walks through the steps required to train an object detection model
4 | on a local machine. It assumes the reader has completed the
5 | following prerequisites:
6 |
7 | 1. The Tensorflow Object Detection API has been installed as documented in the
8 | [installation instructions](installation.md). This includes installing library
9 | dependencies, compiling the configuration protobufs and setting up the Python
10 | environment.
11 | 2. A valid data set has been created. See [this page](preparing_inputs.md) for
12 | instructions on how to generate a dataset for the PASCAL VOC challenge or the
13 | Oxford-IIIT Pet dataset.
14 | 3. A Object Detection pipeline configuration has been written. See
15 | [this page](configuring_jobs.md) for details on how to write a pipeline configuration.
16 |
17 | ## Recommended Directory Structure for Training and Evaluation
18 |
19 | ```
20 | +data
21 | -label_map file
22 | -train TFRecord file
23 | -eval TFRecord file
24 | +models
25 | + model
26 | -pipeline config file
27 | +train
28 | +eval
29 | ```
30 |
31 | ## Running the Training Job
32 |
33 | A local training job can be run with the following command:
34 |
35 | ```bash
36 | # From the tensorflow/models/research/ directory
37 | python object_detection/train.py \
38 | --logtostderr \
39 | --pipeline_config_path=${PATH_TO_YOUR_PIPELINE_CONFIG} \
40 | --train_dir=${PATH_TO_TRAIN_DIR}
41 | ```
42 |
43 | where `${PATH_TO_YOUR_PIPELINE_CONFIG}` points to the pipeline config and
44 | `${PATH_TO_TRAIN_DIR}` points to the directory in which training checkpoints
45 | and events will be written to. By default, the training job will
46 | run indefinitely until the user kills it.
47 |
48 | ## Running the Evaluation Job
49 |
50 | Evaluation is run as a separate job. The eval job will periodically poll the
51 | train directory for new checkpoints and evaluate them on a test dataset. The
52 | job can be run using the following command:
53 |
54 | ```bash
55 | # From the tensorflow/models/research/ directory
56 | python object_detection/eval.py \
57 | --logtostderr \
58 | --pipeline_config_path=${PATH_TO_YOUR_PIPELINE_CONFIG} \
59 | --checkpoint_dir=${PATH_TO_TRAIN_DIR} \
60 | --eval_dir=${PATH_TO_EVAL_DIR}
61 | ```
62 |
63 | where `${PATH_TO_YOUR_PIPELINE_CONFIG}` points to the pipeline config,
64 | `${PATH_TO_TRAIN_DIR}` points to the directory in which training checkpoints
65 | were saved (same as the training job) and `${PATH_TO_EVAL_DIR}` points to the
66 | directory in which evaluation events will be saved. As with the training job,
67 | the eval job run until terminated by default.
68 |
69 | ## Running Tensorboard
70 |
71 | Progress for training and eval jobs can be inspected using Tensorboard. If
72 | using the recommended directory structure, Tensorboard can be run using the
73 | following command:
74 |
75 | ```bash
76 | tensorboard --logdir=${PATH_TO_MODEL_DIRECTORY}
77 | ```
78 |
79 | where `${PATH_TO_MODEL_DIRECTORY}` points to the directory that contains the
80 | train and eval directories. Please note it may take Tensorboard a couple minutes
81 | to populate with data.
82 |
--------------------------------------------------------------------------------
/object_detection/g3doc/running_notebook.md:
--------------------------------------------------------------------------------
1 | # Quick Start: Jupyter notebook for off-the-shelf inference
2 |
3 | If you'd like to hit the ground running and run detection on a few example
4 | images right out of the box, we recommend trying out the Jupyter notebook demo.
5 | To run the Jupyter notebook, run the following command from
6 | `tensorflow/models/research/object_detection`:
7 |
8 | ```
9 | # From tensorflow/models/research/object_detection
10 | jupyter notebook
11 | ```
12 |
13 | The notebook should open in your favorite web browser. Click the
14 | [`object_detection_tutorial.ipynb`](../object_detection_tutorial.ipynb) link to
15 | open the demo.
16 |
--------------------------------------------------------------------------------
/object_detection/inference/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/inference/__init__.py
--------------------------------------------------------------------------------
/object_detection/inference/faster_rcnn_batch/104001000FB77500.sh:
--------------------------------------------------------------------------------
1 | echo $(date -u) Tile 104001000FB77500 Starting >> tilelog.txt
2 | CUDA_VISIBLE_DEVICES='0' python object_detection/inference/data_infer_batch.py \
3 | --input_path="/media/ssd1/data/104001000FB77500_jpg.tif_tiles/19/" \
4 | --inference_graph="/media/ssd1/sat_data_models/faster_rcnn/large/export/frozen_inference_graph.pb" \
5 | --output_path="/media/ssd1/tile_output/104001000FB77500" \
6 | --shard_path="/media/ssd1/tile_output/104001000FB77500" \
7 | --batch_size=8 \
8 | --shard=0 \
9 | --shard_size=2 \
10 | --vis_path="/media/ssd1/tile_output/vis/104001000FB77500" \
11 | --restore_from_json=False
12 |
13 | CUDA_VISIBLE_DEVICES='3' python object_detection/inference/data_infer_batch.py \
14 | --input_path="/media/ssd1/data/104001000FB77500_jpg.tif_tiles/19/" \
15 | --inference_graph="/media/ssd1/sat_data_models/faster_rcnn/large/export/frozen_inference_graph.pb" \
16 | --output_path="/media/ssd1/tile_output/104001000FB77500" \
17 | --shard_path="/media/ssd1/tile_output/104001000FB77500" \
18 | --batch_size=8 \
19 | --shard=1 \
20 | --shard_size=2 \
21 | --vis_path="/media/ssd1/tile_output/vis/104001000FB77500" \
22 | --restore_from_json=False
23 |
--------------------------------------------------------------------------------
/object_detection/inference/faster_rcnn_batch/1040010018255600.sh:
--------------------------------------------------------------------------------
1 | CUDA_VISIBLE_DEVICES='0' \python object_detection/inference/data_infer_batch.py \
2 | --input_path="/media/ssd1/data/1040010018255600_jpg.tif_tiles/19/" \
3 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
4 | --output_path="/media/ssd1/tile_output_mask_rcnn/" \
5 | --shard_path="/media/ssd1/tile_output_mask_rcnn/" \
6 | --batch_size=16 \
7 | --shard=0
8 | --shard_size=2 \
9 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis" \
10 | --restore_from_json=False
11 |
12 | CUDA_VISIBLE_DEVICES='3' python object_detection/inference/data_infer_batch.py \
13 | --input_path="/media/ssd1/data/1040010018255600_jpg.tif_tiles/19/" \
14 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
15 | --output_path="/media/ssd1/tile_output_mask_rcnn/" \
16 | --shard_path="/media/ssd1/tile_output_mask_rcnn/" \
17 | --batch_size=16 \
18 | --shard=1 \
19 | --shard_size=2 \
20 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis" \
21 | --restore_from_json=False
22 |
--------------------------------------------------------------------------------
/object_detection/inference/faster_rcnn_batch/104001002F3A8700.sh:
--------------------------------------------------------------------------------
1 | echo $(date -u) Tile 104001002F3A8700 starting >> tilelog.txt
2 | CUDA_VISIBLE_DEVICES='0' python object_detection/inference/data_infer_batch.py \
3 | --input_path="/media/ssd1/data/104001002F3A8700_jpg.tif_tiles/19/" \
4 | --inference_graph="/media/ssd1/sat_data_models/faster_rcnn/large/export/frozen_inference_graph.pb" \
5 | --output_path="/media/ssd1/tile_output/104001002F3A8700" \
6 | --shard_path="/media/ssd1/tile_output/104001002F3A8700" \
7 | --batch_size=8 \
8 | --shard=0 \
9 | --shard_size=2 \
10 | --vis_path="/media/ssd1/tile_output/vis/104001002F3A8700" \
11 | --restore_from_json=False
12 |
13 | CUDA_VISIBLE_DEVICES='3' python object_detection/inference/data_infer_batch.py \
14 | --input_path="/media/ssd1/data/104001002F3A8700_jpg.tif_tiles/19/" \
15 | --inference_graph="/media/ssd1/sat_data_models/faster_rcnn/large/export/frozen_inference_graph.pb" \
16 | --output_path="/media/ssd1/tile_output/104001002F3A8700" \
17 | --shard_path="/media/ssd1/tile_output/104001002F3A8700" \
18 | --batch_size=8 \
19 | --shard=1 \
20 | --shard_size=2 \
21 | --vis_path="/media/ssd1/tile_output/vis/104001002F3A8700" \
22 | --restore_from_json=False
23 |
--------------------------------------------------------------------------------
/object_detection/inference/faster_rcnn_batch/10400100305A7E00.sh:
--------------------------------------------------------------------------------
1 | echo $(date -u) Tile 10400100305A7E00 starting >> tilelog.txt
2 | CUDA_VISIBLE_DEVICES='0' python object_detection/inference/data_infer_batch.py \
3 | --input_path="/media/ssd1/data/10400100305A7E00_jpg.tif_tiles/19/" \
4 | --inference_graph="/media/ssd1/sat_data_models/faster_rcnn/large/export/frozen_inference_graph.pb" \
5 | --output_path="/media/ssd1/tile_output/10400100305A7E00" \
6 | --shard_path="/media/ssd1/tile_output/10400100305A7E00" \
7 | --batch_size=8 \
8 | --shard=0 \
9 | --shard_size=2 \
10 | --vis_path="/media/ssd1/tile_output/vis/10400100305A7E00" \
11 | --restore_from_json=False
12 |
13 | CUDA_VISIBLE_DEVICES='3' python object_detection/inference/data_infer_batch.py \
14 | --input_path="/media/ssd1/data/10400100305A7E00_jpg.tif_tiles/19/" \
15 | --inference_graph="/media/ssd1/sat_data_models/faster_rcnn/large/export/frozen_inference_graph.pb" \
16 | --output_path="/media/ssd1/tile_output/10400100305A7E00" \
17 | --shard_path="/media/ssd1/tile_output/10400100305A7E00" \
18 | --batch_size=8 \
19 | --shard=1 \
20 | --shard_size=2 \
21 | --vis_path="/media/ssd1/tile_output/vis/10400100305A7E00" \
22 | --restore_from_json=False
23 |
--------------------------------------------------------------------------------
/object_detection/inference/faster_rcnn_batch/run.sh:
--------------------------------------------------------------------------------
1 | bash object_detection/inference/faster_rcnn_batch/10400100305A7E00.sh
2 | bash object_detection/inference/faster_rcnn_batch/1040010018255600.sh
3 |
--------------------------------------------------------------------------------
/object_detection/inference/mask_rcnn_batch/104001000FB77500.sh:
--------------------------------------------------------------------------------
1 | echo $(date -u) MASK Tile 104001000FB77500 Starting >> tilelog.txt
2 | CUDA_VISIBLE_DEVICES='0' python object_detection/inference/data_infer_batch.py \
3 | --input_path="/media/ssd1/data/104001000FB77500_jpg.tif_tiles/19/" \
4 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
5 | --output_path="/media/ssd1/tile_output_mask_rcnn/104001000FB77500" \
6 | --shard_path="/media/ssd1/tile_output_mask_rcnn/104001000FB77500" \
7 | --batch_size=16 \
8 | --shard=0 \
9 | --shard_size=2 \
10 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis/104001000FB77500" \
11 | --restore_from_json=False &
12 |
13 |
14 | CUDA_VISIBLE_DEVICES='3' python object_detection/inference/data_infer_batch.py \
15 | --input_path="/media/ssd1/data/104001000FB77500_jpg.tif_tiles/19/" \
16 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
17 | --output_path="/media/ssd1/tile_output_mask_rcnn/104001000FB77500" \
18 | --shard_path="/media/ssd1/tile_output_mask_rcnn/104001000FB77500" \
19 | --batch_size=16 \
20 | --shard=1 \
21 | --shard_size=2 \
22 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis/104001000FB77500" \
23 | --restore_from_json=False
24 |
--------------------------------------------------------------------------------
/object_detection/inference/mask_rcnn_batch/1040010010608200.sh:
--------------------------------------------------------------------------------
1 | echo $(date -u) MASK Tile 1040010010608200 starting>>tilelog.txt
2 | # 1040010010608200
3 |
4 | CUDA_VISIBLE_DEVICES='0' python object_detection/inference/data_infer_batch.py \
5 | --input_path="/media/ssd1/data/1040010010608200_jpg.tif_tiles/19/" \
6 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
7 | --output_path="/media/ssd1/tile_output_mask_rcnn/1040010010608200" \
8 | --shard_path="/media/ssd1/tile_output_mask_rcnn/1040010010608200" \
9 | --batch_size=16 \
10 | --shard=0 \
11 | --shard_size=2 \
12 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis/1040010010608200" \
13 | --restore_from_json=False &
14 |
15 | CUDA_VISIBLE_DEVICES='3' python object_detection/inference/data_infer_batch.py \
16 | --input_path="/media/ssd1/data/1040010010608200_jpg.tif_tiles/19/" \
17 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
18 | --output_path="/media/ssd1/tile_output_mask_rcnn/1040010010608200" \
19 | --shard_path="/media/ssd1/tile_output_mask_rcnn/1040010010608200" \
20 | --batch_size=16 \
21 | --shard=1 \
22 | --shard_size=2 \
23 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis/1040010010608200" \
24 | --restore_from_json=False
25 |
--------------------------------------------------------------------------------
/object_detection/inference/mask_rcnn_batch/1040010018255600.sh:
--------------------------------------------------------------------------------
1 | echo $(date -u) MASK Tile 1040010018255600 starting>>tilelog.txt
2 | # 1040010010608200
3 |
4 | CUDA_VISIBLE_DEVICES='0' python object_detection/inference/data_infer_batch.py \
5 | --input_path="/media/ssd1/data/1040010018255600_jpg.tif_tiles/19/" \
6 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
7 | --output_path="/media/ssd1/tile_output_mask_rcnn/1040010018255600" \
8 | --shard_path="/media/ssd1/tile_output_mask_rcnn/1040010018255600" \
9 | --batch_size=16 \
10 | --shard=0 \
11 | --shard_size=2 \
12 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis/1040010018255600" \
13 | --restore_from_json=False
14 |
15 | CUDA_VISIBLE_DEVICES='3' python object_detection/inference/data_infer_batch.py \
16 | --input_path="/media/ssd1/data/1040010018255600_jpg.tif_tiles/19/" \
17 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
18 | --output_path="/media/ssd1/tile_output_mask_rcnn/1040010018255600" \
19 | --shard_path="/media/ssd1/tile_output_mask_rcnn/1040010018255600" \
20 | --batch_size=16 \
21 | --shard=1 \
22 | --shard_size=2 \
23 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis/1040010018255600" \
24 | --restore_from_json=False
25 |
--------------------------------------------------------------------------------
/object_detection/inference/mask_rcnn_batch/104001002F3A8700.sh:
--------------------------------------------------------------------------------
1 | echo $(date -u) MASK Tile 104001002F3A8700 starting >> tilelog.txt
2 | CUDA_VISIBLE_DEVICES='0' python object_detection/inference/data_infer_batch.py \
3 | --input_path="/media/ssd1/data/104001002F3A8700_jpg.tif_tiles/19/" \
4 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
5 | --output_path="/media/ssd1/tile_output_mask_rcnn/104001002F3A8700" \
6 | --shard_path="/media/ssd1/tile_output_mask_rcnn/104001002F3A8700" \
7 | --batch_size=16 \
8 | --shard=0 \
9 | --shard_size=2 \
10 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis/104001002F3A8700" \
11 | --restore_from_json=False
12 |
13 | CUDA_VISIBLE_DEVICES='3' python object_detection/inference/data_infer_batch.py \
14 | --input_path="/media/ssd1/data/104001002F3A8700_jpg.tif_tiles/19/" \
15 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
16 | --output_path="/media/ssd1/tile_output_mask_rcnn/104001002F3A8700" \
17 | --shard_path="/media/ssd1/tile_output_mask_rcnn/104001002F3A8700" \
18 | --batch_size=16 \
19 | --shard=1 \
20 | --shard_size=2 \
21 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis/104001002F3A8700" \
22 | --restore_from_json=False
23 |
--------------------------------------------------------------------------------
/object_detection/inference/mask_rcnn_batch/10400100305A7E00.sh:
--------------------------------------------------------------------------------
1 | echo $(date -u) MASK Tile 10400100305A7E00 starting >> tilelog.txt
2 | CUDA_VISIBLE_DEVICES='0' python object_detection/inference/data_infer_batch.py \
3 | --input_path="/media/ssd1/data/10400100305A7E00_jpg.tif_tiles/19/" \
4 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
5 | --output_path="/media/ssd1/tile_output_mask_rcnn/10400100305A7E00" \
6 | --shard_path="/media/ssd1/tile_output_mask_rcnn/10400100305A7E00" \
7 | --batch_size=16 \
8 | --shard=0 \
9 | --shard_size=2 \
10 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis/10400100305A7E00"&
11 |
12 | CUDA_VISIBLE_DEVICES='3' python object_detection/inference/data_infer_batch.py \
13 | --input_path="/media/ssd1/data/10400100305A7E00_jpg.tif_tiles/19/" \
14 | --inference_graph="/media/ssd1/sat_data_models/mask_rcnn/large/export_batch_low_proposals/frozen_inference_graph.pb" \
15 | --output_path="/media/ssd1/tile_output_mask_rcnn/10400100305A7E00" \
16 | --shard_path="/media/ssd1/tile_output_mask_rcnn/10400100305A7E00" \
17 | --batch_size=16 \
18 | --shard=1 \
19 | --shard_size=2 \
20 | --vis_path="/media/ssd1/tile_output_mask_rcnn/vis/10400100305A7E00" \
21 | --restore_from_json=False
22 |
23 | echo $(date -u) Finished!!!
24 |
--------------------------------------------------------------------------------
/object_detection/inference/mask_rcnn_batch/run.sh:
--------------------------------------------------------------------------------
1 | bash object_detection/inference/mask_rcnn_batch/1040010010608200.sh
2 | bash object_detection/inference/mask_rcnn_batch/104001000FB77500.sh
3 |
--------------------------------------------------------------------------------
/object_detection/inference/queue-runners.py:
--------------------------------------------------------------------------------
1 | """ Example to demonstrate how to use queues
2 | Author: Chip Huyen
3 | Prepared for the class CS 20SI: "TensorFlow for Deep Learning Research"
4 | cs20si.stanford.edu
5 | """
6 | import os
7 | os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
8 |
9 | import numpy as np
10 | import tensorflow as tf
11 |
12 | N_SAMPLES = int(1e4)
13 | NUM_THREADS = 4
14 | # Generating some simple data
15 | # create 1000 random samples, each is a 1D array from the normal distribution (10, 1)
16 | data = 10 * np.random.randn(N_SAMPLES, 4) + 1
17 | # create 1000 random labels of 0 and 1
18 | target = np.random.randint(0, 2, size=N_SAMPLES)
19 |
20 | queue = tf.FIFOQueue(capacity=50, dtypes=[tf.float32, tf.int32], shapes=[[4], []])
21 |
22 | enqueue_op = queue.enqueue_many([data, target])
23 | data_sample, label_sample = queue.dequeue()
24 |
25 | # create ops that do something with data_sample and label_sample
26 |
27 | # create NUM_THREADS to do enqueue
28 | qr = tf.train.QueueRunner(queue, [enqueue_op] * NUM_THREADS)
29 | with tf.Session() as sess:
30 | # create a coordinator, launch the queue runner threads.
31 | coord = tf.train.Coordinator()
32 | enqueue_threads = qr.create_threads(sess, coord=coord, start=True)
33 | try:
34 | for step in range(100): # do to 100 iterations
35 | if coord.should_stop():
36 | break
37 | data_batch, label_batch = sess.run([data_sample, label_sample])
38 | print(data_batch)
39 | print(label_batch)
40 | except Exception as e:
41 | coord.request_stop(e)
42 | finally:
43 | coord.request_stop()
44 | coord.join(enqueue_threads)
45 |
--------------------------------------------------------------------------------
/object_detection/inference/run.sh:
--------------------------------------------------------------------------------
1 | bash object_detection/inference/mask_rcnn_batch/run.sh
2 | bash object_detection/inference/faster_rcnn_batch/run.sh
--------------------------------------------------------------------------------
/object_detection/inference/run_data_infer_batch_test.sh:
--------------------------------------------------------------------------------
1 | CUDA_VISIBLE_DEVICES='0' \python object_detection/inference/data_infer_batch_test.py \
2 | --input_path="/media/ssd1/data/1040010018255600_jpg.tif_tiles/19/" \
3 | --inference_graph="/media/ssd1/sat_data_models/faster_rcnn/large/export/frozen_inference_graph.pb" \
4 | --output_path="" \
5 | --shard_path="" \
6 | --batch_size=1 \
7 | --test_size=30 \
8 | --shard=0 \
9 | --vis_path="output_xxx" &
10 |
11 | CUDA_VISIBLE_DEVICES='1' python object_detection/inference/data_infer_batch_test.py \
12 | --input_path="/media/ssd1/data/1040010018255600_jpg.tif_tiles/19/" \
13 | --inference_graph="/media/ssd1/sat_data_models/faster_rcnn/large/export/frozen_inference_graph.pb" \
14 | --output_path="" \
15 | --shard_path="" \
16 | --batch_size=1 \
17 | --test_size=30 \
18 | --shard=1 \
19 | --vis_path="output_xxx" &
20 |
21 | CUDA_VISIBLE_DEVICES='2' python object_detection/inference/data_infer_batch_test.py \
22 | --input_path="/media/ssd1/data/1040010018255600_jpg.tif_tiles/19/" \
23 | --inference_graph="/media/ssd1/sat_data_models/faster_rcnn/large/export/frozen_inference_graph.pb" \
24 | --output_path="" \
25 | --shard_path="" \
26 | --batch_size=1 \
27 | --test_size=30 \
28 | --shard=2 \
29 | --vis_path="output_xxx"
30 |
--------------------------------------------------------------------------------
/object_detection/matchers/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/matchers/__init__.py
--------------------------------------------------------------------------------
/object_detection/matchers/bipartite_matcher.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Bipartite matcher implementation."""
17 |
18 | import tensorflow as tf
19 |
20 | from tensorflow.contrib.image.python.ops import image_ops
21 | from object_detection.core import matcher
22 |
23 |
24 | class GreedyBipartiteMatcher(matcher.Matcher):
25 | """Wraps a Tensorflow greedy bipartite matcher."""
26 |
27 | def __init__(self, use_matmul_gather=False):
28 | """Constructs a Matcher.
29 |
30 | Args:
31 | use_matmul_gather: Force constructed match objects to use matrix
32 | multiplication based gather instead of standard tf.gather.
33 | (Default: False).
34 | """
35 | super(GreedyBipartiteMatcher, self).__init__(
36 | use_matmul_gather=use_matmul_gather)
37 |
38 | def _match(self, similarity_matrix, num_valid_rows=-1):
39 | """Bipartite matches a collection rows and columns. A greedy bi-partite.
40 |
41 | TODO(rathodv): Add num_valid_columns options to match only that many columns
42 | with all the rows.
43 |
44 | Args:
45 | similarity_matrix: Float tensor of shape [N, M] with pairwise similarity
46 | where higher values mean more similar.
47 | num_valid_rows: A scalar or a 1-D tensor with one element describing the
48 | number of valid rows of similarity_matrix to consider for the bipartite
49 | matching. If set to be negative, then all rows from similarity_matrix
50 | are used.
51 |
52 | Returns:
53 | match_results: int32 tensor of shape [M] with match_results[i]=-1
54 | meaning that column i is not matched and otherwise that it is matched to
55 | row match_results[i].
56 | """
57 | # Convert similarity matrix to distance matrix as tf.image.bipartite tries
58 | # to find minimum distance matches.
59 | distance_matrix = -1 * similarity_matrix
60 | _, match_results = image_ops.bipartite_match(
61 | distance_matrix, num_valid_rows)
62 | match_results = tf.reshape(match_results, [-1])
63 | match_results = tf.cast(match_results, tf.int32)
64 | return match_results
65 |
--------------------------------------------------------------------------------
/object_detection/meta_architectures/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/meta_architectures/__init__.py
--------------------------------------------------------------------------------
/object_detection/meta_architectures/rfcn_meta_arch_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.meta_architectures.rfcn_meta_arch."""
17 |
18 | import tensorflow as tf
19 |
20 | from object_detection.meta_architectures import faster_rcnn_meta_arch_test_lib
21 | from object_detection.meta_architectures import rfcn_meta_arch
22 |
23 |
24 | class RFCNMetaArchTest(
25 | faster_rcnn_meta_arch_test_lib.FasterRCNNMetaArchTestBase):
26 |
27 | def _get_second_stage_box_predictor_text_proto(self):
28 | box_predictor_text_proto = """
29 | rfcn_box_predictor {
30 | conv_hyperparams {
31 | op: CONV
32 | activation: NONE
33 | regularizer {
34 | l2_regularizer {
35 | weight: 0.0005
36 | }
37 | }
38 | initializer {
39 | variance_scaling_initializer {
40 | factor: 1.0
41 | uniform: true
42 | mode: FAN_AVG
43 | }
44 | }
45 | }
46 | }
47 | """
48 | return box_predictor_text_proto
49 |
50 | def _get_model(self, box_predictor, **common_kwargs):
51 | return rfcn_meta_arch.RFCNMetaArch(
52 | second_stage_rfcn_box_predictor=box_predictor, **common_kwargs)
53 |
54 | def _get_box_classifier_features_shape(self,
55 | image_size,
56 | batch_size,
57 | max_num_proposals,
58 | initial_crop_size,
59 | maxpool_stride,
60 | num_features):
61 | return (batch_size, image_size, image_size, num_features)
62 |
63 |
64 | if __name__ == '__main__':
65 | tf.test.main()
66 |
--------------------------------------------------------------------------------
/object_detection/metrics/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/metrics/__init__.py
--------------------------------------------------------------------------------
/object_detection/metrics/offline_eval_map_corloc_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Tests for utilities in offline_eval_map_corloc binary."""
16 |
17 | import tensorflow as tf
18 |
19 | from object_detection.metrics import offline_eval_map_corloc as offline_eval
20 |
21 |
22 | class OfflineEvalMapCorlocTest(tf.test.TestCase):
23 |
24 | def test_generateShardedFilenames(self):
25 | test_filename = '/path/to/file'
26 | result = offline_eval._generate_sharded_filenames(test_filename)
27 | self.assertEqual(result, [test_filename])
28 |
29 | test_filename = '/path/to/file-00000-of-00050'
30 | result = offline_eval._generate_sharded_filenames(test_filename)
31 | self.assertEqual(result, [test_filename])
32 |
33 | result = offline_eval._generate_sharded_filenames('/path/to/@3.record')
34 | self.assertEqual(result, [
35 | '/path/to/-00000-of-00003.record', '/path/to/-00001-of-00003.record',
36 | '/path/to/-00002-of-00003.record'
37 | ])
38 |
39 | result = offline_eval._generate_sharded_filenames('/path/to/abc@3')
40 | self.assertEqual(result, [
41 | '/path/to/abc-00000-of-00003', '/path/to/abc-00001-of-00003',
42 | '/path/to/abc-00002-of-00003'
43 | ])
44 |
45 | result = offline_eval._generate_sharded_filenames('/path/to/@1')
46 | self.assertEqual(result, ['/path/to/-00000-of-00001'])
47 |
48 | def test_generateFilenames(self):
49 | test_filenames = ['/path/to/file', '/path/to/@3.record']
50 | result = offline_eval._generate_filenames(test_filenames)
51 | self.assertEqual(result, [
52 | '/path/to/file', '/path/to/-00000-of-00003.record',
53 | '/path/to/-00001-of-00003.record', '/path/to/-00002-of-00003.record'
54 | ])
55 |
56 |
57 | if __name__ == '__main__':
58 | tf.test.main()
59 |
--------------------------------------------------------------------------------
/object_detection/model_hparams.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Hyperparameters for the object detection model in TF.learn.
16 |
17 | This file consolidates and documents the hyperparameters used by the model.
18 | """
19 |
20 | from __future__ import absolute_import
21 | from __future__ import division
22 | from __future__ import print_function
23 |
24 | import tensorflow as tf
25 |
26 |
27 | def create_hparams(hparams_overrides=None):
28 | """Returns hyperparameters, including any flag value overrides.
29 |
30 | Args:
31 | hparams_overrides: Optional hparams overrides, represented as a
32 | string containing comma-separated hparam_name=value pairs.
33 |
34 | Returns:
35 | The hyperparameters as a tf.HParams object.
36 | """
37 | hparams = tf.contrib.training.HParams(
38 | # Whether a fine tuning checkpoint (provided in the pipeline config)
39 | # should be loaded for training.
40 | load_pretrained=True)
41 | # Override any of the preceding hyperparameter values.
42 | if hparams_overrides:
43 | hparams = hparams.parse(hparams_overrides)
44 | return hparams
45 |
--------------------------------------------------------------------------------
/object_detection/models/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/models/__init__.py
--------------------------------------------------------------------------------
/object_detection/protos/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/protos/__init__.py
--------------------------------------------------------------------------------
/object_detection/protos/anchor_generator.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | import "object_detection/protos/grid_anchor_generator.proto";
6 | import "object_detection/protos/ssd_anchor_generator.proto";
7 | import "object_detection/protos/multiscale_anchor_generator.proto";
8 |
9 | // Configuration proto for the anchor generator to use in the object detection
10 | // pipeline. See core/anchor_generator.py for details.
11 | message AnchorGenerator {
12 | oneof anchor_generator_oneof {
13 | GridAnchorGenerator grid_anchor_generator = 1;
14 | SsdAnchorGenerator ssd_anchor_generator = 2;
15 | MultiscaleAnchorGenerator multiscale_anchor_generator = 3;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/object_detection/protos/argmax_matcher.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for ArgMaxMatcher. See
6 | // matchers/argmax_matcher.py for details.
7 | message ArgMaxMatcher {
8 | // Threshold for positive matches.
9 | optional float matched_threshold = 1 [default = 0.5];
10 |
11 | // Threshold for negative matches.
12 | optional float unmatched_threshold = 2 [default = 0.5];
13 |
14 | // Whether to construct ArgMaxMatcher without thresholds.
15 | optional bool ignore_thresholds = 3 [default = false];
16 |
17 | // If True then negative matches are the ones below the unmatched_threshold,
18 | // whereas ignored matches are in between the matched and umatched
19 | // threshold. If False, then negative matches are in between the matched
20 | // and unmatched threshold, and everything lower than unmatched is ignored.
21 | optional bool negatives_lower_than_unmatched = 4 [default = true];
22 |
23 | // Whether to ensure each row is matched to at least one column.
24 | optional bool force_match_for_each_row = 5 [default = false];
25 |
26 | // Force constructed match objects to use matrix multiplication based gather
27 | // instead of standard tf.gather
28 | optional bool use_matmul_gather = 6 [default = false];
29 | }
30 |
--------------------------------------------------------------------------------
/object_detection/protos/bipartite_matcher.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for bipartite matcher. See
6 | // matchers/bipartite_matcher.py for details.
7 | message BipartiteMatcher {
8 | // Force constructed match objects to use matrix multiplication based gather
9 | // instead of standard tf.gather
10 | optional bool use_matmul_gather = 6 [default = false];
11 | }
12 |
--------------------------------------------------------------------------------
/object_detection/protos/bipartite_matcher_pb2.py:
--------------------------------------------------------------------------------
1 | # Generated by the protocol buffer compiler. DO NOT EDIT!
2 | # source: object_detection/protos/bipartite_matcher.proto
3 |
4 | import sys
5 | _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
6 | from google.protobuf import descriptor as _descriptor
7 | from google.protobuf import message as _message
8 | from google.protobuf import reflection as _reflection
9 | from google.protobuf import symbol_database as _symbol_database
10 | from google.protobuf import descriptor_pb2
11 | # @@protoc_insertion_point(imports)
12 |
13 | _sym_db = _symbol_database.Default()
14 |
15 |
16 |
17 |
18 | DESCRIPTOR = _descriptor.FileDescriptor(
19 | name='object_detection/protos/bipartite_matcher.proto',
20 | package='object_detection.protos',
21 | syntax='proto2',
22 | serialized_pb=_b('\n/object_detection/protos/bipartite_matcher.proto\x12\x17object_detection.protos\"4\n\x10\x42ipartiteMatcher\x12 \n\x11use_matmul_gather\x18\x06 \x01(\x08:\x05\x66\x61lse')
23 | )
24 |
25 |
26 |
27 |
28 | _BIPARTITEMATCHER = _descriptor.Descriptor(
29 | name='BipartiteMatcher',
30 | full_name='object_detection.protos.BipartiteMatcher',
31 | filename=None,
32 | file=DESCRIPTOR,
33 | containing_type=None,
34 | fields=[
35 | _descriptor.FieldDescriptor(
36 | name='use_matmul_gather', full_name='object_detection.protos.BipartiteMatcher.use_matmul_gather', index=0,
37 | number=6, type=8, cpp_type=7, label=1,
38 | has_default_value=True, default_value=False,
39 | message_type=None, enum_type=None, containing_type=None,
40 | is_extension=False, extension_scope=None,
41 | options=None),
42 | ],
43 | extensions=[
44 | ],
45 | nested_types=[],
46 | enum_types=[
47 | ],
48 | options=None,
49 | is_extendable=False,
50 | syntax='proto2',
51 | extension_ranges=[],
52 | oneofs=[
53 | ],
54 | serialized_start=76,
55 | serialized_end=128,
56 | )
57 |
58 | DESCRIPTOR.message_types_by_name['BipartiteMatcher'] = _BIPARTITEMATCHER
59 | _sym_db.RegisterFileDescriptor(DESCRIPTOR)
60 |
61 | BipartiteMatcher = _reflection.GeneratedProtocolMessageType('BipartiteMatcher', (_message.Message,), dict(
62 | DESCRIPTOR = _BIPARTITEMATCHER,
63 | __module__ = 'object_detection.protos.bipartite_matcher_pb2'
64 | # @@protoc_insertion_point(class_scope:object_detection.protos.BipartiteMatcher)
65 | ))
66 | _sym_db.RegisterMessage(BipartiteMatcher)
67 |
68 |
69 | # @@protoc_insertion_point(module_scope)
70 |
--------------------------------------------------------------------------------
/object_detection/protos/box_coder.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | import "object_detection/protos/faster_rcnn_box_coder.proto";
6 | import "object_detection/protos/keypoint_box_coder.proto";
7 | import "object_detection/protos/mean_stddev_box_coder.proto";
8 | import "object_detection/protos/square_box_coder.proto";
9 |
10 | // Configuration proto for the box coder to be used in the object detection
11 | // pipeline. See core/box_coder.py for details.
12 | message BoxCoder {
13 | oneof box_coder_oneof {
14 | FasterRcnnBoxCoder faster_rcnn_box_coder = 1;
15 | MeanStddevBoxCoder mean_stddev_box_coder = 2;
16 | SquareBoxCoder square_box_coder = 3;
17 | KeypointBoxCoder keypoint_box_coder = 4;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/object_detection/protos/faster_rcnn_box_coder.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for FasterRCNNBoxCoder. See
6 | // box_coders/faster_rcnn_box_coder.py for details.
7 | message FasterRcnnBoxCoder {
8 | // Scale factor for anchor encoded box center.
9 | optional float y_scale = 1 [default = 10.0];
10 | optional float x_scale = 2 [default = 10.0];
11 |
12 | // Scale factor for anchor encoded box height.
13 | optional float height_scale = 3 [default = 5.0];
14 |
15 | // Scale factor for anchor encoded box width.
16 | optional float width_scale = 4 [default = 5.0];
17 | }
18 |
--------------------------------------------------------------------------------
/object_detection/protos/graph_rewriter.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Message to configure graph rewriter for the tf graph.
6 | message GraphRewriter {
7 | optional Quantization quantization = 1;
8 | }
9 |
10 | // Message for quantization options. See
11 | // tensorflow/contrib/quantize/python/quantize.py for details.
12 | message Quantization {
13 | // Number of steps to delay before quantization takes effect during training.
14 | optional int32 delay = 1 [default = 500000];
15 |
16 | // Number of bits to use for quantizing weights.
17 | // Only 8 bit is supported for now.
18 | optional int32 weight_bits = 2 [default = 8];
19 |
20 | // Number of bits to use for quantizing activations.
21 | // Only 8 bit is supported for now.
22 | optional int32 activation_bits = 3 [default = 8];
23 | }
24 |
--------------------------------------------------------------------------------
/object_detection/protos/grid_anchor_generator.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for GridAnchorGenerator. See
6 | // anchor_generators/grid_anchor_generator.py for details.
7 | message GridAnchorGenerator {
8 | // Anchor height in pixels.
9 | optional int32 height = 1 [default = 256];
10 |
11 | // Anchor width in pixels.
12 | optional int32 width = 2 [default = 256];
13 |
14 | // Anchor stride in height dimension in pixels.
15 | optional int32 height_stride = 3 [default = 16];
16 |
17 | // Anchor stride in width dimension in pixels.
18 | optional int32 width_stride = 4 [default = 16];
19 |
20 | // Anchor height offset in pixels.
21 | optional int32 height_offset = 5 [default = 0];
22 |
23 | // Anchor width offset in pixels.
24 | optional int32 width_offset = 6 [default = 0];
25 |
26 | // At any given location, len(scales) * len(aspect_ratios) anchors are
27 | // generated with all possible combinations of scales and aspect ratios.
28 |
29 | // List of scales for the anchors.
30 | repeated float scales = 7;
31 |
32 | // List of aspect ratios for the anchors.
33 | repeated float aspect_ratios = 8;
34 | }
35 |
--------------------------------------------------------------------------------
/object_detection/protos/image_resizer.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for image resizing operations.
6 | // See builders/image_resizer_builder.py for details.
7 | message ImageResizer {
8 | oneof image_resizer_oneof {
9 | KeepAspectRatioResizer keep_aspect_ratio_resizer = 1;
10 | FixedShapeResizer fixed_shape_resizer = 2;
11 | }
12 | }
13 |
14 | // Enumeration type for image resizing methods provided in TensorFlow.
15 | enum ResizeType {
16 | BILINEAR = 0; // Corresponds to tf.image.ResizeMethod.BILINEAR
17 | NEAREST_NEIGHBOR = 1; // Corresponds to tf.image.ResizeMethod.NEAREST_NEIGHBOR
18 | BICUBIC = 2; // Corresponds to tf.image.ResizeMethod.BICUBIC
19 | AREA = 3; // Corresponds to tf.image.ResizeMethod.AREA
20 | }
21 |
22 | // Configuration proto for image resizer that keeps aspect ratio.
23 | message KeepAspectRatioResizer {
24 | // Desired size of the smaller image dimension in pixels.
25 | optional int32 min_dimension = 1 [default = 600];
26 |
27 | // Desired size of the larger image dimension in pixels.
28 | optional int32 max_dimension = 2 [default = 1024];
29 |
30 | // Desired method when resizing image.
31 | optional ResizeType resize_method = 3 [default = BILINEAR];
32 |
33 | // Whether to pad the image with zeros so the output spatial size is
34 | // [max_dimension, max_dimension]. Note that the zeros are padded to the
35 | // bottom and the right of the resized image.
36 | optional bool pad_to_max_dimension = 4 [default = false];
37 |
38 | // Whether to also resize the image channels from 3 to 1 (RGB to grayscale).
39 | optional bool convert_to_grayscale = 5 [default = false];
40 | }
41 |
42 | // Configuration proto for image resizer that resizes to a fixed shape.
43 | message FixedShapeResizer {
44 | // Desired height of image in pixels.
45 | optional int32 height = 1 [default = 300];
46 |
47 | // Desired width of image in pixels.
48 | optional int32 width = 2 [default = 300];
49 |
50 | // Desired method when resizing image.
51 | optional ResizeType resize_method = 3 [default = BILINEAR];
52 |
53 | // Whether to also resize the image channels from 3 to 1 (RGB to grayscale).
54 | optional bool convert_to_grayscale = 4 [default = false];
55 | }
56 |
--------------------------------------------------------------------------------
/object_detection/protos/keypoint_box_coder.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for KeypointBoxCoder. See
6 | // box_coders/keypoint_box_coder.py for details.
7 | message KeypointBoxCoder {
8 | optional int32 num_keypoints = 1;
9 |
10 | // Scale factor for anchor encoded box center and keypoints.
11 | optional float y_scale = 2 [default = 10.0];
12 | optional float x_scale = 3 [default = 10.0];
13 |
14 | // Scale factor for anchor encoded box height.
15 | optional float height_scale = 4 [default = 5.0];
16 |
17 | // Scale factor for anchor encoded box width.
18 | optional float width_scale = 5 [default = 5.0];
19 | }
20 |
--------------------------------------------------------------------------------
/object_detection/protos/matcher.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | import "object_detection/protos/argmax_matcher.proto";
6 | import "object_detection/protos/bipartite_matcher.proto";
7 |
8 | // Configuration proto for the matcher to be used in the object detection
9 | // pipeline. See core/matcher.py for details.
10 | message Matcher {
11 | oneof matcher_oneof {
12 | ArgMaxMatcher argmax_matcher = 1;
13 | BipartiteMatcher bipartite_matcher = 2;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/object_detection/protos/mean_stddev_box_coder.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for MeanStddevBoxCoder. See
6 | // box_coders/mean_stddev_box_coder.py for details.
7 | message MeanStddevBoxCoder {
8 | // The standard deviation used to encode and decode boxes.
9 | optional float stddev = 1 [default=0.01];
10 | }
11 |
--------------------------------------------------------------------------------
/object_detection/protos/mean_stddev_box_coder_pb2.py:
--------------------------------------------------------------------------------
1 | # Generated by the protocol buffer compiler. DO NOT EDIT!
2 | # source: object_detection/protos/mean_stddev_box_coder.proto
3 |
4 | import sys
5 | _b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
6 | from google.protobuf import descriptor as _descriptor
7 | from google.protobuf import message as _message
8 | from google.protobuf import reflection as _reflection
9 | from google.protobuf import symbol_database as _symbol_database
10 | from google.protobuf import descriptor_pb2
11 | # @@protoc_insertion_point(imports)
12 |
13 | _sym_db = _symbol_database.Default()
14 |
15 |
16 |
17 |
18 | DESCRIPTOR = _descriptor.FileDescriptor(
19 | name='object_detection/protos/mean_stddev_box_coder.proto',
20 | package='object_detection.protos',
21 | syntax='proto2',
22 | serialized_pb=_b('\n3object_detection/protos/mean_stddev_box_coder.proto\x12\x17object_detection.protos\"*\n\x12MeanStddevBoxCoder\x12\x14\n\x06stddev\x18\x01 \x01(\x02:\x04\x30.01')
23 | )
24 |
25 |
26 |
27 |
28 | _MEANSTDDEVBOXCODER = _descriptor.Descriptor(
29 | name='MeanStddevBoxCoder',
30 | full_name='object_detection.protos.MeanStddevBoxCoder',
31 | filename=None,
32 | file=DESCRIPTOR,
33 | containing_type=None,
34 | fields=[
35 | _descriptor.FieldDescriptor(
36 | name='stddev', full_name='object_detection.protos.MeanStddevBoxCoder.stddev', index=0,
37 | number=1, type=2, cpp_type=6, label=1,
38 | has_default_value=True, default_value=float(0.01),
39 | message_type=None, enum_type=None, containing_type=None,
40 | is_extension=False, extension_scope=None,
41 | options=None),
42 | ],
43 | extensions=[
44 | ],
45 | nested_types=[],
46 | enum_types=[
47 | ],
48 | options=None,
49 | is_extendable=False,
50 | syntax='proto2',
51 | extension_ranges=[],
52 | oneofs=[
53 | ],
54 | serialized_start=80,
55 | serialized_end=122,
56 | )
57 |
58 | DESCRIPTOR.message_types_by_name['MeanStddevBoxCoder'] = _MEANSTDDEVBOXCODER
59 | _sym_db.RegisterFileDescriptor(DESCRIPTOR)
60 |
61 | MeanStddevBoxCoder = _reflection.GeneratedProtocolMessageType('MeanStddevBoxCoder', (_message.Message,), dict(
62 | DESCRIPTOR = _MEANSTDDEVBOXCODER,
63 | __module__ = 'object_detection.protos.mean_stddev_box_coder_pb2'
64 | # @@protoc_insertion_point(class_scope:object_detection.protos.MeanStddevBoxCoder)
65 | ))
66 | _sym_db.RegisterMessage(MeanStddevBoxCoder)
67 |
68 |
69 | # @@protoc_insertion_point(module_scope)
70 |
--------------------------------------------------------------------------------
/object_detection/protos/model.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | import "object_detection/protos/faster_rcnn.proto";
6 | import "object_detection/protos/ssd.proto";
7 |
8 | // Top level configuration for DetectionModels.
9 | message DetectionModel {
10 | oneof model {
11 | FasterRcnn faster_rcnn = 1;
12 | Ssd ssd = 2;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/object_detection/protos/multiscale_anchor_generator.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for RetinaNet anchor generator described in
6 | // https://arxiv.org/abs/1708.02002. See
7 | // anchor_generators/multiscale_grid_anchor_generator.py for details.
8 | message MultiscaleAnchorGenerator {
9 | // minimum level in feature pyramid
10 | optional int32 min_level = 1 [default = 3];
11 |
12 | // maximum level in feature pyramid
13 | optional int32 max_level = 2 [default = 7];
14 |
15 | // Scale of anchor to feature stride
16 | optional float anchor_scale = 3 [default = 4.0];
17 |
18 | // Aspect ratios for anchors at each grid point.
19 | repeated float aspect_ratios = 4;
20 |
21 | // Number of intermediate scale each scale octave
22 | optional int32 scales_per_octave = 5 [default = 2];
23 |
24 | // Whether to produce anchors in normalized coordinates.
25 | optional bool normalize_coordinates = 6 [default = true];
26 | }
27 |
--------------------------------------------------------------------------------
/object_detection/protos/pipeline.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | import "object_detection/protos/eval.proto";
6 | import "object_detection/protos/graph_rewriter.proto";
7 | import "object_detection/protos/input_reader.proto";
8 | import "object_detection/protos/model.proto";
9 | import "object_detection/protos/train.proto";
10 |
11 | // Convenience message for configuring a training and eval pipeline. Allows all
12 | // of the pipeline parameters to be configured from one file.
13 | message TrainEvalPipelineConfig {
14 | optional DetectionModel model = 1;
15 | optional TrainConfig train_config = 2;
16 | optional InputReader train_input_reader = 3;
17 | optional EvalConfig eval_config = 4;
18 | optional InputReader eval_input_reader = 5;
19 | optional GraphRewriter graph_rewriter = 6;
20 | extensions 1000 to max;
21 | }
22 |
--------------------------------------------------------------------------------
/object_detection/protos/post_processing.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for non-max-suppression operation on a batch of
6 | // detections.
7 | message BatchNonMaxSuppression {
8 | // Scalar threshold for score (low scoring boxes are removed).
9 | optional float score_threshold = 1 [default = 0.0];
10 |
11 | // Scalar threshold for IOU (boxes that have high IOU overlap
12 | // with previously selected boxes are removed).
13 | optional float iou_threshold = 2 [default = 0.6];
14 |
15 | // Maximum number of detections to retain per class.
16 | optional int32 max_detections_per_class = 3 [default = 100];
17 |
18 | // Maximum number of detections to retain across all classes.
19 | optional int32 max_total_detections = 5 [default = 100];
20 | }
21 |
22 | // Configuration proto for post-processing predicted boxes and
23 | // scores.
24 | message PostProcessing {
25 | // Non max suppression parameters.
26 | optional BatchNonMaxSuppression batch_non_max_suppression = 1;
27 |
28 | // Enum to specify how to convert the detection scores.
29 | enum ScoreConverter {
30 | // Input scores equals output scores.
31 | IDENTITY = 0;
32 |
33 | // Applies a sigmoid on input scores.
34 | SIGMOID = 1;
35 |
36 | // Applies a softmax on input scores
37 | SOFTMAX = 2;
38 | }
39 |
40 | // Score converter to use.
41 | optional ScoreConverter score_converter = 2 [default = IDENTITY];
42 | // Scale logit (input) value before conversion in post-processing step.
43 | // Typically used for softmax distillation, though can be used to scale for
44 | // other reasons.
45 | optional float logit_scale = 3 [default = 1.0];
46 | }
47 |
--------------------------------------------------------------------------------
/object_detection/protos/region_similarity_calculator.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for region similarity calculators. See
6 | // core/region_similarity_calculator.py for details.
7 | message RegionSimilarityCalculator {
8 | oneof region_similarity {
9 | NegSqDistSimilarity neg_sq_dist_similarity = 1;
10 | IouSimilarity iou_similarity = 2;
11 | IoaSimilarity ioa_similarity = 3;
12 | }
13 | }
14 |
15 | // Configuration for negative squared distance similarity calculator.
16 | message NegSqDistSimilarity {
17 | }
18 |
19 | // Configuration for intersection-over-union (IOU) similarity calculator.
20 | message IouSimilarity {
21 | }
22 |
23 | // Configuration for intersection-over-area (IOA) similarity calculator.
24 | message IoaSimilarity {
25 | }
26 |
--------------------------------------------------------------------------------
/object_detection/protos/square_box_coder.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for SquareBoxCoder. See
6 | // box_coders/square_box_coder.py for details.
7 | message SquareBoxCoder {
8 | // Scale factor for anchor encoded box center.
9 | optional float y_scale = 1 [default = 10.0];
10 | optional float x_scale = 2 [default = 10.0];
11 |
12 | // Scale factor for anchor encoded box length.
13 | optional float length_scale = 3 [default = 5.0];
14 | }
15 |
--------------------------------------------------------------------------------
/object_detection/protos/ssd_anchor_generator.proto:
--------------------------------------------------------------------------------
1 | syntax = "proto2";
2 |
3 | package object_detection.protos;
4 |
5 | // Configuration proto for SSD anchor generator described in
6 | // https://arxiv.org/abs/1512.02325. See
7 | // anchor_generators/multiple_grid_anchor_generator.py for details.
8 | message SsdAnchorGenerator {
9 | // Number of grid layers to create anchors for.
10 | optional int32 num_layers = 1 [default = 6];
11 |
12 | // Scale of anchors corresponding to finest resolution.
13 | optional float min_scale = 2 [default = 0.2];
14 |
15 | // Scale of anchors corresponding to coarsest resolution
16 | optional float max_scale = 3 [default = 0.95];
17 |
18 | // Can be used to override min_scale->max_scale, with an explicitly defined
19 | // set of scales. If empty, then min_scale->max_scale is used.
20 | repeated float scales = 12;
21 |
22 | // Aspect ratios for anchors at each grid point.
23 | repeated float aspect_ratios = 4;
24 |
25 | // When this aspect ratio is greater than 0, then an additional
26 | // anchor, with an interpolated scale is added with this aspect ratio.
27 | optional float interpolated_scale_aspect_ratio = 13 [default = 1.0];
28 |
29 | // Whether to use the following aspect ratio and scale combination for the
30 | // layer with the finest resolution : (scale=0.1, aspect_ratio=1.0),
31 | // (scale=min_scale, aspect_ration=2.0), (scale=min_scale, aspect_ratio=0.5).
32 | optional bool reduce_boxes_in_lowest_layer = 5 [default = true];
33 |
34 | // The base anchor size in height dimension.
35 | optional float base_anchor_height = 6 [default = 1.0];
36 |
37 | // The base anchor size in width dimension.
38 | optional float base_anchor_width = 7 [default = 1.0];
39 |
40 | // Anchor stride in height dimension in pixels for each layer. The length of
41 | // this field is expected to be equal to the value of num_layers.
42 | repeated int32 height_stride = 8;
43 |
44 | // Anchor stride in width dimension in pixels for each layer. The length of
45 | // this field is expected to be equal to the value of num_layers.
46 | repeated int32 width_stride = 9;
47 |
48 | // Anchor height offset in pixels for each layer. The length of this field is
49 | // expected to be equal to the value of num_layers.
50 | repeated int32 height_offset = 10;
51 |
52 | // Anchor width offset in pixels for each layer. The length of this field is
53 | // expected to be equal to the value of num_layers.
54 | repeated int32 width_offset = 11;
55 | }
56 |
--------------------------------------------------------------------------------
/object_detection/protos/string_int_label_map.proto:
--------------------------------------------------------------------------------
1 | // Message to store the mapping from class label strings to class id. Datasets
2 | // use string labels to represent classes while the object detection framework
3 | // works with class ids. This message maps them so they can be converted back
4 | // and forth as needed.
5 | syntax = "proto2";
6 |
7 | package object_detection.protos;
8 |
9 | message StringIntLabelMapItem {
10 | // String name. The most common practice is to set this to a MID or synsets
11 | // id.
12 | optional string name = 1;
13 |
14 | // Integer id that maps to the string name above. Label ids should start from
15 | // 1.
16 | optional int32 id = 2;
17 |
18 | // Human readable string label.
19 | optional string display_name = 3;
20 | };
21 |
22 | message StringIntLabelMap {
23 | repeated StringIntLabelMapItem item = 1;
24 | };
25 |
--------------------------------------------------------------------------------
/object_detection/samples/cloud/cloud.yml:
--------------------------------------------------------------------------------
1 | trainingInput:
2 | runtimeVersion: "1.0"
3 | scaleTier: CUSTOM
4 | masterType: standard_gpu
5 | workerCount: 5
6 | workerType: standard_gpu
7 | parameterServerCount: 3
8 | parameterServerType: standard
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/object_detection/test_images/get_images.sh:
--------------------------------------------------------------------------------
1 | # image1.jpg: https://commons.wikimedia.org/wiki/File:Baegle_dwa.jpg
2 | wget -O object_detection/test_images/image1.jpg https://commons.wikimedia.org/wiki/File:Baegle_dwa.jpg
3 |
4 | #image2.jpg: Michael Miley,
5 | # https://www.flickr.com/photos/mike_miley/4678754542/in/photolist-88rQHL-88oBVp-88oC2B-88rS6J-88rSqm-88oBLv-88oBC4
6 |
7 | wget -O object_detection/test_images/image2.jpg https://www.flickr.com/photos/mike_miley/4678754542/in/photolist-88rQHL-88oBVp-88oC2B-88rS6J-88rSqm-88oBLv-88oBC4
8 |
--------------------------------------------------------------------------------
/object_detection/test_images/image_info.txt:
--------------------------------------------------------------------------------
1 |
2 | Image provenance:
3 | image1.jpg: https://commons.wikimedia.org/wiki/File:Baegle_dwa.jpg
4 | image2.jpg: Michael Miley,
5 | https://www.flickr.com/photos/mike_miley/4678754542/in/photolist-88rQHL-88oBVp-88oC2B-88rS6J-88rSqm-88oBLv-88oBC4
6 |
7 |
--------------------------------------------------------------------------------
/object_detection/utils/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/object_detection/utils/__init__.py
--------------------------------------------------------------------------------
/object_detection/utils/category_util.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Functions for importing/exporting Object Detection categories."""
17 | import csv
18 |
19 | import tensorflow as tf
20 |
21 |
22 | def load_categories_from_csv_file(csv_path):
23 | """Loads categories from a csv file.
24 |
25 | The CSV file should have one comma delimited numeric category id and string
26 | category name pair per line. For example:
27 |
28 | 0,"cat"
29 | 1,"dog"
30 | 2,"bird"
31 | ...
32 |
33 | Args:
34 | csv_path: Path to the csv file to be parsed into categories.
35 | Returns:
36 | categories: A list of dictionaries representing all possible categories.
37 | The categories will contain an integer 'id' field and a string
38 | 'name' field.
39 | Raises:
40 | ValueError: If the csv file is incorrectly formatted.
41 | """
42 | categories = []
43 |
44 | with tf.gfile.Open(csv_path, 'r') as csvfile:
45 | reader = csv.reader(csvfile, delimiter=',', quotechar='"')
46 | for row in reader:
47 | if not row:
48 | continue
49 |
50 | if len(row) != 2:
51 | raise ValueError('Expected 2 fields per row in csv: %s' % ','.join(row))
52 |
53 | category_id = int(row[0])
54 | category_name = row[1]
55 | categories.append({'id': category_id, 'name': category_name})
56 |
57 | return categories
58 |
59 |
60 | def save_categories_to_csv_file(categories, csv_path):
61 | """Saves categories to a csv file.
62 |
63 | Args:
64 | categories: A list of dictionaries representing categories to save to file.
65 | Each category must contain an 'id' and 'name' field.
66 | csv_path: Path to the csv file to be parsed into categories.
67 | """
68 | categories.sort(key=lambda x: x['id'])
69 | with tf.gfile.Open(csv_path, 'w') as csvfile:
70 | writer = csv.writer(csvfile, delimiter=',', quotechar='"')
71 | for category in categories:
72 | writer.writerow([category['id'], category['name']])
73 |
--------------------------------------------------------------------------------
/object_detection/utils/category_util_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.utils.category_util."""
17 | import os
18 |
19 | import tensorflow as tf
20 |
21 | from object_detection.utils import category_util
22 |
23 |
24 | class EvalUtilTest(tf.test.TestCase):
25 |
26 | def test_load_categories_from_csv_file(self):
27 | csv_data = """
28 | 0,"cat"
29 | 1,"dog"
30 | 2,"bird"
31 | """.strip(' ')
32 | csv_path = os.path.join(self.get_temp_dir(), 'test.csv')
33 | with tf.gfile.Open(csv_path, 'wb') as f:
34 | f.write(csv_data)
35 |
36 | categories = category_util.load_categories_from_csv_file(csv_path)
37 | self.assertTrue({'id': 0, 'name': 'cat'} in categories)
38 | self.assertTrue({'id': 1, 'name': 'dog'} in categories)
39 | self.assertTrue({'id': 2, 'name': 'bird'} in categories)
40 |
41 | def test_save_categories_to_csv_file(self):
42 | categories = [
43 | {'id': 0, 'name': 'cat'},
44 | {'id': 1, 'name': 'dog'},
45 | {'id': 2, 'name': 'bird'},
46 | ]
47 | csv_path = os.path.join(self.get_temp_dir(), 'test.csv')
48 | category_util.save_categories_to_csv_file(categories, csv_path)
49 | saved_categories = category_util.load_categories_from_csv_file(csv_path)
50 | self.assertEqual(saved_categories, categories)
51 |
52 |
53 | if __name__ == '__main__':
54 | tf.test.main()
55 |
--------------------------------------------------------------------------------
/object_detection/utils/context_manager.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Python context management helper."""
16 |
17 | from __future__ import absolute_import
18 | from __future__ import division
19 | from __future__ import print_function
20 |
21 |
22 | class IdentityContextManager(object):
23 | """Returns an identity context manager that does nothing.
24 |
25 | This is helpful in setting up conditional `with` statement as below:
26 |
27 | with slim.arg_scope(x) if use_slim_scope else IdentityContextManager():
28 | do_stuff()
29 |
30 | """
31 |
32 | def __enter__(self):
33 | return None
34 |
35 | def __exit__(self, exec_type, exec_value, traceback):
36 | del exec_type
37 | del exec_value
38 | del traceback
39 | return False
40 |
41 |
--------------------------------------------------------------------------------
/object_detection/utils/context_manager_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Tests for tensorflow_models.object_detection.utils.context_manager."""
16 |
17 | from __future__ import absolute_import
18 | from __future__ import division
19 | from __future__ import print_function
20 |
21 | import tensorflow as tf
22 | from object_detection.utils import context_manager
23 |
24 |
25 | class ContextManagerTest(tf.test.TestCase):
26 |
27 | def test_identity_context_manager(self):
28 | with context_manager.IdentityContextManager() as identity_context:
29 | self.assertIsNone(identity_context)
30 |
31 |
32 | if __name__ == '__main__':
33 | tf.test.main()
34 |
--------------------------------------------------------------------------------
/object_detection/utils/examine_graph.py:
--------------------------------------------------------------------------------
1 | '''
2 | Examine a given .pb file.
3 |
4 | Syntax:
5 |
6 | python object_detection/utils/examine_graph.py
7 | --ckpt_path=/path/to/pb
8 | '''
9 |
10 | import tensorflow as tf
11 |
12 | flags = tf.app.flags
13 | tf.logging.set_verbosity(tf.logging.INFO)
14 |
15 | flags.DEFINE_string('ckpt_path', None,
16 | 'Path to a ckpt saved model.')
17 |
18 | tf.app.flags.mark_flag_as_required('ckpt_path')
19 |
20 | FLAGS = flags.FLAGS
21 |
22 | from tensorflow.python.tools.inspect_checkpoint import print_tensors_in_checkpoint_file
23 |
24 | print_tensors_in_checkpoint_file(file_name=FLAGS.ckpt_path, tensor_name='', all_tensors=False, all_tensor_names=False)
25 |
--------------------------------------------------------------------------------
/object_detection/utils/export_faster_rcnn_incpetion_v2_atrous.sh:
--------------------------------------------------------------------------------
1 |
2 | # From tensorflow/models/research/
3 | pbPATH="object_detection/faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28"
4 |
5 |
6 | EXPORT_DIR="object_detection/faster_rcnn_inception_resnet_v2_atrous_oid_2018_01_28_tf_14"
7 | mkdir EXPORT_DIR
8 |
9 | echo which python
10 | python object_detection/export_inference_graph.py \
11 | --input_type image_tensor \
12 | --pipeline_config_path ${pbPATH}/pipeline.config \
13 | --trained_checkpoint_prefix ${pbPATH}/model.ckpt \
14 | --output_directory ${EXPORT_DIR}
15 |
--------------------------------------------------------------------------------
/object_detection/utils/np_box_mask_list.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Numpy BoxMaskList classes and functions."""
17 |
18 | import numpy as np
19 | from object_detection.utils import np_box_list
20 |
21 |
22 | class BoxMaskList(np_box_list.BoxList):
23 | """Convenience wrapper for BoxList with masks.
24 |
25 | BoxMaskList extends the np_box_list.BoxList to contain masks as well.
26 | In particular, its constructor receives both boxes and masks. Note that the
27 | masks correspond to the full image.
28 | """
29 |
30 | def __init__(self, box_data, mask_data):
31 | """Constructs box collection.
32 |
33 | Args:
34 | box_data: a numpy array of shape [N, 4] representing box coordinates
35 | mask_data: a numpy array of shape [N, height, width] representing masks
36 | with values are in {0,1}. The masks correspond to the full
37 | image. The height and the width will be equal to image height and width.
38 |
39 | Raises:
40 | ValueError: if bbox data is not a numpy array
41 | ValueError: if invalid dimensions for bbox data
42 | ValueError: if mask data is not a numpy array
43 | ValueError: if invalid dimension for mask data
44 | """
45 | super(BoxMaskList, self).__init__(box_data)
46 | if not isinstance(mask_data, np.ndarray):
47 | raise ValueError('Mask data must be a numpy array.')
48 | if len(mask_data.shape) != 3:
49 | raise ValueError('Invalid dimensions for mask data.')
50 | if mask_data.dtype != np.uint8:
51 | raise ValueError('Invalid data type for mask data: uint8 is required.')
52 | if mask_data.shape[0] != box_data.shape[0]:
53 | raise ValueError('There should be the same number of boxes and masks.')
54 | self.data['masks'] = mask_data
55 |
56 | def get_masks(self):
57 | """Convenience function for accessing masks.
58 |
59 | Returns:
60 | a numpy array of shape [N, height, width] representing masks
61 | """
62 | return self.get_field('masks')
63 |
64 |
--------------------------------------------------------------------------------
/object_detection/utils/np_box_ops_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.np_box_ops."""
17 |
18 | import numpy as np
19 | import tensorflow as tf
20 |
21 | from object_detection.utils import np_box_ops
22 |
23 |
24 | class BoxOpsTests(tf.test.TestCase):
25 |
26 | def setUp(self):
27 | boxes1 = np.array([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]],
28 | dtype=float)
29 | boxes2 = np.array([[3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0],
30 | [0.0, 0.0, 20.0, 20.0]],
31 | dtype=float)
32 | self.boxes1 = boxes1
33 | self.boxes2 = boxes2
34 |
35 | def testArea(self):
36 | areas = np_box_ops.area(self.boxes1)
37 | expected_areas = np.array([6.0, 5.0], dtype=float)
38 | self.assertAllClose(expected_areas, areas)
39 |
40 | def testIntersection(self):
41 | intersection = np_box_ops.intersection(self.boxes1, self.boxes2)
42 | expected_intersection = np.array([[2.0, 0.0, 6.0], [1.0, 0.0, 5.0]],
43 | dtype=float)
44 | self.assertAllClose(intersection, expected_intersection)
45 |
46 | def testIOU(self):
47 | iou = np_box_ops.iou(self.boxes1, self.boxes2)
48 | expected_iou = np.array([[2.0 / 16.0, 0.0, 6.0 / 400.0],
49 | [1.0 / 16.0, 0.0, 5.0 / 400.0]],
50 | dtype=float)
51 | self.assertAllClose(iou, expected_iou)
52 |
53 | def testIOA(self):
54 | boxes1 = np.array([[0.25, 0.25, 0.75, 0.75],
55 | [0.0, 0.0, 0.5, 0.75]],
56 | dtype=np.float32)
57 | boxes2 = np.array([[0.5, 0.25, 1.0, 1.0],
58 | [0.0, 0.0, 1.0, 1.0]],
59 | dtype=np.float32)
60 | ioa21 = np_box_ops.ioa(boxes2, boxes1)
61 | expected_ioa21 = np.array([[0.5, 0.0],
62 | [1.0, 1.0]],
63 | dtype=np.float32)
64 | self.assertAllClose(ioa21, expected_ioa21)
65 |
66 |
67 | if __name__ == '__main__':
68 | tf.test.main()
69 |
--------------------------------------------------------------------------------
/object_detection/utils/static_shape.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Helper functions to access TensorShape values.
17 |
18 | The rank 4 tensor_shape must be of the form [batch_size, height, width, depth].
19 | """
20 |
21 |
22 | def get_batch_size(tensor_shape):
23 | """Returns batch size from the tensor shape.
24 |
25 | Args:
26 | tensor_shape: A rank 4 TensorShape.
27 |
28 | Returns:
29 | An integer representing the batch size of the tensor.
30 | """
31 | tensor_shape.assert_has_rank(rank=4)
32 | return tensor_shape[0].value
33 |
34 |
35 | def get_height(tensor_shape):
36 | """Returns height from the tensor shape.
37 |
38 | Args:
39 | tensor_shape: A rank 4 TensorShape.
40 |
41 | Returns:
42 | An integer representing the height of the tensor.
43 | """
44 | tensor_shape.assert_has_rank(rank=4)
45 | return tensor_shape[1].value
46 |
47 |
48 | def get_width(tensor_shape):
49 | """Returns width from the tensor shape.
50 |
51 | Args:
52 | tensor_shape: A rank 4 TensorShape.
53 |
54 | Returns:
55 | An integer representing the width of the tensor.
56 | """
57 | tensor_shape.assert_has_rank(rank=4)
58 | return tensor_shape[2].value
59 |
60 |
61 | def get_depth(tensor_shape):
62 | """Returns depth from the tensor shape.
63 |
64 | Args:
65 | tensor_shape: A rank 4 TensorShape.
66 |
67 | Returns:
68 | An integer representing the depth of the tensor.
69 | """
70 | tensor_shape.assert_has_rank(rank=4)
71 | return tensor_shape[3].value
72 |
--------------------------------------------------------------------------------
/object_detection/utils/static_shape_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.utils.static_shape."""
17 |
18 | import tensorflow as tf
19 |
20 | from object_detection.utils import static_shape
21 |
22 |
23 | class StaticShapeTest(tf.test.TestCase):
24 |
25 | def test_return_correct_batchSize(self):
26 | tensor_shape = tf.TensorShape(dims=[32, 299, 384, 3])
27 | self.assertEqual(32, static_shape.get_batch_size(tensor_shape))
28 |
29 | def test_return_correct_height(self):
30 | tensor_shape = tf.TensorShape(dims=[32, 299, 384, 3])
31 | self.assertEqual(299, static_shape.get_height(tensor_shape))
32 |
33 | def test_return_correct_width(self):
34 | tensor_shape = tf.TensorShape(dims=[32, 299, 384, 3])
35 | self.assertEqual(384, static_shape.get_width(tensor_shape))
36 |
37 | def test_return_correct_depth(self):
38 | tensor_shape = tf.TensorShape(dims=[32, 299, 384, 3])
39 | self.assertEqual(3, static_shape.get_depth(tensor_shape))
40 |
41 | def test_die_on_tensor_shape_with_rank_three(self):
42 | tensor_shape = tf.TensorShape(dims=[32, 299, 384])
43 | with self.assertRaises(ValueError):
44 | static_shape.get_batch_size(tensor_shape)
45 | static_shape.get_height(tensor_shape)
46 | static_shape.get_width(tensor_shape)
47 | static_shape.get_depth(tensor_shape)
48 |
49 | if __name__ == '__main__':
50 | tf.test.main()
51 |
--------------------------------------------------------------------------------
/object_detection/utils/test_utils_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for object_detection.utils.test_utils."""
17 |
18 | import numpy as np
19 | import tensorflow as tf
20 |
21 | from object_detection.utils import test_utils
22 |
23 |
24 | class TestUtilsTest(tf.test.TestCase):
25 |
26 | def test_diagonal_gradient_image(self):
27 | """Tests if a good pyramid image is created."""
28 | pyramid_image = test_utils.create_diagonal_gradient_image(3, 4, 2)
29 |
30 | # Test which is easy to understand.
31 | expected_first_channel = np.array([[3, 2, 1, 0],
32 | [4, 3, 2, 1],
33 | [5, 4, 3, 2]], dtype=np.float32)
34 | self.assertAllEqual(np.squeeze(pyramid_image[:, :, 0]),
35 | expected_first_channel)
36 |
37 | # Actual test.
38 | expected_image = np.array([[[3, 30],
39 | [2, 20],
40 | [1, 10],
41 | [0, 0]],
42 | [[4, 40],
43 | [3, 30],
44 | [2, 20],
45 | [1, 10]],
46 | [[5, 50],
47 | [4, 40],
48 | [3, 30],
49 | [2, 20]]], dtype=np.float32)
50 |
51 | self.assertAllEqual(pyramid_image, expected_image)
52 |
53 | def test_random_boxes(self):
54 | """Tests if valid random boxes are created."""
55 | num_boxes = 1000
56 | max_height = 3
57 | max_width = 5
58 | boxes = test_utils.create_random_boxes(num_boxes,
59 | max_height,
60 | max_width)
61 |
62 | true_column = np.ones(shape=(num_boxes)) == 1
63 | self.assertAllEqual(boxes[:, 0] < boxes[:, 2], true_column)
64 | self.assertAllEqual(boxes[:, 1] < boxes[:, 3], true_column)
65 |
66 | self.assertTrue(boxes[:, 0].min() >= 0)
67 | self.assertTrue(boxes[:, 1].min() >= 0)
68 | self.assertTrue(boxes[:, 2].max() <= max_height)
69 | self.assertTrue(boxes[:, 3].max() <= max_width)
70 |
71 |
72 | if __name__ == '__main__':
73 | tf.test.main()
74 |
--------------------------------------------------------------------------------
/object_detection/visualisation_configs/eval.config:
--------------------------------------------------------------------------------
1 | # Evaluation Config for running benchmarking metrics
2 |
3 | #num_examples: 5000
4 | # Note: The below line limits the evaluation process to 10 evaluations.
5 | # Remove the below line to evaluate indefinitely.
6 | # max_evals: 10
7 |
8 | # Metrics
9 | metrics_set:'pascal_voc_detection_metrics'
10 | metrics_set:'weighted_pascal_voc_detection_metrics'
11 | metrics_set:'open_images_detection_metrics'
12 | metrics_set:'coco_detection_metrics'
13 |
14 | visualize_groundtruth_boxes: true
15 | groundtruth_box_visualization_color: 'LightPink'
16 | visualization_export_dir: "/media/ssd1/visualisation"
17 | keep_image_id_for_visualization_export: true
18 |
--------------------------------------------------------------------------------
/object_detection/visualisation_configs/faster_rcnn/input_reader.config:
--------------------------------------------------------------------------------
1 | # Input Configuration for running benchmarking metrics
2 |
3 | tf_record_input_reader {
4 |
5 | input_path: "/media/ssd1/sat_data_inferences/faster_rcnn/large/detections.tfrecord"
6 |
7 | # Can add multiple input_path arguments
8 | # input_path: "/path/to/another/model/inference.record"
9 |
10 | }
11 | label_map_path: "/media/ssd1/sat_data/satellite.pbtxt"
12 |
--------------------------------------------------------------------------------
/object_detection/visualisation_configs/mask_rcnn/input_reader.config:
--------------------------------------------------------------------------------
1 | # Input Configuration for running benchmarking metrics
2 |
3 | tf_record_input_reader {
4 |
5 | input_path: "/media/ssd1/sat_data_inferences/mask_rcnn/large/detections.tfrecord"
6 |
7 | # Can add multiple input_path arguments
8 | # input_path: "/path/to/another/model/inference.record"
9 |
10 | }
11 | label_map_path: "/media/ssd1/sat_data/satellite.pbtxt"
12 |
--------------------------------------------------------------------------------
/pycocotools/__init__.py:
--------------------------------------------------------------------------------
1 | __author__ = 'tylin'
2 |
--------------------------------------------------------------------------------
/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/pycocotools/_mask.cpython-35m-x86_64-linux-gnu.so
--------------------------------------------------------------------------------
/pycocotools/_mask.cpython-36m-x86_64-linux-gnu.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/pycocotools/_mask.cpython-36m-x86_64-linux-gnu.so
--------------------------------------------------------------------------------
/recognition/FaceRecognition.py:
--------------------------------------------------------------------------------
1 | import os
2 | import cv2
3 | import numpy as np
4 | import tensorflow as tf
5 | from recognition import facenet
6 |
7 | # Path to frozen detection graph. This is the actual model that is used for the object detection.
8 |
9 | class FaceRecognition:
10 | def __init__(self,\
11 | PATH_TO_CKPT = 'model/20170512-110547.pb',\
12 | input_image_size = 160,\
13 | BASE_DIR = os.path.dirname(__file__)):
14 | # Load models
15 | self.recognition_graph = tf.Graph()
16 | self.sess = tf.Session(graph=self.recognition_graph)
17 | print('Loading feature extraction model')
18 | with self.sess.as_default():
19 | with self.recognition_graph.as_default():
20 | facenet.load_model(os.path.join(BASE_DIR ,PATH_TO_CKPT))
21 |
22 | def __del__(self):
23 | self.sess.close()
24 |
25 | def recognize(self, image,input_image_size=160,mobilenet=False):
26 |
27 | images_placeholder = self.recognition_graph.get_tensor_by_name("input:0")
28 | embeddings = self.recognition_graph.get_tensor_by_name("embeddings:0")
29 | if not mobilenet:
30 | phase_train_placeholder = self.recognition_graph.get_tensor_by_name("phase_train:0")
31 | embedding_size = embeddings.get_shape()[1]
32 |
33 | emb_array = np.zeros((1, embedding_size))
34 | image = facenet.prewhiten(image)
35 | image = cv2.resize(image, (input_image_size, input_image_size), interpolation=cv2.INTER_AREA)
36 | image = image.reshape(-1, input_image_size, input_image_size, 3)
37 |
38 | if not mobilenet:
39 | feed_dict = {images_placeholder: image, phase_train_placeholder: False}
40 | else:
41 | feed_dict = {images_placeholder: image}
42 | emb_array[0, :] = self.sess.run(embeddings, feed_dict=feed_dict)
43 | return emb_array.squeeze()
44 |
--------------------------------------------------------------------------------
/recognition/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/recognition/__init__.py
--------------------------------------------------------------------------------
/recognition/model/det1.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/recognition/model/det1.npy
--------------------------------------------------------------------------------
/recognition/model/det2.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/recognition/model/det2.npy
--------------------------------------------------------------------------------
/recognition/model/det3.npy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/recognition/model/det3.npy
--------------------------------------------------------------------------------
/rot_and_flip.py:
--------------------------------------------------------------------------------
1 | from keras.preprocessing.image import ImageDataGenerator
2 | import numpy as np
3 | import cv2
4 | import tensorflow as tf
5 | import os
6 | from skimage import transform
7 |
8 |
9 | #datagen = ImageDataGenerator(rotation_range=20,horizontal_flip=True,brightness_range=[0.5,1],zoom_range=0.2)
10 |
11 | path='source_path'
12 |
13 | save_path='dest_path'
14 |
15 |
16 |
17 |
18 | i=0
19 | '''datagen=ImageDataGenerator(rotation_range=40,width_shift_range=2,height_shift_range=2,horizontal_flip=True,shear_range=0.1,zoom_range=0.2)
20 | generator=datagen.flow_from_directory(path,save_to_dir=path+'/resized',save_format='jpeg',batch_size=10) '''
21 | for filename in os.listdir(path):
22 | path_1=path+filename
23 | print(path_1)
24 | img=cv2.imread(os.path.join(path,filename))
25 | print(i)
26 | if img is not None:
27 | i+=1
28 | '''if i==5 :
29 | break'''
30 | flip_1 = np.fliplr(img)
31 | rot_1 = transform.rotate(img, angle=20, mode='reflect',preserve_range=True).astype(np.uint8)
32 | rot_2 = transform.rotate(img, angle=30, mode='constant',preserve_range=True).astype(np.uint8)
33 | rot_3 = transform.rotate(flip_1, angle=20, mode='constant',preserve_range=True).astype(np.uint8)
34 | cv2.imwrite(path+'/rot_1_%d.jpeg'%i,rot_1)
35 | cv2.imwrite(path+'/rot_2_%d.jpeg'%i,rot_2)
36 | cv2.imwrite(path+'/rot_3_%d.jpeg'%i,rot_3)
37 | cv2.imwrite(path+'/flip_1_%d.jpeg'%i,flip_1)
38 |
--------------------------------------------------------------------------------
/slim/WORKSPACE:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/slim/WORKSPACE
--------------------------------------------------------------------------------
/slim/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/slim/__init__.py
--------------------------------------------------------------------------------
/slim/datasets/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/slim/datasets/dataset_factory.py:
--------------------------------------------------------------------------------
1 | # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """A factory-pattern class which returns classification image/label pairs."""
16 |
17 | from __future__ import absolute_import
18 | from __future__ import division
19 | from __future__ import print_function
20 |
21 | from datasets import cifar10
22 | from datasets import flowers
23 | from datasets import imagenet
24 | from datasets import mnist
25 |
26 | datasets_map = {
27 | 'cifar10': cifar10,
28 | 'flowers': flowers,
29 | 'imagenet': imagenet,
30 | 'mnist': mnist,
31 | }
32 |
33 |
34 | def get_dataset(name, split_name, dataset_dir, file_pattern=None, reader=None):
35 | """Given a dataset name and a split_name returns a Dataset.
36 |
37 | Args:
38 | name: String, the name of the dataset.
39 | split_name: A train/test split name.
40 | dataset_dir: The directory where the dataset files are stored.
41 | file_pattern: The file pattern to use for matching the dataset source files.
42 | reader: The subclass of tf.ReaderBase. If left as `None`, then the default
43 | reader defined by each dataset is used.
44 |
45 | Returns:
46 | A `Dataset` class.
47 |
48 | Raises:
49 | ValueError: If the dataset `name` is unknown.
50 | """
51 | if name not in datasets_map:
52 | raise ValueError('Name of dataset unknown %s' % name)
53 | return datasets_map[name].get_split(
54 | split_name,
55 | dataset_dir,
56 | file_pattern,
57 | reader)
58 |
--------------------------------------------------------------------------------
/slim/deployment/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/slim/download_and_convert_data.py:
--------------------------------------------------------------------------------
1 | # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | r"""Downloads and converts a particular dataset.
16 |
17 | Usage:
18 | ```shell
19 |
20 | $ python download_and_convert_data.py \
21 | --dataset_name=mnist \
22 | --dataset_dir=/tmp/mnist
23 |
24 | $ python download_and_convert_data.py \
25 | --dataset_name=cifar10 \
26 | --dataset_dir=/tmp/cifar10
27 |
28 | $ python download_and_convert_data.py \
29 | --dataset_name=flowers \
30 | --dataset_dir=/tmp/flowers
31 | ```
32 | """
33 | from __future__ import absolute_import
34 | from __future__ import division
35 | from __future__ import print_function
36 |
37 | import tensorflow as tf
38 |
39 | from datasets import download_and_convert_cifar10
40 | from datasets import download_and_convert_flowers
41 | from datasets import download_and_convert_mnist
42 |
43 | FLAGS = tf.app.flags.FLAGS
44 |
45 | tf.app.flags.DEFINE_string(
46 | 'dataset_name',
47 | None,
48 | 'The name of the dataset to convert, one of "cifar10", "flowers", "mnist".')
49 |
50 | tf.app.flags.DEFINE_string(
51 | 'dataset_dir',
52 | None,
53 | 'The directory where the output TFRecords and temporary files are saved.')
54 |
55 |
56 | def main(_):
57 | if not FLAGS.dataset_name:
58 | raise ValueError('You must supply the dataset name with --dataset_name')
59 | if not FLAGS.dataset_dir:
60 | raise ValueError('You must supply the dataset directory with --dataset_dir')
61 |
62 | if FLAGS.dataset_name == 'cifar10':
63 | download_and_convert_cifar10.run(FLAGS.dataset_dir)
64 | elif FLAGS.dataset_name == 'flowers':
65 | download_and_convert_flowers.run(FLAGS.dataset_dir)
66 | elif FLAGS.dataset_name == 'mnist':
67 | download_and_convert_mnist.run(FLAGS.dataset_dir)
68 | else:
69 | raise ValueError(
70 | 'dataset_name [%s] was not recognized.' % FLAGS.dataset_name)
71 |
72 | if __name__ == '__main__':
73 | tf.app.run()
74 |
--------------------------------------------------------------------------------
/slim/export_inference_graph_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for export_inference_graph."""
17 |
18 | from __future__ import absolute_import
19 | from __future__ import division
20 | from __future__ import print_function
21 |
22 | import os
23 |
24 |
25 | import tensorflow as tf
26 |
27 | from tensorflow.python.platform import gfile
28 | import export_inference_graph
29 |
30 |
31 | class ExportInferenceGraphTest(tf.test.TestCase):
32 |
33 | def testExportInferenceGraph(self):
34 | tmpdir = self.get_temp_dir()
35 | output_file = os.path.join(tmpdir, 'inception_v3.pb')
36 | flags = tf.app.flags.FLAGS
37 | flags.output_file = output_file
38 | flags.model_name = 'inception_v3'
39 | flags.dataset_dir = tmpdir
40 | export_inference_graph.main(None)
41 | self.assertTrue(gfile.Exists(output_file))
42 |
43 | if __name__ == '__main__':
44 | tf.test.main()
45 |
--------------------------------------------------------------------------------
/slim/nets/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/slim/nets/inception.py:
--------------------------------------------------------------------------------
1 | # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Brings all inception models under one namespace."""
16 |
17 | from __future__ import absolute_import
18 | from __future__ import division
19 | from __future__ import print_function
20 |
21 | # pylint: disable=unused-import
22 | from nets.inception_resnet_v2 import inception_resnet_v2
23 | from nets.inception_resnet_v2 import inception_resnet_v2_arg_scope
24 | from nets.inception_resnet_v2 import inception_resnet_v2_base
25 | from nets.inception_v1 import inception_v1
26 | from nets.inception_v1 import inception_v1_arg_scope
27 | from nets.inception_v1 import inception_v1_base
28 | from nets.inception_v2 import inception_v2
29 | from nets.inception_v2 import inception_v2_arg_scope
30 | from nets.inception_v2 import inception_v2_base
31 | from nets.inception_v3 import inception_v3
32 | from nets.inception_v3 import inception_v3_arg_scope
33 | from nets.inception_v3 import inception_v3_base
34 | from nets.inception_v4 import inception_v4
35 | from nets.inception_v4 import inception_v4_arg_scope
36 | from nets.inception_v4 import inception_v4_base
37 | # pylint: enable=unused-import
38 |
39 |
40 | # Layers defined
41 | from nets.inception_resnet_v2_layers import inception_resnet_v2_layers
42 | from nets.inception_resnet_v2_layers import inception_resnet_v2_layers_arg_scope
43 | from nets.inception_resnet_v2_layers import inception_resnet_v2_layers_base
44 |
--------------------------------------------------------------------------------
/slim/nets/inception_utils.py:
--------------------------------------------------------------------------------
1 | # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Contains common code shared by all inception models.
16 |
17 | Usage of arg scope:
18 | with slim.arg_scope(inception_arg_scope()):
19 | logits, end_points = inception.inception_v3(images, num_classes,
20 | is_training=is_training)
21 |
22 | """
23 | from __future__ import absolute_import
24 | from __future__ import division
25 | from __future__ import print_function
26 |
27 | import tensorflow as tf
28 |
29 | slim = tf.contrib.slim
30 |
31 |
32 | def inception_arg_scope(weight_decay=0.00004,
33 | use_batch_norm=True,
34 | batch_norm_decay=0.9997,
35 | batch_norm_epsilon=0.001,
36 | activation_fn=tf.nn.relu):
37 | """Defines the default arg scope for inception models.
38 |
39 | Args:
40 | weight_decay: The weight decay to use for regularizing the model.
41 | use_batch_norm: "If `True`, batch_norm is applied after each convolution.
42 | batch_norm_decay: Decay for batch norm moving average.
43 | batch_norm_epsilon: Small float added to variance to avoid dividing by zero
44 | in batch norm.
45 | activation_fn: Activation function for conv2d.
46 |
47 | Returns:
48 | An `arg_scope` to use for the inception models.
49 | """
50 | batch_norm_params = {
51 | # Decay for the moving averages.
52 | 'decay': batch_norm_decay,
53 | # epsilon to prevent 0s in variance.
54 | 'epsilon': batch_norm_epsilon,
55 | # collection containing update_ops.
56 | 'updates_collections': tf.GraphKeys.UPDATE_OPS,
57 | # use fused batch norm if possible.
58 | 'fused': None,
59 | }
60 | if use_batch_norm:
61 | normalizer_fn = slim.batch_norm
62 | normalizer_params = batch_norm_params
63 | else:
64 | normalizer_fn = None
65 | normalizer_params = {}
66 | # Set weight_decay for weights in Conv and FC layers.
67 | with slim.arg_scope([slim.conv2d, slim.fully_connected],
68 | weights_regularizer=slim.l2_regularizer(weight_decay)):
69 | with slim.arg_scope(
70 | [slim.conv2d],
71 | weights_initializer=slim.variance_scaling_initializer(),
72 | activation_fn=activation_fn,
73 | normalizer_fn=normalizer_fn,
74 | normalizer_params=normalizer_params) as sc:
75 | return sc
76 |
--------------------------------------------------------------------------------
/slim/nets/mobilenet/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/iitmcvg/attendance-system/d4d7b8c0e75bbae0d8fe2f3c7f02fe7ac80d7f46/slim/nets/mobilenet/__init__.py
--------------------------------------------------------------------------------
/slim/nets/nasnet/README.md:
--------------------------------------------------------------------------------
1 | # TensorFlow-Slim NASNet-A Implementation/Checkpoints
2 | This directory contains the code for the NASNet-A model from the paper
3 | [Learning Transferable Architectures for Scalable Image Recognition](https://arxiv.org/abs/1707.07012) by Zoph et al.
4 | In nasnet.py there are three different configurations of NASNet-A that are implementented. One of the models is the NASNet-A built for CIFAR-10 and the
5 | other two are variants of NASNet-A trained on ImageNet, which are listed below.
6 |
7 | # Pre-Trained Models
8 | Two NASNet-A checkpoints are available that have been trained on the
9 | [ILSVRC-2012-CLS](http://www.image-net.org/challenges/LSVRC/2012/)
10 | image classification dataset. Accuracies were computed by evaluating using a single image crop.
11 |
12 | Model Checkpoint | Million MACs | Million Parameters | Top-1 Accuracy| Top-5 Accuracy |
13 | :----:|:------------:|:----------:|:-------:|:-------:|
14 | [NASNet-A_Mobile_224](https://storage.googleapis.com/download.tensorflow.org/models/nasnet-a_mobile_04_10_2017.tar.gz)|564|5.3|74.0|91.6|
15 | [NASNet-A_Large_331](https://storage.googleapis.com/download.tensorflow.org/models/nasnet-a_large_04_10_2017.tar.gz)|23800|88.9|82.7|96.2|
16 |
17 |
18 | Here is an example of how to download the NASNet-A_Mobile_224 checkpoint. The way to download the NASNet-A_Large_331 is the same.
19 |
20 | ```shell
21 | CHECKPOINT_DIR=/tmp/checkpoints
22 | mkdir ${CHECKPOINT_DIR}
23 | cd ${CHECKPOINT_DIR}
24 | wget https://storage.googleapis.com/download.tensorflow.org/models/nasnet-a_mobile_04_10_2017.tar.gz
25 | tar -xvf nasnet-a_mobile_04_10_2017.tar.gz
26 | rm nasnet-a_mobile_04_10_2017.tar.gz
27 | ```
28 | More information on integrating NASNet Models into your project can be found at the [TF-Slim Image Classification Library](https://github.com/tensorflow/models/blob/master/research/slim/README.md).
29 |
30 | To get started running models on-device go to [TensorFlow Mobile](https://www.tensorflow.org/mobile/).
31 |
32 | ## Sample Commands for using NASNet-A Mobile and Large Checkpoints for Inference
33 | -------
34 | Run eval with the NASNet-A mobile ImageNet model
35 |
36 | ```shell
37 | DATASET_DIR=/tmp/imagenet
38 | EVAL_DIR=/tmp/tfmodel/eval
39 | CHECKPOINT_DIR=/tmp/checkpoints/model.ckpt
40 | python tensorflow_models/research/slim/eval_image_classifier \
41 | --checkpoint_path=${CHECKPOINT_DIR} \
42 | --eval_dir=${EVAL_DIR} \
43 | --dataset_dir=${DATASET_DIR} \
44 | --dataset_name=imagenet \
45 | --dataset_split_name=validation \
46 | --model_name=nasnet_mobile \
47 | --eval_image_size=224
48 | ```
49 |
50 | Run eval with the NASNet-A large ImageNet model
51 |
52 | ```shell
53 | DATASET_DIR=/tmp/imagenet
54 | EVAL_DIR=/tmp/tfmodel/eval
55 | CHECKPOINT_DIR=/tmp/checkpoints/model.ckpt
56 | python tensorflow_models/research/slim/eval_image_classifier \
57 | --checkpoint_path=${CHECKPOINT_DIR} \
58 | --eval_dir=${EVAL_DIR} \
59 | --dataset_dir=${DATASET_DIR} \
60 | --dataset_name=imagenet \
61 | --dataset_split_name=validation \
62 | --model_name=nasnet_large \
63 | --eval_image_size=331
64 | ```
65 |
--------------------------------------------------------------------------------
/slim/nets/nasnet/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/slim/nets/nasnet/nasnet_utils_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Tests for slim.nets.nasnet.nasnet_utils."""
16 |
17 | from __future__ import absolute_import
18 | from __future__ import division
19 | from __future__ import print_function
20 |
21 | import tensorflow as tf
22 |
23 | from nets.nasnet import nasnet_utils
24 |
25 |
26 | class NasnetUtilsTest(tf.test.TestCase):
27 |
28 | def testCalcReductionLayers(self):
29 | num_cells = 18
30 | num_reduction_layers = 2
31 | reduction_layers = nasnet_utils.calc_reduction_layers(
32 | num_cells, num_reduction_layers)
33 | self.assertEqual(len(reduction_layers), 2)
34 | self.assertEqual(reduction_layers[0], 6)
35 | self.assertEqual(reduction_layers[1], 12)
36 |
37 | def testGetChannelIndex(self):
38 | data_formats = ['NHWC', 'NCHW']
39 | for data_format in data_formats:
40 | index = nasnet_utils.get_channel_index(data_format)
41 | correct_index = 3 if data_format == 'NHWC' else 1
42 | self.assertEqual(index, correct_index)
43 |
44 | def testGetChannelDim(self):
45 | data_formats = ['NHWC', 'NCHW']
46 | shape = [10, 20, 30, 40]
47 | for data_format in data_formats:
48 | dim = nasnet_utils.get_channel_dim(shape, data_format)
49 | correct_dim = shape[3] if data_format == 'NHWC' else shape[1]
50 | self.assertEqual(dim, correct_dim)
51 |
52 | def testGlobalAvgPool(self):
53 | data_formats = ['NHWC', 'NCHW']
54 | inputs = tf.placeholder(tf.float32, (5, 10, 20, 10))
55 | for data_format in data_formats:
56 | output = nasnet_utils.global_avg_pool(
57 | inputs, data_format)
58 | self.assertEqual(output.shape, [5, 10])
59 |
60 |
61 | if __name__ == '__main__':
62 | tf.test.main()
63 |
--------------------------------------------------------------------------------
/slim/nets/nets_factory_test.py:
--------------------------------------------------------------------------------
1 | # Copyright 2016 Google Inc. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 |
16 | """Tests for slim.inception."""
17 |
18 | from __future__ import absolute_import
19 | from __future__ import division
20 | from __future__ import print_function
21 |
22 |
23 | import tensorflow as tf
24 |
25 | from nets import nets_factory
26 |
27 |
28 | class NetworksTest(tf.test.TestCase):
29 |
30 | def testGetNetworkFnFirstHalf(self):
31 | batch_size = 5
32 | num_classes = 1000
33 | for net in list(nets_factory.networks_map.keys())[:10]:
34 | with tf.Graph().as_default() as g, self.test_session(g):
35 | net_fn = nets_factory.get_network_fn(net, num_classes)
36 | # Most networks use 224 as their default_image_size
37 | image_size = getattr(net_fn, 'default_image_size', 224)
38 | inputs = tf.random_uniform((batch_size, image_size, image_size, 3))
39 | logits, end_points = net_fn(inputs)
40 | self.assertTrue(isinstance(logits, tf.Tensor))
41 | self.assertTrue(isinstance(end_points, dict))
42 | self.assertEqual(logits.get_shape().as_list()[0], batch_size)
43 | self.assertEqual(logits.get_shape().as_list()[-1], num_classes)
44 |
45 | def testGetNetworkFnSecondHalf(self):
46 | batch_size = 5
47 | num_classes = 1000
48 | for net in list(nets_factory.networks_map.keys())[10:]:
49 | with tf.Graph().as_default() as g, self.test_session(g):
50 | net_fn = nets_factory.get_network_fn(net, num_classes)
51 | # Most networks use 224 as their default_image_size
52 | image_size = getattr(net_fn, 'default_image_size', 224)
53 | inputs = tf.random_uniform((batch_size, image_size, image_size, 3))
54 | logits, end_points = net_fn(inputs)
55 | self.assertTrue(isinstance(logits, tf.Tensor))
56 | self.assertTrue(isinstance(end_points, dict))
57 | self.assertEqual(logits.get_shape().as_list()[0], batch_size)
58 | self.assertEqual(logits.get_shape().as_list()[-1], num_classes)
59 |
60 | if __name__ == '__main__':
61 | tf.test.main()
62 |
--------------------------------------------------------------------------------
/slim/preprocessing/__init__.py:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/slim/preprocessing/lenet_preprocessing.py:
--------------------------------------------------------------------------------
1 | # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Provides utilities for preprocessing."""
16 |
17 | from __future__ import absolute_import
18 | from __future__ import division
19 | from __future__ import print_function
20 |
21 | import tensorflow as tf
22 |
23 | slim = tf.contrib.slim
24 |
25 |
26 | def preprocess_image(image, output_height, output_width, is_training):
27 | """Preprocesses the given image.
28 |
29 | Args:
30 | image: A `Tensor` representing an image of arbitrary size.
31 | output_height: The height of the image after preprocessing.
32 | output_width: The width of the image after preprocessing.
33 | is_training: `True` if we're preprocessing the image for training and
34 | `False` otherwise.
35 |
36 | Returns:
37 | A preprocessed image.
38 | """
39 | image = tf.to_float(image)
40 | image = tf.image.resize_image_with_crop_or_pad(
41 | image, output_width, output_height)
42 | image = tf.subtract(image, 128.0)
43 | image = tf.div(image, 128.0)
44 | return image
45 |
--------------------------------------------------------------------------------
/slim/scripts/train_cifarnet_on_cifar10.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | # ==============================================================================
16 | #
17 | # This script performs the following operations:
18 | # 1. Downloads the Cifar10 dataset
19 | # 2. Trains a CifarNet model on the Cifar10 training set.
20 | # 3. Evaluates the model on the Cifar10 testing set.
21 | #
22 | # Usage:
23 | # cd slim
24 | # ./scripts/train_cifarnet_on_cifar10.sh
25 | set -e
26 |
27 | # Where the checkpoint and logs will be saved to.
28 | TRAIN_DIR=/tmp/cifarnet-model
29 |
30 | # Where the dataset is saved to.
31 | DATASET_DIR=/tmp/cifar10
32 |
33 | # Download the dataset
34 | python download_and_convert_data.py \
35 | --dataset_name=cifar10 \
36 | --dataset_dir=${DATASET_DIR}
37 |
38 | # Run training.
39 | python train_image_classifier.py \
40 | --train_dir=${TRAIN_DIR} \
41 | --dataset_name=cifar10 \
42 | --dataset_split_name=train \
43 | --dataset_dir=${DATASET_DIR} \
44 | --model_name=cifarnet \
45 | --preprocessing_name=cifarnet \
46 | --max_number_of_steps=100000 \
47 | --batch_size=128 \
48 | --save_interval_secs=120 \
49 | --save_summaries_secs=120 \
50 | --log_every_n_steps=100 \
51 | --optimizer=sgd \
52 | --learning_rate=0.1 \
53 | --learning_rate_decay_factor=0.1 \
54 | --num_epochs_per_decay=200 \
55 | --weight_decay=0.004
56 |
57 | # Run evaluation.
58 | python eval_image_classifier.py \
59 | --checkpoint_path=${TRAIN_DIR} \
60 | --eval_dir=${TRAIN_DIR} \
61 | --dataset_name=cifar10 \
62 | --dataset_split_name=test \
63 | --dataset_dir=${DATASET_DIR} \
64 | --model_name=cifarnet
65 |
--------------------------------------------------------------------------------
/slim/scripts/train_lenet_on_mnist.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | # ==============================================================================
16 | #
17 | # This script performs the following operations:
18 | # 1. Downloads the MNIST dataset
19 | # 2. Trains a LeNet model on the MNIST training set.
20 | # 3. Evaluates the model on the MNIST testing set.
21 | #
22 | # Usage:
23 | # cd slim
24 | # ./slim/scripts/train_lenet_on_mnist.sh
25 | set -e
26 |
27 | # Where the checkpoint and logs will be saved to.
28 | TRAIN_DIR=/tmp/lenet-model
29 |
30 | # Where the dataset is saved to.
31 | DATASET_DIR=/tmp/mnist
32 |
33 | # Download the dataset
34 | python download_and_convert_data.py \
35 | --dataset_name=mnist \
36 | --dataset_dir=${DATASET_DIR}
37 |
38 | # Run training.
39 | python train_image_classifier.py \
40 | --train_dir=${TRAIN_DIR} \
41 | --dataset_name=mnist \
42 | --dataset_split_name=train \
43 | --dataset_dir=${DATASET_DIR} \
44 | --model_name=lenet \
45 | --preprocessing_name=lenet \
46 | --max_number_of_steps=20000 \
47 | --batch_size=50 \
48 | --learning_rate=0.01 \
49 | --save_interval_secs=60 \
50 | --save_summaries_secs=60 \
51 | --log_every_n_steps=100 \
52 | --optimizer=sgd \
53 | --learning_rate_decay_type=fixed \
54 | --weight_decay=0
55 |
56 | # Run evaluation.
57 | python eval_image_classifier.py \
58 | --checkpoint_path=${TRAIN_DIR} \
59 | --eval_dir=${TRAIN_DIR} \
60 | --dataset_name=mnist \
61 | --dataset_split_name=test \
62 | --dataset_dir=${DATASET_DIR} \
63 | --model_name=lenet
64 |
--------------------------------------------------------------------------------
/slim/setup.py:
--------------------------------------------------------------------------------
1 | # Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # http://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ==============================================================================
15 | """Setup script for slim."""
16 |
17 | from setuptools import find_packages
18 | from setuptools import setup
19 |
20 |
21 | setup(
22 | name='slim',
23 | version='0.1',
24 | include_package_data=True,
25 | packages=find_packages(),
26 | description='tf-slim',
27 | )
28 |
--------------------------------------------------------------------------------
/train_with_npy.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | from classifier.FaceClassifier import FaceClassifier
3 | #Training classifiers after obtaining the feaure vectors from the recognition model
4 | features=np.load('./npy files/features.npy')
5 | labels=np.load('./npy files/labels.npy')
6 | face_classifier = FaceClassifier('./classifier/trained_svm.pkl')
7 | Svm = face_classifier.train(features,labels,model='SVM',save_model_path='./classifier/new_classifiers/trained_svm.pkl')
8 | #KNN = face_classifier.train(features,labels,model='knn',save_model_path='./classifier/trained_classifier.pkl')
9 | KNN_5 = face_classifier.train(features,labels,model='knn',knn_neighbours=5,save_model_path='./classifier/new_classifiers/knn_5.pkl')
10 | KNN_7 = face_classifier.train(features,labels,model='knn',knn_neighbours=7,save_model_path='./classifier/new_classifiers/knn_7.pkl')
11 | random_forests= face_classifier.train(features,labels,model='random-forests',save_model_path='./classifier/new_classifiers/random_forests.pkl')
12 | Svm_poly = face_classifier.train(features,labels,model='SVC-poly',save_model_path='./classifier/new_classifiers/trained_svm_poly.pkl')
13 | Svm_rbf = face_classifier.train(features,labels,model='SVC-rbf',save_model_path='./classifier/new_classifiers/trained_svm_rbf.pkl')
14 |
--------------------------------------------------------------------------------
/utils/explore_graph.py:
--------------------------------------------------------------------------------
1 | '''
2 | Prints all tensors in a frozen graph
3 | '''
4 | import tensorflow as tf
5 | import argparse
6 | from recognition import facenet
7 |
8 | parser=argparse.ArgumentParser()
9 |
10 | parser.add_argument("--frozen_graph",default="recognition/model/20180402-114759.pb",
11 | help="Frozen graph to use.")
12 |
13 | args=parser.parse_args()
14 |
15 | with tf.Graph().as_default() as graph:
16 | facenet.load_model(args.frozen_graph)
17 |
18 | nodes=[n.name for n in graph.as_graph_def().node if not (n.name.startswith("InceptionResnetV1") )]#or n.name.startswith("MobilenetV2"))]
19 |
20 | print("\n".join(nodes))
21 |
22 | print(tf.contrib.graph_editor.get_tensors(tf.get_default_graph()))
--------------------------------------------------------------------------------