├── ActivityNet_task_1_summary.pdf ├── BSN ├── Evaluation │ ├── data │ │ ├── activity_net.v1-3.min.json │ │ ├── activity_net_1_3_new.json │ │ ├── activity_net_1_3_new_19934.json │ │ ├── sample_classification_prediction.json │ │ └── sample_detection_prediction.json │ ├── eval_proposal.py │ ├── eval_proposal.pyc │ ├── utils.py │ └── utils.pyc ├── bsn_3fold_diff_backbone.sh ├── check_videos.py ├── data │ ├── activitynet_annotations │ │ ├── 3fold_csv │ │ │ ├── fold_0_activity_net.v1-3.min.json │ │ │ ├── fold_0_video_info.csv │ │ │ ├── fold_0_video_info_clean_for_train.csv │ │ │ ├── fold_1_activity_net.v1-3.min.json │ │ │ ├── fold_1_video_info.csv │ │ │ ├── fold_1_video_info_clean_for_train.csv │ │ │ ├── fold_2_activity_net.v1-3.min.json │ │ │ ├── fold_2_video_info.csv │ │ │ └── fold_2_video_info_clean_for_train.csv │ │ ├── action_name.csv │ │ ├── activity_net.v1-3.min.json │ │ ├── anet_anno_action.json │ │ ├── anet_anno_action_19994.json │ │ └── video_info.csv │ └── activitynet_feature_cuhk │ │ ├── concat_feature.py │ │ ├── data_process.py │ │ ├── fuse_feat_non_rescale.py │ │ ├── fuse_feat_non_rescale_mp.py │ │ ├── ldb_process.py │ │ └── name_list.txt ├── data_process.py ├── dataset.py ├── ensemble │ ├── eval_search.py │ ├── load_all_PEM_result.py │ ├── main_fusion.py │ ├── main_search.py │ ├── post_processing_fusion.py │ └── post_processing_fusion_search.py ├── eval.py ├── extract_frames.py ├── loss_function.py ├── main.py ├── models.py ├── opts.py ├── pgm.py ├── post_processing.py ├── test_list.txt ├── train_list.txt └── val_list.txt ├── README.md ├── TSN ├── dataset.py ├── extract_anet_feature.py ├── extract_feature.sh ├── lists_16 │ ├── gen_list.py │ ├── list.txt.new0 │ ├── list.txt.new1 │ ├── list.txt.new10 │ ├── list.txt.new11 │ ├── list.txt.new12 │ ├── list.txt.new13 │ ├── list.txt.new14 │ ├── list.txt.new15 │ ├── list.txt.new2 │ ├── list.txt.new3 │ ├── list.txt.new4 │ ├── list.txt.new5 │ ├── list.txt.new6 │ ├── list.txt.new7 │ ├── list.txt.new8 │ └── list.txt.new9 ├── main.py ├── models.py ├── new_train_list.txt ├── new_val_list.txt ├── ops │ ├── __init__.py │ ├── __init__.pyc │ ├── __pycache__ │ │ ├── __init__.cpython-36.pyc │ │ └── basic_ops.cpython-36.pyc │ ├── basic_ops.py │ ├── basic_ops.pyc │ └── utils.py ├── opts.py ├── pretrain │ ├── __init__.py │ ├── dpn.py │ ├── inception_v4.py │ ├── inceptionresnetv2.py │ ├── include.py │ ├── resnet.py │ ├── resnet_ibn_a.py │ ├── resnet_ibn_a_old.py │ ├── resnet_ibn_b.py │ ├── resnext_ibn_a.py │ ├── se_module.py │ ├── se_resnet_ibn_a.py │ ├── senet.py │ └── xception.py ├── run.sh ├── test_list.txt ├── test_models.py ├── tf_model_zoo │ ├── LICENSE │ ├── README.md │ ├── __init__.py │ ├── bninception │ │ ├── __init__.py │ │ ├── bn_inception.yaml │ │ ├── caffe_pb2.py │ │ ├── inceptionv3.yaml │ │ ├── layer_factory.py │ │ ├── parse_caffe.py │ │ └── pytorch_load.py │ ├── inceptionresnetv2 │ │ ├── __init__.py │ │ ├── pytorch_load.py │ │ ├── tensorflow_dump.py │ │ └── torch_load.lua │ ├── inceptionv4 │ │ ├── __init__.py │ │ ├── pytorch_load.py │ │ ├── tensorflow_dump.py │ │ └── torch_load.lua │ ├── lena_224.png │ ├── lena_299.png │ ├── lena_origin.png │ └── models │ │ ├── AUTHORS │ │ ├── CONTRIBUTING.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── WORKSPACE │ │ ├── autoencoder │ │ ├── AdditiveGaussianNoiseAutoencoderRunner.py │ │ ├── AutoencoderRunner.py │ │ ├── MaskingNoiseAutoencoderRunner.py │ │ ├── Utils.py │ │ ├── VariationalAutoencoderRunner.py │ │ ├── __init__.py │ │ └── autoencoder_models │ │ │ ├── Autoencoder.py │ │ │ ├── DenoisingAutoencoder.py │ │ │ ├── VariationalAutoencoder.py │ │ │ └── __init__.py │ │ ├── compression │ │ ├── README.md │ │ ├── decoder.py │ │ ├── encoder.py │ │ ├── example.png │ │ └── msssim.py │ │ ├── differential_privacy │ │ ├── README.md │ │ ├── __init__.py │ │ ├── dp_sgd │ │ │ ├── README.md │ │ │ ├── dp_mnist │ │ │ │ ├── BUILD │ │ │ │ └── dp_mnist.py │ │ │ ├── dp_optimizer │ │ │ │ ├── BUILD │ │ │ │ ├── dp_optimizer.py │ │ │ │ ├── dp_pca.py │ │ │ │ ├── sanitizer.py │ │ │ │ └── utils.py │ │ │ └── per_example_gradients │ │ │ │ ├── BUILD │ │ │ │ └── per_example_gradients.py │ │ ├── multiple_teachers │ │ │ ├── BUILD │ │ │ ├── README.md │ │ │ ├── aggregation.py │ │ │ ├── analysis.py │ │ │ ├── deep_cnn.py │ │ │ ├── input.py │ │ │ ├── metrics.py │ │ │ ├── train_student.py │ │ │ ├── train_student_mnist_250_lap_20_count_50_epochs_600.sh │ │ │ ├── train_teachers.py │ │ │ └── utils.py │ │ └── privacy_accountant │ │ │ ├── python │ │ │ ├── BUILD │ │ │ └── gaussian_moments.py │ │ │ └── tf │ │ │ ├── BUILD │ │ │ └── accountant.py │ │ ├── im2txt │ │ ├── README.md │ │ ├── WORKSPACE │ │ ├── g3doc │ │ │ ├── COCO_val2014_000000224477.jpg │ │ │ ├── example_captions.jpg │ │ │ └── show_and_tell_architecture.png │ │ └── im2txt │ │ │ ├── BUILD │ │ │ ├── configuration.py │ │ │ ├── data │ │ │ ├── build_mscoco_data.py │ │ │ └── download_and_preprocess_mscoco.sh │ │ │ ├── evaluate.py │ │ │ ├── inference_utils │ │ │ ├── BUILD │ │ │ ├── caption_generator.py │ │ │ ├── caption_generator_test.py │ │ │ ├── inference_wrapper_base.py │ │ │ └── vocabulary.py │ │ │ ├── inference_wrapper.py │ │ │ ├── ops │ │ │ ├── BUILD │ │ │ ├── image_embedding.py │ │ │ ├── image_embedding_test.py │ │ │ ├── image_processing.py │ │ │ └── inputs.py │ │ │ ├── run_inference.py │ │ │ ├── show_and_tell_model.py │ │ │ ├── show_and_tell_model_test.py │ │ │ └── train.py │ │ ├── inception │ │ ├── README.md │ │ ├── WORKSPACE │ │ ├── g3doc │ │ │ └── inception_v3_architecture.png │ │ └── inception │ │ │ ├── BUILD │ │ │ ├── data │ │ │ ├── build_image_data.py │ │ │ ├── build_imagenet_data.py │ │ │ ├── download_and_preprocess_flowers.sh │ │ │ ├── download_and_preprocess_flowers_mac.sh │ │ │ ├── download_and_preprocess_imagenet.sh │ │ │ ├── download_imagenet.sh │ │ │ ├── imagenet_2012_validation_synset_labels.txt │ │ │ ├── imagenet_lsvrc_2015_synsets.txt │ │ │ ├── imagenet_metadata.txt │ │ │ ├── preprocess_imagenet_validation_data.py │ │ │ └── process_bounding_boxes.py │ │ │ ├── dataset.py │ │ │ ├── flowers_data.py │ │ │ ├── flowers_eval.py │ │ │ ├── flowers_train.py │ │ │ ├── image_processing.py │ │ │ ├── imagenet_data.py │ │ │ ├── imagenet_distributed_train.py │ │ │ ├── imagenet_eval.py │ │ │ ├── imagenet_train.py │ │ │ ├── inception_distributed_train.py │ │ │ ├── inception_eval.py │ │ │ ├── inception_model.py │ │ │ ├── inception_train.py │ │ │ └── slim │ │ │ ├── BUILD │ │ │ ├── README.md │ │ │ ├── collections_test.py │ │ │ ├── inception_model.py │ │ │ ├── inception_test.py │ │ │ ├── losses.py │ │ │ ├── losses_test.py │ │ │ ├── ops.py │ │ │ ├── ops_test.py │ │ │ ├── scopes.py │ │ │ ├── scopes_test.py │ │ │ ├── slim.py │ │ │ ├── variables.py │ │ │ └── variables_test.py │ │ ├── lm_1b │ │ ├── BUILD │ │ ├── README.md │ │ ├── data_utils.py │ │ └── lm_1b_eval.py │ │ ├── namignizer │ │ ├── README.md │ │ ├── data_utils.py │ │ ├── model.py │ │ └── names.py │ │ ├── neural_gpu │ │ ├── README.md │ │ ├── data_utils.py │ │ ├── neural_gpu.py │ │ └── neural_gpu_trainer.py │ │ ├── neural_programmer │ │ ├── README.md │ │ ├── data_utils.py │ │ ├── model.py │ │ ├── neural_programmer.py │ │ ├── nn_utils.py │ │ ├── parameters.py │ │ └── wiki_data.py │ │ ├── resnet │ │ ├── BUILD │ │ ├── README.md │ │ ├── cifar_input.py │ │ ├── g3doc │ │ │ ├── cifar_resnet.gif │ │ │ └── cifar_resnet_legends.gif │ │ ├── resnet_main.py │ │ └── resnet_model.py │ │ ├── slim │ │ ├── BUILD │ │ ├── README.md │ │ ├── datasets │ │ │ ├── __init__.py │ │ │ ├── cifar10.py │ │ │ ├── dataset_factory.py │ │ │ ├── dataset_utils.py │ │ │ ├── download_and_convert_cifar10.py │ │ │ ├── download_and_convert_flowers.py │ │ │ ├── download_and_convert_mnist.py │ │ │ ├── flowers.py │ │ │ ├── imagenet.py │ │ │ └── mnist.py │ │ ├── deployment │ │ │ ├── __init__.py │ │ │ ├── model_deploy.py │ │ │ └── model_deploy_test.py │ │ ├── download_and_convert_data.py │ │ ├── eval_image_classifier.py │ │ ├── nets │ │ │ ├── __init__.py │ │ │ ├── alexnet.py │ │ │ ├── alexnet_test.py │ │ │ ├── cifarnet.py │ │ │ ├── inception.py │ │ │ ├── inception_resnet_v2.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 │ │ │ ├── nets_factory.py │ │ │ ├── nets_factory_test.py │ │ │ ├── overfeat.py │ │ │ ├── overfeat_test.py │ │ │ ├── resnet_utils.py │ │ │ ├── resnet_v1.py │ │ │ ├── resnet_v1_test.py │ │ │ ├── resnet_v2.py │ │ │ ├── resnet_v2_test.py │ │ │ ├── vgg.py │ │ │ └── vgg_test.py │ │ ├── preprocessing │ │ │ ├── __init__.py │ │ │ ├── cifarnet_preprocessing.py │ │ │ ├── inception_preprocessing.py │ │ │ ├── lenet_preprocessing.py │ │ │ ├── preprocessing_factory.py │ │ │ └── vgg_preprocessing.py │ │ ├── scripts │ │ │ ├── finetune_inception_v1_on_flowers.sh │ │ │ ├── finetune_inception_v3_on_flowers.sh │ │ │ ├── train_cifarnet_on_cifar10.sh │ │ │ └── train_lenet_on_mnist.sh │ │ ├── slim_walkthough.ipynb │ │ └── train_image_classifier.py │ │ ├── street │ │ ├── README.md │ │ ├── cc │ │ │ └── rnn_ops.cc │ │ ├── g3doc │ │ │ ├── avdessapins.png │ │ │ └── vgslspecs.md │ │ ├── python │ │ │ ├── decoder.py │ │ │ ├── decoder_test.py │ │ │ ├── errorcounter.py │ │ │ ├── errorcounter_test.py │ │ │ ├── nn_ops.py │ │ │ ├── shapes.py │ │ │ ├── shapes_test.py │ │ │ ├── vgsl_eval.py │ │ │ ├── vgsl_input.py │ │ │ ├── vgsl_model.py │ │ │ ├── vgsl_model_test.py │ │ │ ├── vgsl_train.py │ │ │ ├── vgslspecs.py │ │ │ └── vgslspecs_test.py │ │ └── testdata │ │ │ ├── arial-32-tiny │ │ │ ├── arial.charset_size=105.txt │ │ │ ├── charset_size=134.txt │ │ │ ├── charset_size_10.txt │ │ │ ├── mnist-tiny │ │ │ ├── numbers-16-tiny │ │ │ └── numbers.charset_size=12.txt │ │ ├── swivel │ │ ├── README.md │ │ ├── analogy.cc │ │ ├── eval.mk │ │ ├── fastprep.cc │ │ ├── fastprep.mk │ │ ├── glove_to_shards.py │ │ ├── nearest.py │ │ ├── prep.py │ │ ├── swivel.py │ │ ├── text2bin.py │ │ ├── vecs.py │ │ └── wordsim.py │ │ ├── syntaxnet │ │ ├── Dockerfile │ │ ├── README.md │ │ ├── WORKSPACE │ │ ├── beam_search_training.png │ │ ├── ff_nn_schematic.png │ │ ├── looping-parser.gif │ │ ├── sawman.png │ │ ├── syntaxnet │ │ │ ├── BUILD │ │ │ ├── affix.cc │ │ │ ├── affix.h │ │ │ ├── arc_standard_transitions.cc │ │ │ ├── arc_standard_transitions_test.cc │ │ │ ├── base.h │ │ │ ├── beam_reader_ops.cc │ │ │ ├── beam_reader_ops_test.py │ │ │ ├── binary_segment_state.cc │ │ │ ├── binary_segment_state.h │ │ │ ├── binary_segment_state_test.cc │ │ │ ├── binary_segment_transitions.cc │ │ │ ├── binary_segment_transitions_test.cc │ │ │ ├── char_properties.cc │ │ │ ├── char_properties.h │ │ │ ├── char_properties_test.cc │ │ │ ├── conll2tree.py │ │ │ ├── context.pbtxt │ │ │ ├── demo.sh │ │ │ ├── dictionary.proto │ │ │ ├── document_filters.cc │ │ │ ├── document_format.cc │ │ │ ├── document_format.h │ │ │ ├── embedding_feature_extractor.cc │ │ │ ├── embedding_feature_extractor.h │ │ │ ├── feature_extractor.cc │ │ │ ├── feature_extractor.h │ │ │ ├── feature_extractor.proto │ │ │ ├── feature_types.h │ │ │ ├── fml_parser.cc │ │ │ ├── fml_parser.h │ │ │ ├── graph_builder.py │ │ │ ├── graph_builder_test.py │ │ │ ├── kbest_syntax.proto │ │ │ ├── lexicon_builder.cc │ │ │ ├── lexicon_builder_test.py │ │ │ ├── load_parser_ops.py │ │ │ ├── models │ │ │ │ ├── parsey_mcparseface │ │ │ │ │ ├── context.pbtxt │ │ │ │ │ ├── fine-to-universal.map │ │ │ │ │ ├── label-map │ │ │ │ │ ├── parser-params │ │ │ │ │ ├── prefix-table │ │ │ │ │ ├── suffix-table │ │ │ │ │ ├── tag-map │ │ │ │ │ ├── tagger-params │ │ │ │ │ └── word-map │ │ │ │ └── parsey_universal │ │ │ │ │ ├── context-tokenize-zh.pbtxt │ │ │ │ │ ├── context.pbtxt │ │ │ │ │ ├── parse.sh │ │ │ │ │ ├── tokenize.sh │ │ │ │ │ └── tokenize_zh.sh │ │ │ ├── morpher_transitions.cc │ │ │ ├── morphology_label_set.cc │ │ │ ├── morphology_label_set.h │ │ │ ├── morphology_label_set_test.cc │ │ │ ├── ops │ │ │ │ └── parser_ops.cc │ │ │ ├── parser_eval.py │ │ │ ├── parser_features.cc │ │ │ ├── parser_features.h │ │ │ ├── parser_features_test.cc │ │ │ ├── parser_state.cc │ │ │ ├── parser_state.h │ │ │ ├── parser_trainer.py │ │ │ ├── parser_trainer_test.sh │ │ │ ├── parser_transitions.cc │ │ │ ├── parser_transitions.h │ │ │ ├── populate_test_inputs.cc │ │ │ ├── populate_test_inputs.h │ │ │ ├── proto_io.h │ │ │ ├── reader_ops.cc │ │ │ ├── reader_ops_test.py │ │ │ ├── registry.cc │ │ │ ├── registry.h │ │ │ ├── segmenter_utils.cc │ │ │ ├── segmenter_utils.h │ │ │ ├── segmenter_utils_test.cc │ │ │ ├── sentence.proto │ │ │ ├── sentence_batch.cc │ │ │ ├── sentence_batch.h │ │ │ ├── sentence_features.cc │ │ │ ├── sentence_features.h │ │ │ ├── sentence_features_test.cc │ │ │ ├── shared_store.cc │ │ │ ├── shared_store.h │ │ │ ├── shared_store_test.cc │ │ │ ├── sparse.proto │ │ │ ├── structured_graph_builder.py │ │ │ ├── syntaxnet.bzl │ │ │ ├── tagger_transitions.cc │ │ │ ├── tagger_transitions_test.cc │ │ │ ├── task_context.cc │ │ │ ├── task_context.h │ │ │ ├── task_spec.proto │ │ │ ├── term_frequency_map.cc │ │ │ ├── term_frequency_map.h │ │ │ ├── test_main.cc │ │ │ ├── testdata │ │ │ │ ├── context.pbtxt │ │ │ │ ├── document │ │ │ │ └── mini-training-set │ │ │ ├── text_formats.cc │ │ │ ├── text_formats_test.py │ │ │ ├── unpack_sparse_features.cc │ │ │ ├── utils.cc │ │ │ ├── utils.h │ │ │ ├── workspace.cc │ │ │ └── workspace.h │ │ ├── third_party │ │ │ └── utf │ │ │ │ ├── BUILD │ │ │ │ ├── README │ │ │ │ ├── rune.c │ │ │ │ ├── runestrcat.c │ │ │ │ ├── runestrchr.c │ │ │ │ ├── runestrcmp.c │ │ │ │ ├── runestrcpy.c │ │ │ │ ├── runestrdup.c │ │ │ │ ├── runestrecpy.c │ │ │ │ ├── runestrlen.c │ │ │ │ ├── runestrncat.c │ │ │ │ ├── runestrncmp.c │ │ │ │ ├── runestrncpy.c │ │ │ │ ├── runestrrchr.c │ │ │ │ ├── runestrstr.c │ │ │ │ ├── runetype.c │ │ │ │ ├── runetypebody.c │ │ │ │ ├── utf.h │ │ │ │ ├── utfdef.h │ │ │ │ ├── utfecpy.c │ │ │ │ ├── utflen.c │ │ │ │ ├── utfnlen.c │ │ │ │ ├── utfrrune.c │ │ │ │ ├── utfrune.c │ │ │ │ └── utfutf.c │ │ ├── tools │ │ │ └── bazel.rc │ │ ├── universal.md │ │ └── util │ │ │ └── utf8 │ │ │ ├── BUILD │ │ │ ├── gtest_main.cc │ │ │ ├── unicodetext.cc │ │ │ ├── unicodetext.h │ │ │ ├── unicodetext_main.cc │ │ │ ├── unicodetext_unittest.cc │ │ │ ├── unilib.cc │ │ │ ├── unilib.h │ │ │ └── unilib_utf8_utils.h │ │ ├── textsum │ │ ├── BUILD │ │ ├── README.md │ │ ├── batch_reader.py │ │ ├── beam_search.py │ │ ├── data.py │ │ ├── data │ │ │ ├── data │ │ │ └── vocab │ │ ├── data_convert_example.py │ │ ├── seq2seq_attention.py │ │ ├── seq2seq_attention_decode.py │ │ ├── seq2seq_attention_model.py │ │ └── seq2seq_lib.py │ │ ├── transformer │ │ ├── README.md │ │ ├── cluttered_mnist.py │ │ ├── data │ │ │ └── README.md │ │ ├── example.py │ │ ├── spatial_transformer.py │ │ └── tf_utils.py │ │ └── video_prediction │ │ ├── README.md │ │ ├── download_data.sh │ │ ├── lstm_ops.py │ │ ├── prediction_input.py │ │ ├── prediction_model.py │ │ ├── prediction_train.py │ │ └── push_datafiles.txt ├── train_list.txt ├── transforms.py └── val_list.txt ├── demo_activity ├── bsn │ ├── Evaluation │ │ ├── data │ │ │ └── activity_net.v1-3.min.json │ │ ├── eval_proposal.py │ │ ├── eval_proposal.pyc │ │ ├── utils.py │ │ └── utils.pyc │ ├── bsn_clean_train_dataset_dpn92.sh │ ├── checkpoint │ │ ├── k600_dpn92_fold_2_200_pem_best.pth.tar │ │ ├── k600_dpn92_fold_2_200_tem_best.pth.tar │ │ ├── k600_dpn92_fold_2_200nonrescale_opts.json │ │ └── k600_dpn92_fold_2_200rescale_opts.json │ ├── data │ │ └── activitynet_annotations │ │ │ └── action_name.csv │ ├── dataset.py │ ├── eval.py │ ├── loss_function.py │ ├── main.py │ ├── models.py │ ├── opts.py │ ├── pgm.py │ └── post_processing.py ├── extract_anet_feature.py ├── models.py ├── ops │ ├── __init__.py │ ├── basic_ops.py │ └── utils.py ├── pretrain │ ├── __init__.py │ ├── dpn.py │ ├── inception_v4.py │ ├── inceptionresnetv2.py │ ├── include.py │ ├── resnet.py │ ├── resnet_ibn_a.py │ ├── resnet_ibn_a_old.py │ ├── resnet_ibn_b.py │ ├── resnext_ibn_a.py │ ├── se_module.py │ ├── se_resnet_ibn_a.py │ ├── senet.py │ └── xception.py ├── result_process.py ├── run.sh ├── transforms.py └── v_Vk-aKj0R65o.mp4 └── environment.yml /ActivityNet_task_1_summary.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/ActivityNet_task_1_summary.pdf -------------------------------------------------------------------------------- /BSN/Evaluation/data/activity_net_1_3_new_19934.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/BSN/Evaluation/data/activity_net_1_3_new_19934.json -------------------------------------------------------------------------------- /BSN/Evaluation/eval_proposal.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/BSN/Evaluation/eval_proposal.pyc -------------------------------------------------------------------------------- /BSN/Evaluation/utils.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/BSN/Evaluation/utils.pyc -------------------------------------------------------------------------------- /BSN/bsn_3fold_diff_backbone.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ### feature path "k600_resnet152_fold_0_rescale", "k600_resnet152_fold_0_nonrescale" 3 | #for backbone in 'k600_resnet152' 'k600_dpn92' 4 | # for backbone in 'se101' 5 | for backbone in 'cuhk' 6 | do 7 | # for fold in 0 1 2 8 | for fold in 2 9 | do 10 | arch="k600_${backbone}_fold_${fold}_norm" 11 | # feat_path="./data/activitynet_feature_cuhk/${backbone}_k600_3fold_feat/k600_${backbone}_fold_${fold}_rescale" 12 | feat_path="./data/activitynet_feature_cuhk/rescale_100/csv_mean_100" 13 | video_info="./data/activitynet_annotations/3fold_csv/fold_${fold}_video_info.csv" 14 | eval_json="./data/activitynet_annotations/3fold_csv/fold_${fold}_activity_net.v1-3.min.json" 15 | subopts="--feature_path ${feat_path} --video_info ${video_info} --arch ${arch} --fix_scale rescale" 16 | 17 | python main.py --module TEM --mode train ${subopts} 18 | 19 | python main.py --module TEM --mode inference ${subopts} 20 | 21 | python main.py --module PGM ${subopts} 22 | python main.py --module PEM --mode train ${subopts} 23 | 24 | python main.py --module PEM --mode inference --pem_batch_size 1 ${subopts} 25 | 26 | python main.py --module Post_processing ${subopts} 27 | 28 | python main.py --module Evaluation ${subopts} --eval_json ${eval_json} 29 | ##test 30 | python main.py --module PEM --mode inference --pem_batch_size 1 --pem_inference_subset testing ${subopts} 31 | python main.py --module Post_processing --pem_inference_subset testing ${subopts} 32 | 33 | # feat_path_nonrescale="./data/activitynet_feature_cuhk/${backbone}_k600_3fold_feat/k600_${backbone}_fold_${fold}_nonrescale" 34 | feat_path_nonrescale="./data/activitynet_feature_cuhk/non_rescale" 35 | subopts_nonrescale="--feature_path ${feat_path_nonrescale} --video_info ${video_info} --arch ${arch} --fix_scale nonrescale" 36 | ######### nonrescale #### 37 | python main.py --module TEM --mode inference --tem_batch_size 1 ${subopts_nonrescale} 38 | 39 | python main.py --module PGM ${subopts_nonrescale} 40 | 41 | python main.py --module PEM --mode inference --pem_batch_size 1 ${subopts_nonrescale} 42 | 43 | python main.py --module Post_processing ${subopts_nonrescale} 44 | 45 | python main.py --module Evaluation ${subopts_nonrescale} --eval_json ${eval_json} 46 | ###test 47 | python main.py --module PEM --mode inference --pem_batch_size 1 --pem_inference_subset testing ${subopts_nonrescale} 48 | python main.py --module Post_processing --pem_inference_subset testing ${subopts_nonrescale} 49 | done 50 | done -------------------------------------------------------------------------------- /BSN/check_videos.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import argparse 4 | import cv2 5 | from tqdm import tqdm 6 | 7 | 8 | if __name__ == '__main__': 9 | file_path = lambda path: os.path.abspath(os.path.expanduser(path)) 10 | 11 | parser = argparse.ArgumentParser() 12 | parser.add_argument('video_dir', type=file_path) 13 | parser.add_argument('json_file', type=file_path) 14 | args = parser.parse_args() 15 | 16 | with open(args.json_file) as f: 17 | database = json.load(f)['database'] 18 | 19 | for vid, annotations in tqdm(database.items()): 20 | fname = 'v_{}.mp4'.format(vid) 21 | duration = annotations['duration'] 22 | 23 | capture = cv2.VideoCapture(os.path.join(args.video_dir, fname)) 24 | fps = capture.get(cv2.CAP_PROP_FPS) 25 | count = capture.get(cv2.CAP_PROP_FRAME_COUNT) 26 | 27 | actual_duration = count / fps 28 | if duration - actual_duration > 3: 29 | tqdm.write('{}: actual_duration={:.2f}, duration={}'.format(fname, actual_duration, duration)) 30 | 31 | capture.release() 32 | 33 | -------------------------------------------------------------------------------- /BSN/data/activitynet_feature_cuhk/concat_feature.py: -------------------------------------------------------------------------------- 1 | import os 2 | import argparse 3 | import pandas as pd 4 | from tqdm import tqdm 5 | from multiprocessing import Pool 6 | 7 | 8 | def concat(csv_name): 9 | paths = [os.path.join(dpath, csv_name) for dpath in args.input_dirs] 10 | dfs = [pd.read_csv(path).ix[:, :200] for path in paths] 11 | seg = [0] 12 | for df in dfs: 13 | # seg.append(seg[-1] + df.shape[1]) 14 | seg.append(seg[-1] + 200) 15 | 16 | for i, df in enumerate(dfs): 17 | df.columns = ['f{}'.format(j) for j in range(seg[i], seg[i+1])] 18 | 19 | df_all = pd.concat(dfs, axis=1) 20 | df_all.to_csv(os.path.join(args.output_dir, csv_name), index=False) 21 | 22 | 23 | def file_path(path): 24 | return os.path.abspath(os.path.expanduser(path)) 25 | 26 | 27 | if __name__ == '__main__': 28 | parser = argparse.ArgumentParser() 29 | parser.add_argument('--input_dirs', '-i', nargs='+', required=True) 30 | parser.add_argument('--output_dir', '-o', required=True) 31 | parser.add_argument('--num_workers', '-j', type=int, default=64) 32 | args = parser.parse_args() 33 | 34 | if not os.path.exists(args.output_dir): 35 | os.mkdir(args.output_dir) 36 | 37 | csv_list = [fname for fname in os.listdir(args.input_dirs[0]) if fname.startswith('v_') and fname.endswith('.csv')] 38 | tqdm.write('total: {}'.format(len(csv_list))) 39 | 40 | pool = Pool(args.num_workers) 41 | with tqdm(total=len(csv_list)) as pbar: 42 | for _ in pool.imap_unordered(concat, csv_list): 43 | pbar.update() 44 | -------------------------------------------------------------------------------- /BSN/data/activitynet_feature_cuhk/fuse_feat_non_rescale.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import pandas as pd 4 | from tqdm import tqdm 5 | rgb_folder, flow_folder, fuse_folder = sys.argv[1:] 6 | if os.path.exists(fuse_folder) is False: 7 | os.mkdir(fuse_folder) 8 | name_list = os.listdir(rgb_folder) 9 | for name in tqdm(name_list): 10 | one_fuse_path = os.path.join(fuse_folder, name) 11 | if os.path.exists(one_fuse_path): 12 | continue 13 | one_rgb_path = os.path.join(rgb_folder, name) 14 | one_flow_path = os.path.join(flow_folder, name) 15 | rgb_feat = pd.read_csv(one_rgb_path) 16 | flow_feat = pd.read_csv(one_flow_path) 17 | fuse = pd.concat([rgb_feat, flow_feat], axis=1) 18 | #one_fuse_path = os.path.join(fuse_folder, name) 19 | fuse.to_csv(one_fuse_path, index=None) 20 | -------------------------------------------------------------------------------- /BSN/data/activitynet_feature_cuhk/fuse_feat_non_rescale_mp.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import pandas as pd 4 | from tqdm import tqdm 5 | import multiprocessing as mp 6 | 7 | rgb_folder, flow_folder, fuse_folder, num_works = sys.argv[1:] 8 | num_works = int(num_works) 9 | if os.path.exists(fuse_folder) is False: 10 | os.mkdir(fuse_folder) 11 | name_list = os.listdir(rgb_folder) 12 | 13 | def fuse_rgb_and_flow(video_list): 14 | for name in tqdm(video_list): 15 | one_fuse_path = os.path.join(fuse_folder, name) 16 | if os.path.exists(one_fuse_path): 17 | continue 18 | one_rgb_path = os.path.join(rgb_folder, name) 19 | one_flow_path = os.path.join(flow_folder, name) 20 | rgb_feat = pd.read_csv(one_rgb_path) 21 | flow_feat = pd.read_csv(one_flow_path) 22 | fuse = pd.concat([rgb_feat, flow_feat], axis=1) 23 | # one_fuse_path = os.path.join(fuse_folder, name) 24 | fuse.to_csv(one_fuse_path, index=None) 25 | 26 | num_names_per_thread = len(name_list) / num_works 27 | processes = [] 28 | 29 | for tid in range(int(num_works)): 30 | start = tid*num_names_per_thread 31 | end = min((tid+1)*num_names_per_thread, len(name_list)) 32 | tmp_name_list = name_list[start: end] 33 | p = mp.Process(target=fuse_rgb_and_flow, args=(tmp_name_list,)) 34 | p.start() 35 | processes.append(p) 36 | for p in processes: 37 | p.join() 38 | -------------------------------------------------------------------------------- /BSN/data/activitynet_feature_cuhk/ldb_process.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Mon May 15 22:31:31 2017 4 | 5 | @author: wzmsltw 6 | """ 7 | import caffe 8 | import leveldb 9 | import numpy as np 10 | from caffe.proto import caffe_pb2 11 | import pandas as pd 12 | 13 | col_names=[] 14 | for i in range(200): 15 | col_names.append("f"+str(i)) 16 | 17 | df=pd.read_table("./input_spatial_list.txt",names=['image','frame','label'],sep=" ") 18 | 19 | db = leveldb.LevelDB('./LDB') 20 | datum = caffe_pb2.Datum() 21 | 22 | i=0 23 | video_name="init" 24 | videoData=np.reshape([],[-1,200]) 25 | 26 | for key, value in db.RangeIter(): 27 | 28 | tmp_video_name=df.image.values[i].split('/')[-1] 29 | if tmp_video_name !=video_name: 30 | outDf=pd.DataFrame(videoData,columns=col_names) 31 | outDf.to_csv("./csv_raw/"+video_name+".csv",index=False) 32 | videoData=np.reshape([],[-1,200]) 33 | video_name=tmp_video_name 34 | i+=1 35 | 36 | datum.ParseFromString(value) 37 | label = datum.label 38 | data = caffe.io.datum_to_array(datum) 39 | data=np.reshape(data,[1,200]) 40 | videoData=np.concatenate((videoData,data)) 41 | 42 | del db 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ActivityNet_task_1 2 | This repository holds the codes for ActivityNet Challenge Task 1: Temporal Action Proposals 3 | # Related repositories: 4 | [Temporal Segment Networks][TSN] 5 | [TSN PyTorch][TSN_pytorch] 6 | [BSN-boundary-sensitive-network.pytorch][BSN] 7 | [anet2016 CUHK][CUHK_anet] 8 | 9 | # *Update 10 | DPN92 RGB+Flow nonrescale feature [Baidu_pan_passwd_x8ff][dpn92] 11 | # Usage Guide 12 | ## Setting 13 | ``` 14 | conda env create -f environment.yml 15 | ``` 16 | ## Data Preparation 17 | [Extract Frames and Optical Flow Images][Extract Frames and Optical Flow Images] 18 | ## TSN 19 | ### Training TSN 20 | RGB&Flow 21 | ```bash 22 | cd ./TSN && sh run.sh 23 | ``` 24 | ### Extracting video's feature 25 | RGB&Flow 26 | ```bash 27 | sh extract_feature.sh 28 | ``` 29 | ## BSN 30 | ### Rescaling RGB and Flow's features and concatenate them 31 | ```bash 32 | cd ./BSN 33 | python data_process.py arch ../TSN/RGB_feature_folder ../TSN/Flow_feature_folder num_works 34 | ``` 35 | ### Training, evaluating and testing BSN 36 | ```bash 37 | sh bsn_3fold_diff_backbone.sh 38 | ``` 39 | # Final result proposal 40 | ```bash 41 | ./BSN/output/result_proposal.json 42 | ``` 43 | # Ensemble 44 | ## Soft-NMS layer ensemble 45 | Naive greed search to find a combination. 46 | ```bash 47 | mv ./BSN/ensemble/* ./BSN 48 | # need to add 49 | ``` 50 | # Demo 51 | Put TSN RGB trained model in the folder ``./demo_activity`` 52 | Download: 53 | dpn92_RGB_k600_fold_2_rgb_model_best.pth.tar, [google_drive][google_drive] or [baidu_pan_passwd_38cw][baidu_pan] 54 | k600_dpn92_fold_0_flow_model_best.pth.tar: [google_drive][dpn92_flow_pretrained_model_google] or [baidu_pan_passwd_7k1j][dpn92_flow_pretrained_model_baidu] 55 | ```bash 56 | cd demo_activity && sh run.sh VIDEO_PATH 57 | ``` 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | [TSN]:https://github.com/yjxiong/temporal-segment-networks 68 | [TSN_pytorch]:https://github.com/yjxiong/tsn-pytorch 69 | [BSN]:https://github.com/wzmsltw/BSN-boundary-sensitive-network.pytorch#prerequisites 70 | [CUHK_anet]:https://github.com/yjxiong/anet2016-cuhk 71 | [Extract Frames and Optical Flow Images]:https://github.com/yjxiong/temporal-segment-networks#extract-frames-and-optical-flow-images 72 | [google_drive]:https://drive.google.com/open?id=1014wTFhfv5Cr0vH49x4L4JACtgS8AXw2 73 | [baidu_pan]:https://pan.baidu.com/s/1rDHf8g_uKC_qJReE1pDd2A 74 | [dpn92]:https://pan.baidu.com/s/1pJoAY2MwfHiDFXtuQmiWqA 75 | [dpn92_flow_pretrained_model_google]:https://drive.google.com/open?id=1wHXeek6QCxb5irOMoOI7Q2sdjTaQoe1M 76 | [dpn92_flow_pretrained_model_baidu]:https://pan.baidu.com/s/1MdBen2WwHoJ5jcW1mKr15Q 77 | -------------------------------------------------------------------------------- /TSN/extract_feature.sh: -------------------------------------------------------------------------------- 1 | for i in `seq 0 15` 2 | do 3 | CUDA_VISIBLE_DEVICES=$((i%4)) python extract_anet_feature.py ./lists/list.txt.new$i ./dpn92_rgb_model_best.pth.tar -m RGB --arch dpn92 -s nonrescale & 4 | done 5 | 6 | for i in `seq 0 15` 7 | do 8 | CUDA_VISIBLE_DEVICES=$((i%4)) python extract_anet_feature.py ./lists/list.txt.new$i ./dpn92_flow__flow_model_best.pth.tar -m Flow --arch dpn92 -s nonrescale & 9 | done 10 | -------------------------------------------------------------------------------- /TSN/lists_16/gen_list.py: -------------------------------------------------------------------------------- 1 | # coding:utf-8 2 | 3 | for i in range(16): 4 | with open("list.txt.{}".format(i), "r")as txt_f: 5 | data = txt_f.readlines() 6 | with open("list.txt.new{}".format(i), "w")as txt_f: 7 | for item in data: 8 | item = item.replace("datasets", "anet_flow") 9 | txt_f.write(item) 10 | -------------------------------------------------------------------------------- /TSN/ops/__init__.py: -------------------------------------------------------------------------------- 1 | from ops.basic_ops import * -------------------------------------------------------------------------------- /TSN/ops/__init__.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/ops/__init__.pyc -------------------------------------------------------------------------------- /TSN/ops/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/ops/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /TSN/ops/__pycache__/basic_ops.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/ops/__pycache__/basic_ops.cpython-36.pyc -------------------------------------------------------------------------------- /TSN/ops/basic_ops.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import math 3 | 4 | 5 | class Identity(torch.nn.Module): 6 | def forward(self, input): 7 | return input 8 | 9 | 10 | class SegmentConsensus(torch.autograd.Function): 11 | 12 | def __init__(self, consensus_type, dim=1): 13 | self.consensus_type = consensus_type 14 | self.dim = dim 15 | self.shape = None 16 | 17 | def forward(self, input_tensor): 18 | self.shape = input_tensor.size() 19 | if self.consensus_type == 'avg': 20 | output = input_tensor.mean(dim=self.dim, keepdim=True) 21 | elif self.consensus_type == 'identity': 22 | output = input_tensor 23 | else: 24 | output = None 25 | 26 | return output 27 | 28 | def backward(self, grad_output): 29 | if self.consensus_type == 'avg': 30 | grad_in = grad_output.expand(self.shape) / float(self.shape[self.dim]) 31 | elif self.consensus_type == 'identity': 32 | grad_in = grad_output 33 | else: 34 | grad_in = None 35 | 36 | return grad_in 37 | 38 | 39 | class ConsensusModule(torch.nn.Module): 40 | 41 | def __init__(self, consensus_type, dim=1): 42 | super(ConsensusModule, self).__init__() 43 | self.consensus_type = consensus_type if consensus_type != 'rnn' else 'identity' 44 | self.dim = dim 45 | 46 | def forward(self, input): 47 | return SegmentConsensus(self.consensus_type, self.dim)(input) 48 | -------------------------------------------------------------------------------- /TSN/ops/basic_ops.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/ops/basic_ops.pyc -------------------------------------------------------------------------------- /TSN/ops/utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import numpy as np 3 | from sklearn.metrics import confusion_matrix 4 | 5 | def get_grad_hook(name): 6 | def hook(m, grad_in, grad_out): 7 | print((name, grad_out[0].data.abs().mean(), grad_in[0].data.abs().mean())) 8 | print((grad_out[0].size())) 9 | print((grad_in[0].size())) 10 | 11 | print((grad_out[0])) 12 | print((grad_in[0])) 13 | 14 | return hook 15 | 16 | 17 | def softmax(scores): 18 | es = np.exp(scores - scores.max(axis=-1)[..., None]) 19 | return es / es.sum(axis=-1)[..., None] 20 | 21 | 22 | def log_add(log_a, log_b): 23 | return log_a + np.log(1 + np.exp(log_b - log_a)) 24 | 25 | 26 | def class_accuracy(prediction, label): 27 | cf = confusion_matrix(prediction, label) 28 | cls_cnt = cf.sum(axis=1) 29 | cls_hit = np.diag(cf) 30 | 31 | cls_acc = cls_hit / cls_cnt.astype(float) 32 | 33 | mean_cls_acc = cls_acc.mean() 34 | 35 | return cls_acc, mean_cls_acc -------------------------------------------------------------------------------- /TSN/pretrain/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/pretrain/__init__.py -------------------------------------------------------------------------------- /TSN/pretrain/include.py: -------------------------------------------------------------------------------- 1 | import os 2 | from datetime import datetime 3 | PROJECT_PATH = os.path.dirname(os.path.realpath(__file__)) 4 | IDENTIFIER = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') 5 | 6 | 7 | #numerical libs 8 | import math 9 | import numpy as np 10 | import random 11 | import PIL 12 | import cv2 13 | import matplotlib 14 | matplotlib.use('TkAgg') 15 | #matplotlib.use('WXAgg') 16 | #matplotlib.use('Qt4Agg') 17 | #matplotlib.use('Qt5Agg') #Qt4Agg 18 | print(matplotlib.get_backend()) 19 | #print(matplotlib.__version__) 20 | 21 | 22 | # torch libs 23 | import torch 24 | from torch.utils.data.dataset import Dataset 25 | from torch.utils.data import DataLoader 26 | from torch.utils.data.sampler import * 27 | 28 | import torch.nn as nn 29 | import torch.nn.functional as F 30 | import torch.optim as optim 31 | from torch.nn.parallel.data_parallel import data_parallel 32 | 33 | 34 | # std libs 35 | import collections 36 | import copy 37 | import numbers 38 | import inspect 39 | import shutil 40 | from timeit import default_timer as timer 41 | import itertools 42 | from collections import OrderedDict 43 | 44 | import csv 45 | import pandas as pd 46 | import pickle 47 | import glob 48 | import sys 49 | from distutils.dir_util import copy_tree 50 | import time 51 | 52 | import matplotlib.pyplot as plt 53 | from mpl_toolkits.mplot3d import Axes3D 54 | 55 | from skimage.transform import resize as skimage_resize 56 | 57 | 58 | 59 | 60 | # constant # 61 | PI = np.pi 62 | INF = np.inf 63 | EPS = 1e-12 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /TSN/pretrain/se_module.py: -------------------------------------------------------------------------------- 1 | from torch import nn 2 | 3 | 4 | class SELayer(nn.Module): 5 | def __init__(self, channel, reduction=16): 6 | super(SELayer, self).__init__() 7 | self.avg_pool = nn.AdaptiveAvgPool2d(1) 8 | self.fc = nn.Sequential( 9 | nn.Linear(channel, int(channel/reduction), bias=False), 10 | nn.ReLU(inplace=True), 11 | nn.Linear(int(channel/reduction), channel, bias=False), 12 | nn.Sigmoid() 13 | ) 14 | 15 | def forward(self, x): 16 | b, c, _, _ = x.size() 17 | y = self.avg_pool(x).view(b, c) 18 | y = self.fc(y).view(b, c, 1, 1) 19 | return x * y.expand_as(x) 20 | -------------------------------------------------------------------------------- /TSN/run.sh: -------------------------------------------------------------------------------- 1 | # RGB 2 | CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python main.py activitynet RGB train_list.txt val_list.txt -j 48 -b 80 --arch dpn92 --output_dir ./logs/20190513_dpn92_RGB/ --snapshot_pref dpn92_RGB 3 | 4 | # Flow 5 | CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python main.py activitynet Flow train_list.txt val_list.txt -j 48 -b 80 --arch dpn92 --dropout 0.7 --lr_steps 190 300 --epochs 340 --gd 20 --snapshot_pref dpn92_flow 6 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 LIP6 Lab 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | 22 | ------------------------------------------------- 23 | 24 | This product contains portions of third party software provided under this license: 25 | 26 | dump_filters.py (x) 27 | =============== 28 | 29 | Copyright 2015 Google Inc. All Rights Reserved. 30 | 31 | Licensed under the Apache License, Version 2.0 (the "License"); 32 | you may not use this file except in compliance with the License. 33 | You may obtain a copy of the License at 34 | 35 | http://www.apache.org/licenses/LICENSE-2.0 36 | 37 | Unless required by applicable law or agreed to in writing, software 38 | distributed under the License is distributed on an "AS IS" BASIS, 39 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 40 | See the License for the specific language governing permissions and 41 | limitations under the License. 42 | 43 | 44 | (x) adapted from https://github.com/tensorflow/tensorflow/blob/411f57e/tensorflow/models/image/imagenet/classify_image.py 45 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/README.md: -------------------------------------------------------------------------------- 1 | # Tensorflow Model Zoo for Torch7 and PyTorch 2 | 3 | This is a porting of tensorflow pretrained models made by [Remi Cadene](http://remicadene.com) and [Micael Carvalho](http://micaelcarvalho.com). Special thanks to Moustapha Cissé. All models have been tested on Imagenet. 4 | 5 | This work was inspired by [inception-v3.torch](https://github.com/Moodstocks/inception-v3.torch). 6 | 7 | 8 | ## Using pretrained models 9 | 10 | ### Torch7 11 | 12 | #### Requirements 13 | 14 | Please install [torchnet-vision](https://github.com/Cadene/torchnet-vision). 15 | ``` 16 | luarocks install --server=http://luarocks.org/dev torchnet-vision 17 | ``` 18 | 19 | Models available: 20 | 21 | - inceptionv3 22 | - inceptionv4 23 | - inceptionresnetv2 24 | - resnet{18, 34, 50, 101, 152, 200} 25 | - overfeat 26 | - vggm 27 | - vgg16 28 | 29 | #### Simple example 30 | 31 | ```lua 32 | require 'image' 33 | tnt = require 'torchnet' 34 | vision = require 'torchnet-vision' 35 | model = vision.models.inceptionresnetv2 36 | net = model.load() 37 | 38 | augmentation = tnt.transform.compose{ 39 | vision.image.transformimage.randomScale{ 40 | minSize = 299, maxSize = 350 41 | }, 42 | vision.image.transformimage.randomCrop(299), 43 | vision.image.transformimage.colorNormalize{ 44 | mean = model.mean, std = model.std 45 | }, 46 | function(img) return img:float() end 47 | } 48 | 49 | net:evaluate() 50 | output = net:forward(augmentation(image.lena())) 51 | ``` 52 | 53 | ### PyTorch 54 | 55 | Currently available in this repo only On pytorch/vision maybe! 56 | 57 | Models available: 58 | 59 | - inceptionv4 60 | - inceptionresnetv2 61 | 62 | #### Simple example 63 | 64 | ```python 65 | import torch 66 | from inceptionv4.pytorch_load import inceptionv4 67 | net = inceptionv4() 68 | input = torch.autograd.Variable(torch.ones(1,3,299,299)) 69 | output = net.forward(input) 70 | ``` 71 | 72 | 73 | ## Reproducing the porting 74 | 75 | ### Requirements 76 | 77 | - Tensorflow 78 | - Torch7 79 | - PyTorch 80 | - hdf5 for python3 81 | - hdf5 for lua 82 | 83 | ### Example of commands 84 | 85 | In Tensorflow: Download tensorflow parameters and extract them in `./dump` directory. 86 | ``` 87 | python3 inceptionv4/tensorflow_dump.py 88 | ``` 89 | 90 | In Torch7 or PyTorch: Create the network, load the parameters, launch few tests and save the network in `./save` directory. 91 | ``` 92 | th inceptionv4/torch_load.lua 93 | python3 inceptionv4/pytorch_load.py 94 | ``` 95 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/__init__.py: -------------------------------------------------------------------------------- 1 | from .inceptionresnetv2.pytorch_load import inceptionresnetv2 2 | from .inceptionv4.pytorch_load import inceptionv4 3 | from .bninception.pytorch_load import BNInception, InceptionV3 4 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/bninception/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/bninception/__init__.py -------------------------------------------------------------------------------- /TSN/tf_model_zoo/inceptionresnetv2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/inceptionresnetv2/__init__.py -------------------------------------------------------------------------------- /TSN/tf_model_zoo/inceptionv4/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/inceptionv4/__init__.py -------------------------------------------------------------------------------- /TSN/tf_model_zoo/lena_224.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/lena_224.png -------------------------------------------------------------------------------- /TSN/tf_model_zoo/lena_299.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/lena_299.png -------------------------------------------------------------------------------- /TSN/tf_model_zoo/lena_origin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/lena_origin.png -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as: 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | Google Inc. 10 | David Dao 11 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing guidelines 2 | 3 | If you have created a model and would like to publish it here, please send us a 4 | pull request. For those just getting started with pull reuests, GitHub has a 5 | [howto](https://help.github.com/articles/using-pull-requests/). 6 | 7 | The code for any model in this repository is licensed under the Apache License 8 | 2.0. 9 | 10 | In order to accept our code, we have to make sure that we can publish your code: 11 | You have to sign a Contributor License Agreement (CLA). 12 | 13 | ### Contributor License Agreements 14 | 15 | Please fill out either the individual or corporate Contributor License Agreement (CLA). 16 | 17 | * If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an [individual CLA](http://code.google.com/legal/individual-cla-v1.0.html). 18 | * If you work for a company that wants to allow you to contribute your work, then you'll need to sign a [corporate CLA](http://code.google.com/legal/corporate-cla-v1.0.html). 19 | 20 | Follow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll be able to accept your pull requests. 21 | 22 | ***NOTE***: Only original source code from you and other people that have signed the CLA can be accepted into the repository. 23 | 24 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/README.md: -------------------------------------------------------------------------------- 1 | # TensorFlow Models 2 | 3 | This repository contains machine learning models implemented in 4 | [TensorFlow](https://tensorflow.org). The models are maintained by their 5 | respective authors. 6 | 7 | To propose a model for inclusion please submit a pull request. 8 | 9 | 10 | ## Models 11 | - [autoencoder](autoencoder) -- various autoencoders 12 | - [inception](inception) -- deep convolutional networks for computer vision 13 | - [namignizer](namignizer) -- recognize and generate names 14 | - [neural_gpu](neural_gpu) -- highly parallel neural computer 15 | - [privacy](privacy) -- privacy-preserving student models from multiple teachers 16 | - [resnet](resnet) -- deep and wide residual networks 17 | - [slim](slim) -- image classification models in TF-Slim 18 | - [swivel](swivel) -- the Swivel algorithm for generating word embeddings 19 | - [syntaxnet](syntaxnet) -- neural models of natural language syntax 20 | - [textsum](textsum) -- sequence-to-sequence with attention model for text summarization. 21 | - [transformer](transformer) -- spatial transformer network, which allows the spatial manipulation of data within the network 22 | - [im2txt](im2txt) -- image-to-text neural network for image captioning. 23 | - [neural_programmer](neural programmer) -- neural network augmented with logic and mathematic operations. 24 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/WORKSPACE: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/WORKSPACE -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/autoencoder/AdditiveGaussianNoiseAutoencoderRunner.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | import sklearn.preprocessing as prep 4 | import tensorflow as tf 5 | from tensorflow.examples.tutorials.mnist import input_data 6 | 7 | from autoencoder.autoencoder_models.DenoisingAutoencoder import AdditiveGaussianNoiseAutoencoder 8 | 9 | mnist = input_data.read_data_sets('MNIST_data', one_hot = True) 10 | 11 | def standard_scale(X_train, X_test): 12 | preprocessor = prep.StandardScaler().fit(X_train) 13 | X_train = preprocessor.transform(X_train) 14 | X_test = preprocessor.transform(X_test) 15 | return X_train, X_test 16 | 17 | def get_random_block_from_data(data, batch_size): 18 | start_index = np.random.randint(0, len(data) - batch_size) 19 | return data[start_index:(start_index + batch_size)] 20 | 21 | X_train, X_test = standard_scale(mnist.train.images, mnist.test.images) 22 | 23 | n_samples = int(mnist.train.num_examples) 24 | training_epochs = 20 25 | batch_size = 128 26 | display_step = 1 27 | 28 | autoencoder = AdditiveGaussianNoiseAutoencoder(n_input = 784, 29 | n_hidden = 200, 30 | transfer_function = tf.nn.softplus, 31 | optimizer = tf.train.AdamOptimizer(learning_rate = 0.001), 32 | scale = 0.01) 33 | 34 | for epoch in range(training_epochs): 35 | avg_cost = 0. 36 | total_batch = int(n_samples / batch_size) 37 | # Loop over all batches 38 | for i in range(total_batch): 39 | batch_xs = get_random_block_from_data(X_train, batch_size) 40 | 41 | # Fit training using batch data 42 | cost = autoencoder.partial_fit(batch_xs) 43 | # Compute average loss 44 | avg_cost += cost / n_samples * batch_size 45 | 46 | # Display logs per epoch step 47 | if epoch % display_step == 0: 48 | print "Epoch:", '%04d' % (epoch + 1), \ 49 | "cost=", "{:.9f}".format(avg_cost) 50 | 51 | print "Total cost: " + str(autoencoder.calc_total_cost(X_test)) 52 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/autoencoder/AutoencoderRunner.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | import sklearn.preprocessing as prep 4 | import tensorflow as tf 5 | from tensorflow.examples.tutorials.mnist import input_data 6 | 7 | from autoencoder.autoencoder_models.Autoencoder import Autoencoder 8 | 9 | mnist = input_data.read_data_sets('MNIST_data', one_hot = True) 10 | 11 | def standard_scale(X_train, X_test): 12 | preprocessor = prep.StandardScaler().fit(X_train) 13 | X_train = preprocessor.transform(X_train) 14 | X_test = preprocessor.transform(X_test) 15 | return X_train, X_test 16 | 17 | def get_random_block_from_data(data, batch_size): 18 | start_index = np.random.randint(0, len(data) - batch_size) 19 | return data[start_index:(start_index + batch_size)] 20 | 21 | X_train, X_test = standard_scale(mnist.train.images, mnist.test.images) 22 | 23 | n_samples = int(mnist.train.num_examples) 24 | training_epochs = 20 25 | batch_size = 128 26 | display_step = 1 27 | 28 | autoencoder = Autoencoder(n_input = 784, 29 | n_hidden = 200, 30 | transfer_function = tf.nn.softplus, 31 | optimizer = tf.train.AdamOptimizer(learning_rate = 0.001)) 32 | 33 | for epoch in range(training_epochs): 34 | avg_cost = 0. 35 | total_batch = int(n_samples / batch_size) 36 | # Loop over all batches 37 | for i in range(total_batch): 38 | batch_xs = get_random_block_from_data(X_train, batch_size) 39 | 40 | # Fit training using batch data 41 | cost = autoencoder.partial_fit(batch_xs) 42 | # Compute average loss 43 | avg_cost += cost / n_samples * batch_size 44 | 45 | # Display logs per epoch step 46 | if epoch % display_step == 0: 47 | print "Epoch:", '%04d' % (epoch + 1), \ 48 | "cost=", "{:.9f}".format(avg_cost) 49 | 50 | print "Total cost: " + str(autoencoder.calc_total_cost(X_test)) 51 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/autoencoder/MaskingNoiseAutoencoderRunner.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | import sklearn.preprocessing as prep 4 | import tensorflow as tf 5 | from tensorflow.examples.tutorials.mnist import input_data 6 | 7 | from autoencoder.autoencoder_models.DenoisingAutoencoder import MaskingNoiseAutoencoder 8 | 9 | mnist = input_data.read_data_sets('MNIST_data', one_hot = True) 10 | 11 | def standard_scale(X_train, X_test): 12 | preprocessor = prep.StandardScaler().fit(X_train) 13 | X_train = preprocessor.transform(X_train) 14 | X_test = preprocessor.transform(X_test) 15 | return X_train, X_test 16 | 17 | def get_random_block_from_data(data, batch_size): 18 | start_index = np.random.randint(0, len(data) - batch_size) 19 | return data[start_index:(start_index + batch_size)] 20 | 21 | X_train, X_test = standard_scale(mnist.train.images, mnist.test.images) 22 | 23 | 24 | n_samples = int(mnist.train.num_examples) 25 | training_epochs = 100 26 | batch_size = 128 27 | display_step = 1 28 | 29 | autoencoder = MaskingNoiseAutoencoder(n_input = 784, 30 | n_hidden = 200, 31 | transfer_function = tf.nn.softplus, 32 | optimizer = tf.train.AdamOptimizer(learning_rate = 0.001), 33 | dropout_probability = 0.95) 34 | 35 | for epoch in range(training_epochs): 36 | avg_cost = 0. 37 | total_batch = int(n_samples / batch_size) 38 | for i in range(total_batch): 39 | batch_xs = get_random_block_from_data(X_train, batch_size) 40 | 41 | cost = autoencoder.partial_fit(batch_xs) 42 | 43 | avg_cost += cost / n_samples * batch_size 44 | 45 | if epoch % display_step == 0: 46 | print "Epoch:", '%04d' % (epoch + 1), \ 47 | "cost=", "{:.9f}".format(avg_cost) 48 | 49 | print "Total cost: " + str(autoencoder.calc_total_cost(X_test)) 50 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/autoencoder/Utils.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import tensorflow as tf 3 | 4 | def xavier_init(fan_in, fan_out, constant = 1): 5 | low = -constant * np.sqrt(6.0 / (fan_in + fan_out)) 6 | high = constant * np.sqrt(6.0 / (fan_in + fan_out)) 7 | return tf.random_uniform((fan_in, fan_out), 8 | minval = low, maxval = high, 9 | dtype = tf.float32) 10 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/autoencoder/VariationalAutoencoderRunner.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | import sklearn.preprocessing as prep 4 | import tensorflow as tf 5 | from tensorflow.examples.tutorials.mnist import input_data 6 | 7 | from autoencoder.autoencoder_models.VariationalAutoencoder import VariationalAutoencoder 8 | 9 | mnist = input_data.read_data_sets('MNIST_data', one_hot = True) 10 | 11 | 12 | 13 | def min_max_scale(X_train, X_test): 14 | preprocessor = prep.MinMaxScaler().fit(X_train) 15 | X_train = preprocessor.transform(X_train) 16 | X_test = preprocessor.transform(X_test) 17 | return X_train, X_test 18 | 19 | 20 | def get_random_block_from_data(data, batch_size): 21 | start_index = np.random.randint(0, len(data) - batch_size) 22 | return data[start_index:(start_index + batch_size)] 23 | 24 | 25 | X_train, X_test = min_max_scale(mnist.train.images, mnist.test.images) 26 | 27 | n_samples = int(mnist.train.num_examples) 28 | training_epochs = 20 29 | batch_size = 128 30 | display_step = 1 31 | 32 | autoencoder = VariationalAutoencoder(n_input = 784, 33 | n_hidden = 200, 34 | optimizer = tf.train.AdamOptimizer(learning_rate = 0.001)) 35 | 36 | for epoch in range(training_epochs): 37 | avg_cost = 0. 38 | total_batch = int(n_samples / batch_size) 39 | # Loop over all batches 40 | for i in range(total_batch): 41 | batch_xs = get_random_block_from_data(X_train, batch_size) 42 | 43 | # Fit training using batch data 44 | cost = autoencoder.partial_fit(batch_xs) 45 | # Compute average loss 46 | avg_cost += cost / n_samples * batch_size 47 | 48 | # Display logs per epoch step 49 | if epoch % display_step == 0: 50 | print "Epoch:", '%04d' % (epoch + 1), \ 51 | "cost=", "{:.9f}".format(avg_cost) 52 | 53 | print "Total cost: " + str(autoencoder.calc_total_cost(X_test)) 54 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/autoencoder/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/autoencoder/__init__.py -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/autoencoder/autoencoder_models/Autoencoder.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | import autoencoder.Utils 4 | 5 | class Autoencoder(object): 6 | 7 | def __init__(self, n_input, n_hidden, transfer_function=tf.nn.softplus, optimizer = tf.train.AdamOptimizer()): 8 | self.n_input = n_input 9 | self.n_hidden = n_hidden 10 | self.transfer = transfer_function 11 | 12 | network_weights = self._initialize_weights() 13 | self.weights = network_weights 14 | 15 | # model 16 | self.x = tf.placeholder(tf.float32, [None, self.n_input]) 17 | self.hidden = self.transfer(tf.add(tf.matmul(self.x, self.weights['w1']), self.weights['b1'])) 18 | self.reconstruction = tf.add(tf.matmul(self.hidden, self.weights['w2']), self.weights['b2']) 19 | 20 | # cost 21 | self.cost = 0.5 * tf.reduce_sum(tf.pow(tf.sub(self.reconstruction, self.x), 2.0)) 22 | self.optimizer = optimizer.minimize(self.cost) 23 | 24 | init = tf.initialize_all_variables() 25 | self.sess = tf.Session() 26 | self.sess.run(init) 27 | 28 | 29 | def _initialize_weights(self): 30 | all_weights = dict() 31 | all_weights['w1'] = tf.Variable(autoencoder.Utils.xavier_init(self.n_input, self.n_hidden)) 32 | all_weights['b1'] = tf.Variable(tf.zeros([self.n_hidden], dtype=tf.float32)) 33 | all_weights['w2'] = tf.Variable(tf.zeros([self.n_hidden, self.n_input], dtype=tf.float32)) 34 | all_weights['b2'] = tf.Variable(tf.zeros([self.n_input], dtype=tf.float32)) 35 | return all_weights 36 | 37 | def partial_fit(self, X): 38 | cost, opt = self.sess.run((self.cost, self.optimizer), feed_dict={self.x: X}) 39 | return cost 40 | 41 | def calc_total_cost(self, X): 42 | return self.sess.run(self.cost, feed_dict = {self.x: X}) 43 | 44 | def transform(self, X): 45 | return self.sess.run(self.hidden, feed_dict={self.x: X}) 46 | 47 | def generate(self, hidden = None): 48 | if hidden is None: 49 | hidden = np.random.normal(size=self.weights["b1"]) 50 | return self.sess.run(self.reconstruction, feed_dict={self.hidden: hidden}) 51 | 52 | def reconstruct(self, X): 53 | return self.sess.run(self.reconstruction, feed_dict={self.x: X}) 54 | 55 | def getWeights(self): 56 | return self.sess.run(self.weights['w1']) 57 | 58 | def getBiases(self): 59 | return self.sess.run(self.weights['b1']) 60 | 61 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/autoencoder/autoencoder_models/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/autoencoder/autoencoder_models/__init__.py -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/compression/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/compression/example.png -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/README.md: -------------------------------------------------------------------------------- 1 | Deep Learning with Differential Privacy 2 | 3 | Open Sourced By: Xin Pan (xpan@google.com, github: panyx0718) 4 | 5 | 6 | ###Introduction for dp_sgd/README.md 7 | 8 | Machine learning techniques based on neural networks are achieving remarkable 9 | results in a wide variety of domains. Often, the training of models requires 10 | large, representative datasets, which may be crowdsourced and contain sensitive 11 | information. The models should not expose private information in these datasets. 12 | Addressing this goal, we develop new algorithmic techniques for learning and a 13 | refined analysis of privacy costs within the framework of differential privacy. 14 | Our implementation and experiments demonstrate that we can train deep neural 15 | networks with non-convex objectives, under a modest privacy budget, and at a 16 | manageable cost in software complexity, training efficiency, and model quality. 17 | 18 | paper: https://arxiv.org/abs/1607.00133 19 | 20 | 21 | ###Introduction for multiple_teachers/README.md 22 | 23 | This repository contains code to create a setup for learning privacy-preserving 24 | student models by transferring knowledge from an ensemble of teachers trained 25 | on disjoint subsets of the data for which privacy guarantees are to be provided. 26 | 27 | Knowledge acquired by teachers is transferred to the student in a differentially 28 | private manner by noisily aggregating the teacher decisions before feeding them 29 | to the student during training. 30 | 31 | paper: https://arxiv.org/abs/1610.05755 32 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/differential_privacy/__init__.py -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/dp_sgd/dp_mnist/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = [":internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | package_group( 8 | name = "internal", 9 | packages = [ 10 | "//differential_privacy/...", 11 | ], 12 | ) 13 | 14 | py_binary( 15 | name = "dp_mnist", 16 | srcs = [ 17 | "dp_mnist.py", 18 | ], 19 | deps = [ 20 | "//differential_privacy/dp_sgd/dp_optimizer", 21 | "//differential_privacy/dp_sgd/dp_optimizer:dp_pca", 22 | "//differential_privacy/dp_sgd/dp_optimizer:utils", 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/dp_sgd/dp_optimizer/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = [":internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | package_group( 8 | name = "internal", 9 | packages = [ 10 | "//differential_privacy/...", 11 | ], 12 | ) 13 | 14 | py_library( 15 | name = "utils", 16 | srcs = [ 17 | "utils.py", 18 | ], 19 | deps = [ 20 | ], 21 | ) 22 | 23 | py_library( 24 | name = "dp_pca", 25 | srcs = [ 26 | "dp_pca.py", 27 | ], 28 | deps = [ 29 | ], 30 | ) 31 | 32 | py_library( 33 | name = "dp_optimizer", 34 | srcs = [ 35 | "dp_optimizer.py", 36 | "sanitizer.py", 37 | ], 38 | deps = [ 39 | ":utils", 40 | "//differential_privacy/dp_sgd/per_example_gradients", 41 | "//differential_privacy/privacy_accountant/tf:accountant", 42 | ], 43 | ) 44 | 45 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/dp_sgd/per_example_gradients/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = [":internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | package_group( 8 | name = "internal", 9 | packages = [ 10 | "//differential_privacy/...", 11 | ], 12 | ) 13 | 14 | py_library( 15 | name = "per_example_gradients", 16 | srcs = [ 17 | "per_example_gradients.py", 18 | ], 19 | deps = [ 20 | ], 21 | ) 22 | 23 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/multiple_teachers/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = [":internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | package_group( 8 | name = "internal", 9 | packages = [ 10 | "//differential_privacy/...", 11 | ], 12 | ) 13 | 14 | py_library( 15 | name = "aggregation", 16 | srcs = [ 17 | "aggregation.py", 18 | ], 19 | deps = [ 20 | ], 21 | ) 22 | 23 | py_library( 24 | name = "deep_cnn", 25 | srcs = [ 26 | "deep_cnn.py", 27 | ], 28 | deps = [ 29 | ":utils", 30 | ], 31 | ) 32 | 33 | py_library( 34 | name = "input", 35 | srcs = [ 36 | "input.py", 37 | ], 38 | deps = [ 39 | ], 40 | ) 41 | 42 | py_library( 43 | name = "metrics", 44 | srcs = [ 45 | "metrics.py", 46 | ], 47 | deps = [ 48 | ], 49 | ) 50 | 51 | py_library( 52 | name = "utils", 53 | srcs = [ 54 | "utils.py", 55 | ], 56 | deps = [ 57 | ], 58 | ) 59 | 60 | py_binary( 61 | name = "train_student", 62 | srcs = [ 63 | "train_student.py", 64 | ], 65 | deps = [ 66 | ":aggregation", 67 | ":deep_cnn", 68 | ":input", 69 | ":metrics", 70 | ], 71 | ) 72 | 73 | py_binary( 74 | name = "train_teachers", 75 | srcs = [ 76 | "train_teachers.py", 77 | ":deep_cnn", 78 | ":input", 79 | ":metrics", 80 | ], 81 | deps = [ 82 | ], 83 | ) 84 | 85 | py_library( 86 | name = "analysis", 87 | srcs = [ 88 | "analysis.py", 89 | ], 90 | deps = [ 91 | "//differential_privacy/multiple_teachers:input", 92 | ], 93 | ) 94 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/multiple_teachers/metrics.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 | 16 | from __future__ import absolute_import 17 | from __future__ import division 18 | from __future__ import print_function 19 | 20 | import numpy as np 21 | 22 | 23 | def accuracy(logits, labels): 24 | """ 25 | Return accuracy of the array of logits (or label predictions) wrt the labels 26 | :param logits: this can either be logits, probabilities, or a single label 27 | :param labels: the correct labels to match against 28 | :return: the accuracy as a float 29 | """ 30 | assert len(logits) == len(labels) 31 | 32 | if len(np.shape(logits)) > 1: 33 | # Predicted labels are the argmax over axis 1 34 | predicted_labels = np.argmax(logits, axis=1) 35 | else: 36 | # Input was already labels 37 | assert len(np.shape(logits)) == 1 38 | predicted_labels = logits 39 | 40 | # Check against correct labels to compute correct guesses 41 | correct = np.sum(predicted_labels == labels.reshape(len(labels))) 42 | 43 | # Divide by number of labels to obtain accuracy 44 | accuracy = float(correct) / len(labels) 45 | 46 | # Return float value 47 | return accuracy 48 | 49 | 50 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/multiple_teachers/train_student_mnist_250_lap_20_count_50_epochs_600.sh: -------------------------------------------------------------------------------- 1 | # Be sure to clone https://github.com/openai/improved-gan 2 | # and add improved-gan/mnist_svhn_cifar10 to your PATH variable 3 | 4 | # Download labels used to train the student 5 | wget https://github.com/npapernot/multiple-teachers-for-privacy/blob/master/mnist_250_student_labels_lap_20.npy 6 | 7 | # Train the student using improved-gan 8 | THEANO_FLAGS='floatX=float32,device=gpu,lib.cnmem=1' train_mnist_fm_custom_labels.py --labels mnist_250_student_labels_lap_20.npy --count 50 --epochs 600 9 | 10 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/multiple_teachers/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 | 16 | 17 | def batch_indices(batch_nb, data_length, batch_size): 18 | """ 19 | This helper function computes a batch start and end index 20 | :param batch_nb: the batch number 21 | :param data_length: the total length of the data being parsed by batches 22 | :param batch_size: the number of inputs in each batch 23 | :return: pair of (start, end) indices 24 | """ 25 | # Batch start and end index 26 | start = int(batch_nb * batch_size) 27 | end = int((batch_nb + 1) * batch_size) 28 | 29 | # When there are not enough inputs left, we reuse some to complete the batch 30 | if end > data_length: 31 | shift = end - data_length 32 | start -= shift 33 | end -= shift 34 | 35 | return start, end 36 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/privacy_accountant/python/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = [":internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | package_group( 8 | name = "internal", 9 | packages = [ 10 | "//third_party/tensorflow_models/...", 11 | ], 12 | ) 13 | 14 | py_binary( 15 | name = "gaussian_moments", 16 | srcs = [ 17 | "gaussian_moments.py", 18 | ], 19 | deps = [ 20 | ], 21 | ) 22 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/differential_privacy/privacy_accountant/tf/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = [":internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | package_group( 8 | name = "internal", 9 | packages = [ 10 | "//differential_privacy/...", 11 | ], 12 | ) 13 | 14 | py_library( 15 | name = "accountant", 16 | srcs = [ 17 | "accountant.py", 18 | ], 19 | deps = [ 20 | "//differential_privacy/dp_sgd/dp_optimizer:utils", 21 | ], 22 | ) 23 | 24 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/im2txt/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "im2txt") 2 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/im2txt/g3doc/COCO_val2014_000000224477.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/im2txt/g3doc/COCO_val2014_000000224477.jpg -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/im2txt/g3doc/example_captions.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/im2txt/g3doc/example_captions.jpg -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/im2txt/g3doc/show_and_tell_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/im2txt/g3doc/show_and_tell_architecture.png -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/im2txt/im2txt/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = [":internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | package_group( 8 | name = "internal", 9 | packages = [ 10 | "//im2txt/...", 11 | ], 12 | ) 13 | 14 | py_binary( 15 | name = "build_mscoco_data", 16 | srcs = [ 17 | "data/build_mscoco_data.py", 18 | ], 19 | ) 20 | 21 | sh_binary( 22 | name = "download_and_preprocess_mscoco", 23 | srcs = ["data/download_and_preprocess_mscoco.sh"], 24 | data = [ 25 | ":build_mscoco_data", 26 | ], 27 | ) 28 | 29 | py_library( 30 | name = "configuration", 31 | srcs = ["configuration.py"], 32 | srcs_version = "PY2AND3", 33 | ) 34 | 35 | py_library( 36 | name = "show_and_tell_model", 37 | srcs = ["show_and_tell_model.py"], 38 | srcs_version = "PY2AND3", 39 | deps = [ 40 | "//im2txt/ops:image_embedding", 41 | "//im2txt/ops:image_processing", 42 | "//im2txt/ops:inputs", 43 | ], 44 | ) 45 | 46 | py_test( 47 | name = "show_and_tell_model_test", 48 | size = "large", 49 | srcs = ["show_and_tell_model_test.py"], 50 | deps = [ 51 | ":configuration", 52 | ":show_and_tell_model", 53 | ], 54 | ) 55 | 56 | py_library( 57 | name = "inference_wrapper", 58 | srcs = ["inference_wrapper.py"], 59 | srcs_version = "PY2AND3", 60 | deps = [ 61 | ":show_and_tell_model", 62 | "//im2txt/inference_utils:inference_wrapper_base", 63 | ], 64 | ) 65 | 66 | py_binary( 67 | name = "train", 68 | srcs = ["train.py"], 69 | srcs_version = "PY2AND3", 70 | deps = [ 71 | ":configuration", 72 | ":show_and_tell_model", 73 | ], 74 | ) 75 | 76 | py_binary( 77 | name = "evaluate", 78 | srcs = ["evaluate.py"], 79 | srcs_version = "PY2AND3", 80 | deps = [ 81 | ":configuration", 82 | ":show_and_tell_model", 83 | ], 84 | ) 85 | 86 | py_binary( 87 | name = "run_inference", 88 | srcs = ["run_inference.py"], 89 | srcs_version = "PY2AND3", 90 | deps = [ 91 | ":configuration", 92 | ":inference_wrapper", 93 | "//im2txt/inference_utils:caption_generator", 94 | "//im2txt/inference_utils:vocabulary", 95 | ], 96 | ) 97 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/im2txt/im2txt/inference_utils/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//im2txt:internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | py_library( 8 | name = "inference_wrapper_base", 9 | srcs = ["inference_wrapper_base.py"], 10 | srcs_version = "PY2AND3", 11 | ) 12 | 13 | py_library( 14 | name = "vocabulary", 15 | srcs = ["vocabulary.py"], 16 | srcs_version = "PY2AND3", 17 | ) 18 | 19 | py_library( 20 | name = "caption_generator", 21 | srcs = ["caption_generator.py"], 22 | srcs_version = "PY2AND3", 23 | ) 24 | 25 | py_test( 26 | name = "caption_generator_test", 27 | srcs = ["caption_generator_test.py"], 28 | deps = [ 29 | ":caption_generator", 30 | ], 31 | ) 32 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/im2txt/im2txt/inference_wrapper.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 | 16 | """Model wrapper class for performing inference with a ShowAndTellModel.""" 17 | 18 | from __future__ import absolute_import 19 | from __future__ import division 20 | from __future__ import print_function 21 | 22 | 23 | 24 | from im2txt import show_and_tell_model 25 | from im2txt.inference_utils import inference_wrapper_base 26 | 27 | 28 | class InferenceWrapper(inference_wrapper_base.InferenceWrapperBase): 29 | """Model wrapper class for performing inference with a ShowAndTellModel.""" 30 | 31 | def __init__(self): 32 | super(InferenceWrapper, self).__init__() 33 | 34 | def build_model(self, model_config): 35 | model = show_and_tell_model.ShowAndTellModel(model_config, mode="inference") 36 | model.build() 37 | return model 38 | 39 | def feed_image(self, sess, encoded_image): 40 | initial_state = sess.run(fetches="lstm/initial_state:0", 41 | feed_dict={"image_feed:0": encoded_image}) 42 | return initial_state 43 | 44 | def inference_step(self, sess, input_feed, state_feed): 45 | softmax_output, state_output = sess.run( 46 | fetches=["softmax:0", "lstm/state:0"], 47 | feed_dict={ 48 | "input_feed:0": input_feed, 49 | "lstm/state_feed:0": state_feed, 50 | }) 51 | return softmax_output, state_output, None 52 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/im2txt/im2txt/ops/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = ["//im2txt:internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | py_library( 8 | name = "image_processing", 9 | srcs = ["image_processing.py"], 10 | srcs_version = "PY2AND3", 11 | ) 12 | 13 | py_library( 14 | name = "image_embedding", 15 | srcs = ["image_embedding.py"], 16 | srcs_version = "PY2AND3", 17 | ) 18 | 19 | py_test( 20 | name = "image_embedding_test", 21 | size = "small", 22 | srcs = ["image_embedding_test.py"], 23 | deps = [ 24 | ":image_embedding", 25 | ], 26 | ) 27 | 28 | py_library( 29 | name = "inputs", 30 | srcs = ["inputs.py"], 31 | srcs_version = "PY2AND3", 32 | ) 33 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "inception") 2 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/g3doc/inception_v3_architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/inception/g3doc/inception_v3_architecture.png -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/inception/flowers_data.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 | """Small library that points to the flowers data set. 16 | """ 17 | from __future__ import absolute_import 18 | from __future__ import division 19 | from __future__ import print_function 20 | 21 | 22 | 23 | from inception.dataset import Dataset 24 | 25 | 26 | class FlowersData(Dataset): 27 | """Flowers data set.""" 28 | 29 | def __init__(self, subset): 30 | super(FlowersData, self).__init__('Flowers', subset) 31 | 32 | def num_classes(self): 33 | """Returns the number of classes in the data set.""" 34 | return 5 35 | 36 | def num_examples_per_epoch(self): 37 | """Returns the number of examples in the data subset.""" 38 | if self.subset == 'train': 39 | return 3170 40 | if self.subset == 'validation': 41 | return 500 42 | 43 | def download_message(self): 44 | """Instruction to download and extract the tarball from Flowers website.""" 45 | 46 | print('Failed to find any Flowers %s files'% self.subset) 47 | print('') 48 | print('If you have already downloaded and processed the data, then make ' 49 | 'sure to set --data_dir to point to the directory containing the ' 50 | 'location of the sharded TFRecords.\n') 51 | print('Please see README.md for instructions on how to build ' 52 | 'the flowers dataset using download_and_preprocess_flowers.\n') 53 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/inception/flowers_eval.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 | """A binary to evaluate Inception on the flowers data set. 16 | """ 17 | from __future__ import absolute_import 18 | from __future__ import division 19 | from __future__ import print_function 20 | 21 | 22 | import tensorflow as tf 23 | 24 | from inception import inception_eval 25 | from inception.flowers_data import FlowersData 26 | 27 | FLAGS = tf.app.flags.FLAGS 28 | 29 | 30 | def main(unused_argv=None): 31 | dataset = FlowersData(subset=FLAGS.subset) 32 | assert dataset.data_files() 33 | if tf.gfile.Exists(FLAGS.eval_dir): 34 | tf.gfile.DeleteRecursively(FLAGS.eval_dir) 35 | tf.gfile.MakeDirs(FLAGS.eval_dir) 36 | inception_eval.evaluate(dataset) 37 | 38 | 39 | if __name__ == '__main__': 40 | tf.app.run() 41 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/inception/flowers_train.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 | """A binary to train Inception on the flowers data set. 16 | """ 17 | from __future__ import absolute_import 18 | from __future__ import division 19 | from __future__ import print_function 20 | 21 | 22 | 23 | import tensorflow as tf 24 | 25 | from inception import inception_train 26 | from inception.flowers_data import FlowersData 27 | 28 | FLAGS = tf.app.flags.FLAGS 29 | 30 | 31 | def main(_): 32 | dataset = FlowersData(subset=FLAGS.subset) 33 | assert dataset.data_files() 34 | if tf.gfile.Exists(FLAGS.train_dir): 35 | tf.gfile.DeleteRecursively(FLAGS.train_dir) 36 | tf.gfile.MakeDirs(FLAGS.train_dir) 37 | inception_train.train(dataset) 38 | 39 | 40 | if __name__ == '__main__': 41 | tf.app.run() 42 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/inception/imagenet_data.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 | """Small library that points to the ImageNet data set. 16 | """ 17 | from __future__ import absolute_import 18 | from __future__ import division 19 | from __future__ import print_function 20 | 21 | 22 | 23 | from inception.dataset import Dataset 24 | 25 | 26 | class ImagenetData(Dataset): 27 | """ImageNet data set.""" 28 | 29 | def __init__(self, subset): 30 | super(ImagenetData, self).__init__('ImageNet', subset) 31 | 32 | def num_classes(self): 33 | """Returns the number of classes in the data set.""" 34 | return 1000 35 | 36 | def num_examples_per_epoch(self): 37 | """Returns the number of examples in the data set.""" 38 | # Bounding box data consists of 615299 bounding boxes for 544546 images. 39 | if self.subset == 'train': 40 | return 1281167 41 | if self.subset == 'validation': 42 | return 50000 43 | 44 | def download_message(self): 45 | """Instruction to download and extract the tarball from Flowers website.""" 46 | 47 | print('Failed to find any ImageNet %s files'% self.subset) 48 | print('') 49 | print('If you have already downloaded and processed the data, then make ' 50 | 'sure to set --data_dir to point to the directory containing the ' 51 | 'location of the sharded TFRecords.\n') 52 | print('If you have not downloaded and prepared the ImageNet data in the ' 53 | 'TFRecord format, you will need to do this at least once. This ' 54 | 'process could take several hours depending on the speed of your ' 55 | 'computer and network connection\n') 56 | print('Please see README.md for instructions on how to build ' 57 | 'the ImageNet dataset using download_and_preprocess_imagenet.\n') 58 | print('Note that the raw data size is 300 GB and the processed data size ' 59 | 'is 150 GB. Please ensure you have at least 500GB disk space.') 60 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/inception/imagenet_distributed_train.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 | # pylint: disable=line-too-long 16 | """A binary to train Inception in a distributed manner using multiple systems. 17 | 18 | Please see accompanying README.md for details and instructions. 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 | from inception import inception_distributed_train 27 | from inception.imagenet_data import ImagenetData 28 | 29 | FLAGS = tf.app.flags.FLAGS 30 | 31 | 32 | def main(unused_args): 33 | assert FLAGS.job_name in ['ps', 'worker'], 'job_name must be ps or worker' 34 | 35 | # Extract all the hostnames for the ps and worker jobs to construct the 36 | # cluster spec. 37 | ps_hosts = FLAGS.ps_hosts.split(',') 38 | worker_hosts = FLAGS.worker_hosts.split(',') 39 | tf.logging.info('PS hosts are: %s' % ps_hosts) 40 | tf.logging.info('Worker hosts are: %s' % worker_hosts) 41 | 42 | cluster_spec = tf.train.ClusterSpec({'ps': ps_hosts, 43 | 'worker': worker_hosts}) 44 | server = tf.train.Server( 45 | {'ps': ps_hosts, 46 | 'worker': worker_hosts}, 47 | job_name=FLAGS.job_name, 48 | task_index=FLAGS.task_id) 49 | 50 | if FLAGS.job_name == 'ps': 51 | # `ps` jobs wait for incoming connections from the workers. 52 | server.join() 53 | else: 54 | # `worker` jobs will actually do the work. 55 | dataset = ImagenetData(subset=FLAGS.subset) 56 | assert dataset.data_files() 57 | # Only the chief checks for or creates train_dir. 58 | if FLAGS.task_id == 0: 59 | if not tf.gfile.Exists(FLAGS.train_dir): 60 | tf.gfile.MakeDirs(FLAGS.train_dir) 61 | inception_distributed_train.train(server.target, dataset, cluster_spec) 62 | 63 | if __name__ == '__main__': 64 | tf.logging.set_verbosity(tf.logging.INFO) 65 | tf.app.run() 66 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/inception/imagenet_eval.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 | """A binary to evaluate Inception on the flowers data set. 16 | 17 | Note that using the supplied pre-trained inception checkpoint, the eval should 18 | achieve: 19 | precision @ 1 = 0.7874 recall @ 5 = 0.9436 [50000 examples] 20 | 21 | See the README.md for more details. 22 | """ 23 | from __future__ import absolute_import 24 | from __future__ import division 25 | from __future__ import print_function 26 | 27 | 28 | import tensorflow as tf 29 | 30 | from inception import inception_eval 31 | from inception.imagenet_data import ImagenetData 32 | 33 | FLAGS = tf.app.flags.FLAGS 34 | 35 | 36 | def main(unused_argv=None): 37 | dataset = ImagenetData(subset=FLAGS.subset) 38 | assert dataset.data_files() 39 | if tf.gfile.Exists(FLAGS.eval_dir): 40 | tf.gfile.DeleteRecursively(FLAGS.eval_dir) 41 | tf.gfile.MakeDirs(FLAGS.eval_dir) 42 | inception_eval.evaluate(dataset) 43 | 44 | 45 | if __name__ == '__main__': 46 | tf.app.run() 47 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/inception/imagenet_train.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 | """A binary to train Inception on the ImageNet data set. 16 | """ 17 | from __future__ import absolute_import 18 | from __future__ import division 19 | from __future__ import print_function 20 | 21 | 22 | 23 | import tensorflow as tf 24 | 25 | from inception import inception_train 26 | from inception.imagenet_data import ImagenetData 27 | 28 | FLAGS = tf.app.flags.FLAGS 29 | 30 | 31 | def main(_): 32 | dataset = ImagenetData(subset=FLAGS.subset) 33 | assert dataset.data_files() 34 | if tf.gfile.Exists(FLAGS.train_dir): 35 | tf.gfile.DeleteRecursively(FLAGS.train_dir) 36 | tf.gfile.MakeDirs(FLAGS.train_dir) 37 | inception_train.train(dataset) 38 | 39 | 40 | if __name__ == '__main__': 41 | tf.app.run() 42 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/inception/slim/BUILD: -------------------------------------------------------------------------------- 1 | # Description: 2 | # Contains the operations and nets for building TensorFlow-Slim models. 3 | 4 | package(default_visibility = ["//inception:internal"]) 5 | 6 | licenses(["notice"]) # Apache 2.0 7 | 8 | exports_files(["LICENSE"]) 9 | 10 | py_library( 11 | name = "scopes", 12 | srcs = ["scopes.py"], 13 | ) 14 | 15 | py_test( 16 | name = "scopes_test", 17 | size = "small", 18 | srcs = ["scopes_test.py"], 19 | deps = [ 20 | ":scopes", 21 | ], 22 | ) 23 | 24 | py_library( 25 | name = "variables", 26 | srcs = ["variables.py"], 27 | deps = [ 28 | ":scopes", 29 | ], 30 | ) 31 | 32 | py_test( 33 | name = "variables_test", 34 | size = "small", 35 | srcs = ["variables_test.py"], 36 | deps = [ 37 | ":variables", 38 | ], 39 | ) 40 | 41 | py_library( 42 | name = "losses", 43 | srcs = ["losses.py"], 44 | ) 45 | 46 | py_test( 47 | name = "losses_test", 48 | size = "small", 49 | srcs = ["losses_test.py"], 50 | deps = [ 51 | ":losses", 52 | ], 53 | ) 54 | 55 | py_library( 56 | name = "ops", 57 | srcs = ["ops.py"], 58 | deps = [ 59 | ":losses", 60 | ":scopes", 61 | ":variables", 62 | ], 63 | ) 64 | 65 | py_test( 66 | name = "ops_test", 67 | size = "small", 68 | srcs = ["ops_test.py"], 69 | deps = [ 70 | ":ops", 71 | ":variables", 72 | ], 73 | ) 74 | 75 | py_library( 76 | name = "inception", 77 | srcs = ["inception_model.py"], 78 | deps = [ 79 | ":ops", 80 | ":scopes", 81 | ], 82 | ) 83 | 84 | py_test( 85 | name = "inception_test", 86 | size = "medium", 87 | srcs = ["inception_test.py"], 88 | deps = [ 89 | ":inception", 90 | ], 91 | ) 92 | 93 | py_library( 94 | name = "slim", 95 | srcs = ["slim.py"], 96 | deps = [ 97 | ":inception", 98 | ":losses", 99 | ":ops", 100 | ":scopes", 101 | ":variables", 102 | ], 103 | ) 104 | 105 | py_test( 106 | name = "collections_test", 107 | size = "small", 108 | srcs = ["collections_test.py"], 109 | deps = [ 110 | ":slim", 111 | ], 112 | ) 113 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/inception/inception/slim/slim.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 | """TF-Slim grouped API. Please see README.md for details and usage.""" 16 | # pylint: disable=unused-import 17 | 18 | # Collapse tf-slim into a single namespace. 19 | from inception.slim import inception_model as inception 20 | from inception.slim import losses 21 | from inception.slim import ops 22 | from inception.slim import scopes 23 | from inception.slim import variables 24 | from inception.slim.scopes import arg_scope 25 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/lm_1b/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = [":internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | package_group( 8 | name = "internal", 9 | packages = [ 10 | "//lm_1b/...", 11 | ], 12 | ) 13 | 14 | py_library( 15 | name = "data_utils", 16 | srcs = ["data_utils.py"], 17 | ) 18 | 19 | py_binary( 20 | name = "lm_1b_eval", 21 | srcs = [ 22 | "lm_1b_eval.py", 23 | ], 24 | deps = [ 25 | ":data_utils", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/neural_gpu/README.md: -------------------------------------------------------------------------------- 1 | # NeuralGPU 2 | Code for the Neural GPU model as described 3 | in [[http://arxiv.org/abs/1511.08228]]. 4 | 5 | Requirements: 6 | * TensorFlow (see tensorflow.org for how to install) 7 | * Matplotlib for Python (sudo apt-get install python-matplotlib) 8 | 9 | The model can be trained on the following algorithmic tasks: 10 | 11 | * `sort` - Sort a symbol list 12 | * `kvsort` - Sort symbol keys in dictionary 13 | * `id` - Return the same symbol list 14 | * `rev` - Reverse a symbol list 15 | * `rev2` - Reverse a symbol dictionary by key 16 | * `incr` - Add one to a symbol value 17 | * `add` - Long decimal addition 18 | * `left` - First symbol in list 19 | * `right` - Last symbol in list 20 | * `left-shift` - Left shift a symbol list 21 | * `right-shift` - Right shift a symbol list 22 | * `bmul` - Long binary multiplication 23 | * `mul` - Long decimal multiplication 24 | * `dup` - Duplicate a symbol list with padding 25 | * `badd` - Long binary addition 26 | * `qadd` - Long quaternary addition 27 | * `search` - Search for symbol key in dictionary 28 | 29 | The value range for symbols are defined by the `niclass` and `noclass` flags. 30 | In particular, the values are in the range `min(--niclass, noclass) - 1`. 31 | So if you set `--niclass=33` and `--noclass=33` (the default) then `--task=rev` 32 | will be reversing lists of 32 symbols, and `--task=id` will be identity on a 33 | list of up to 32 symbols. 34 | 35 | 36 | To train the model on the reverse task run: 37 | 38 | ``` 39 | python neural_gpu_trainer.py --task=rev 40 | ``` 41 | 42 | While training, interim / checkpoint model parameters will be 43 | written to `/tmp/neural_gpu/`. 44 | 45 | Once the amount of error gets down to what you're comfortable 46 | with, hit `Ctrl-C` to stop the training process. The latest 47 | model parameters will be in `/tmp/neural_gpu/neural_gpu.ckpt-` 48 | and used on any subsequent run. 49 | 50 | To test a trained model on how well it decodes run: 51 | 52 | ``` 53 | python neural_gpu_trainer.py --task=rev --mode=1 54 | ``` 55 | 56 | To produce an animation of the result run: 57 | 58 | ``` 59 | python neural_gpu_trainer.py --task=rev --mode=1 --animate=True 60 | ``` 61 | 62 | Maintained by Lukasz Kaiser (lukaszkaiser) 63 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/neural_programmer/README.md: -------------------------------------------------------------------------------- 1 | Implementation of the Neural Programmer model described in https://openreview.net/pdf?id=ry2YOrcge 2 | 3 | Download the data from http://www-nlp.stanford.edu/software/sempre/wikitable/ Change the data_dir FLAG to the location of the data 4 | 5 | Training: python neural_programmer.py 6 | 7 | The models are written to FLAGS.output_dir 8 | 9 | Testing: python neural_programmer.py --evaluator_job=True 10 | 11 | The models are loaded from FLAGS.output_dir. The evaluation is done on development data. 12 | 13 | Maintained by Arvind Neelakantan (arvind2505) 14 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/neural_programmer/nn_utils.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 | """Author: aneelakantan (Arvind Neelakantan) 16 | """ 17 | 18 | import tensorflow as tf 19 | 20 | def get_embedding(word, utility, params): 21 | return tf.nn.embedding_lookup(params["word"], word) 22 | 23 | 24 | def apply_dropout(x, dropout_rate, mode): 25 | if (dropout_rate > 0.0): 26 | if (mode == "train"): 27 | x = tf.nn.dropout(x, dropout_rate) 28 | else: 29 | x = x 30 | return x 31 | 32 | 33 | def LSTMCell(x, mprev, cprev, key, params): 34 | """Create an LSTM cell. 35 | 36 | Implements the equations in pg.2 from 37 | "Long Short-Term Memory Based Recurrent Neural Network Architectures 38 | For Large Vocabulary Speech Recognition", 39 | Hasim Sak, Andrew Senior, Francoise Beaufays. 40 | 41 | Args: 42 | w: A dictionary of the weights and optional biases as returned 43 | by LSTMParametersSplit(). 44 | x: Inputs to this cell. 45 | mprev: m_{t-1}, the recurrent activations (same as the output) 46 | from the previous cell. 47 | cprev: c_{t-1}, the cell activations from the previous cell. 48 | keep_prob: Keep probability on the input and the outputs of a cell. 49 | 50 | Returns: 51 | m: Outputs of this cell. 52 | c: Cell Activations. 53 | """ 54 | 55 | i = tf.matmul(x, params[key + "_ix"]) + tf.matmul(mprev, params[key + "_im"]) 56 | i = tf.nn.bias_add(i, params[key + "_i"]) 57 | f = tf.matmul(x, params[key + "_fx"]) + tf.matmul(mprev, params[key + "_fm"]) 58 | f = tf.nn.bias_add(f, params[key + "_f"]) 59 | c = tf.matmul(x, params[key + "_cx"]) + tf.matmul(mprev, params[key + "_cm"]) 60 | c = tf.nn.bias_add(c, params[key + "_c"]) 61 | o = tf.matmul(x, params[key + "_ox"]) + tf.matmul(mprev, params[key + "_om"]) 62 | o = tf.nn.bias_add(o, params[key + "_o"]) 63 | i = tf.sigmoid(i, name="i_gate") 64 | f = tf.sigmoid(f, name="f_gate") 65 | o = tf.sigmoid(o, name="o_gate") 66 | c = f * cprev + i * tf.tanh(c) 67 | m = o * c 68 | return m, c 69 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/resnet/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = [":internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | package_group( 8 | name = "internal", 9 | packages = [ 10 | "//resnet/...", 11 | ], 12 | ) 13 | 14 | filegroup( 15 | name = "py_srcs", 16 | data = glob([ 17 | "**/*.py", 18 | ]), 19 | ) 20 | 21 | py_library( 22 | name = "resnet_model", 23 | srcs = ["resnet_model.py"], 24 | ) 25 | 26 | py_binary( 27 | name = "resnet_main", 28 | srcs = [ 29 | "resnet_main.py", 30 | ], 31 | deps = [ 32 | ":cifar_input", 33 | ":resnet_model", 34 | ], 35 | ) 36 | 37 | py_library( 38 | name = "cifar_input", 39 | srcs = ["cifar_input.py"], 40 | ) 41 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/resnet/g3doc/cifar_resnet.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/resnet/g3doc/cifar_resnet.gif -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/resnet/g3doc/cifar_resnet_legends.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/resnet/g3doc/cifar_resnet_legends.gif -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/slim/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/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 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/slim/deployment/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/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_dir) 71 | 72 | if __name__ == '__main__': 73 | tf.app.run() 74 | 75 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/slim/nets/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/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_v1 import inception_v1 25 | from nets.inception_v1 import inception_v1_arg_scope 26 | from nets.inception_v1 import inception_v1_base 27 | from nets.inception_v2 import inception_v2 28 | from nets.inception_v2 import inception_v2_arg_scope 29 | from nets.inception_v2 import inception_v2_base 30 | from nets.inception_v3 import inception_v3 31 | from nets.inception_v3 import inception_v3_arg_scope 32 | from nets.inception_v3 import inception_v3_base 33 | from nets.inception_v4 import inception_v4 34 | from nets.inception_v4 import inception_v4_arg_scope 35 | from nets.inception_v4 import inception_v4_base 36 | # pylint: enable=unused-import 37 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/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 testGetNetworkFn(self): 31 | batch_size = 5 32 | num_classes = 1000 33 | for net in nets_factory.networks_map: 34 | with self.test_session(): 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 | if __name__ == '__main__': 46 | tf.test.main() 47 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/slim/preprocessing/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/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.sub(image, 128.0) 43 | image = tf.div(image, 128.0) 44 | return image 45 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/slim/scripts/train_cifarnet_on_cifar10.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script performs the following operations: 4 | # 1. Downloads the Cifar10 dataset 5 | # 2. Trains a CifarNet model on the Cifar10 training set. 6 | # 3. Evaluates the model on the Cifar10 testing set. 7 | # 8 | # Usage: 9 | # cd slim 10 | # ./scripts/train_cifar_net_on_mnist.sh 11 | 12 | # Where the checkpoint and logs will be saved to. 13 | TRAIN_DIR=/tmp/cifarnet-model 14 | 15 | # Where the dataset is saved to. 16 | DATASET_DIR=/tmp/cifar10 17 | 18 | # Download the dataset 19 | python download_and_convert_data.py \ 20 | --dataset_name=cifar10 \ 21 | --dataset_dir=${DATASET_DIR} 22 | 23 | # Run training. 24 | python train_image_classifier.py \ 25 | --train_dir=${TRAIN_DIR} \ 26 | --dataset_name=cifar10 \ 27 | --dataset_split_name=train \ 28 | --dataset_dir=${DATASET_DIR} \ 29 | --model_name=cifarnet \ 30 | --preprocessing_name=cifarnet \ 31 | --max_number_of_steps=100000 \ 32 | --batch_size=128 \ 33 | --save_interval_secs=120 \ 34 | --save_summaries_secs=120 \ 35 | --log_every_n_steps=100 \ 36 | --optimizer=sgd \ 37 | --learning_rate=0.1 \ 38 | --learning_rate_decay_factor=0.1 \ 39 | --num_epochs_per_decay=200 \ 40 | --weight_decay=0.004 41 | 42 | # Run evaluation. 43 | python eval_image_classifier.py \ 44 | --checkpoint_path=${TRAIN_DIR} \ 45 | --eval_dir=${TRAIN_DIR} \ 46 | --dataset_name=cifar10 \ 47 | --dataset_split_name=test \ 48 | --dataset_dir=${DATASET_DIR} \ 49 | --model_name=cifarnet 50 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/slim/scripts/train_lenet_on_mnist.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This script performs the following operations: 4 | # 1. Downloads the MNIST dataset 5 | # 2. Trains a LeNet model on the MNIST training set. 6 | # 3. Evaluates the model on the MNIST testing set. 7 | # 8 | # Usage: 9 | # cd slim 10 | # ./slim/scripts/train_lenet_on_mnist.sh 11 | 12 | # Where the checkpoint and logs will be saved to. 13 | TRAIN_DIR=/tmp/lenet-model 14 | 15 | # Where the dataset is saved to. 16 | DATASET_DIR=/tmp/mnist 17 | 18 | # Download the dataset 19 | python download_and_convert_data.py \ 20 | --dataset_name=mnist \ 21 | --dataset_dir=${DATASET_DIR} 22 | 23 | # Run training. 24 | python train_image_classifier.py \ 25 | --train_dir=${TRAIN_DIR} \ 26 | --dataset_name=mnist \ 27 | --dataset_split_name=train \ 28 | --dataset_dir=${DATASET_DIR} \ 29 | --model_name=lenet \ 30 | --preprocessing_name=lenet \ 31 | --max_number_of_steps=20000 \ 32 | --batch_size=50 \ 33 | --learning_rate=0.01 \ 34 | --save_interval_secs=60 \ 35 | --save_summaries_secs=60 \ 36 | --log_every_n_steps=100 \ 37 | --optimizer=sgd \ 38 | --learning_rate_decay_type=fixed \ 39 | --weight_decay=0 40 | 41 | # Run evaluation. 42 | python eval_image_classifier.py \ 43 | --checkpoint_path=${TRAIN_DIR} \ 44 | --eval_dir=${TRAIN_DIR} \ 45 | --dataset_name=mnist \ 46 | --dataset_split_name=test \ 47 | --dataset_dir=${DATASET_DIR} \ 48 | --model_name=lenet 49 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/street/g3doc/avdessapins.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/street/g3doc/avdessapins.png -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/street/python/decoder_test.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 | """Tests for decoder.""" 16 | import os 17 | 18 | import tensorflow as tf 19 | import decoder 20 | 21 | 22 | def _testdata(filename): 23 | return os.path.join('../testdata/', filename) 24 | 25 | 26 | class DecoderTest(tf.test.TestCase): 27 | 28 | def testCodesFromCTC(self): 29 | """Tests that the simple CTC decoder drops nulls and duplicates. 30 | """ 31 | ctc_labels = [9, 9, 9, 1, 9, 2, 2, 3, 9, 9, 0, 0, 1, 9, 1, 9, 9, 9] 32 | decode = decoder.Decoder(filename=None) 33 | non_null_labels = decode._CodesFromCTC( 34 | ctc_labels, merge_dups=False, null_label=9) 35 | self.assertEqual(non_null_labels, [1, 2, 2, 3, 0, 0, 1, 1]) 36 | idempotent_labels = decode._CodesFromCTC( 37 | non_null_labels, merge_dups=False, null_label=9) 38 | self.assertEqual(idempotent_labels, non_null_labels) 39 | collapsed_labels = decode._CodesFromCTC( 40 | ctc_labels, merge_dups=True, null_label=9) 41 | self.assertEqual(collapsed_labels, [1, 2, 3, 0, 1, 1]) 42 | non_idempotent_labels = decode._CodesFromCTC( 43 | collapsed_labels, merge_dups=True, null_label=9) 44 | self.assertEqual(non_idempotent_labels, [1, 2, 3, 0, 1]) 45 | 46 | def testStringFromCTC(self): 47 | """Tests that the decoder can decode sequences including multi-codes. 48 | """ 49 | # - f - a r - m(1/2)m -junk sp b a r - n - 50 | ctc_labels = [9, 6, 9, 1, 3, 9, 4, 9, 5, 5, 9, 5, 0, 2, 1, 3, 9, 4, 9] 51 | decode = decoder.Decoder(filename=_testdata('charset_size_10.txt')) 52 | text = decode.StringFromCTC(ctc_labels, merge_dups=True, null_label=9) 53 | self.assertEqual(text, 'farm barn') 54 | 55 | 56 | if __name__ == '__main__': 57 | tf.test.main() 58 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/street/python/vgsl_eval.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 | """Model eval separate from training.""" 16 | from tensorflow import app 17 | from tensorflow.python.platform import flags 18 | 19 | import vgsl_model 20 | 21 | flags.DEFINE_string('eval_dir', '/tmp/mdir/eval', 22 | 'Directory where to write event logs.') 23 | flags.DEFINE_string('graph_def_file', None, 24 | 'Output eval graph definition file.') 25 | flags.DEFINE_string('train_dir', '/tmp/mdir', 26 | 'Directory where to find training checkpoints.') 27 | flags.DEFINE_string('model_str', 28 | '1,150,600,3[S2(4x150)0,2 Ct5,5,16 Mp2,2 Ct5,5,64 Mp3,3' 29 | '([Lrys64 Lbx128][Lbys64 Lbx128][Lfys64 Lbx128])S3(3x0)2,3' 30 | 'Lfx128 Lrx128 S0(1x4)0,3 Do Lfx256]O1c134', 31 | 'Network description.') 32 | flags.DEFINE_integer('num_steps', 1000, 'Number of steps to run evaluation.') 33 | flags.DEFINE_integer('eval_interval_secs', 60, 34 | 'Time interval between eval runs.') 35 | flags.DEFINE_string('eval_data', None, 'Evaluation data filepattern') 36 | flags.DEFINE_string('decoder', None, 'Charset decoder') 37 | 38 | FLAGS = flags.FLAGS 39 | 40 | 41 | def main(argv): 42 | del argv 43 | vgsl_model.Eval(FLAGS.train_dir, FLAGS.eval_dir, FLAGS.model_str, 44 | FLAGS.eval_data, FLAGS.decoder, FLAGS.num_steps, 45 | FLAGS.graph_def_file, FLAGS.eval_interval_secs) 46 | 47 | 48 | if __name__ == '__main__': 49 | app.run() 50 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/street/testdata/arial-32-tiny: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/street/testdata/arial-32-tiny -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/street/testdata/arial.charset_size=105.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 104 3 | 1 G 4 | 2 r 5 | 3 a 6 | 4 s 7 | 5 l 8 | 6 n 9 | 7 d 10 | 8 . 11 | 9 B 12 | 10 C 13 | 11 O 14 | 12 W 15 | 13 Y 16 | 14 , 17 | 15 ( 18 | 16 u 19 | 17 z 20 | 18 i 21 | 19 e 22 | 20 ) 23 | 21 1 24 | 22 9 25 | 23 2 26 | 24 - 27 | 25 6 28 | 26 o 29 | 27 L 30 | 28 P 31 | 29 ' 32 | 30 t 33 | 31 m 34 | 32 K 35 | 33 c 36 | 34 k 37 | 35 V 38 | 36 S 39 | 37 D 40 | 38 J 41 | 39 h 42 | 40 M 43 | 41 x 44 | 42 E 45 | 43 q 46 | 44 ; 47 | 45 A 48 | 46 y 49 | 47 f 50 | 48 5 51 | 49 7 52 | 50 b 53 | 51 4 54 | 52 0 55 | 53 3 56 | 54 N 57 | 55 I 58 | 56 T 59 | 57 / 60 | 58 p 61 | 59 w 62 | 60 g 63 | 61 H 64 | 62 “ 65 | 63 F 66 | 62 ” 67 | 62 " 68 | 29 ’ 69 | 64 R 70 | 24 — 71 | 65 8 72 | 66 v 73 | 67 ? 74 | 68 é 75 | 69 % 76 | 70 : 77 | 71 j 78 | 72 \ 79 | 73 { 80 | 74 } 81 | 75 | 82 | 76 U 83 | 77 $ 84 | 78 ° 85 | 79 * 86 | 80 ! 87 | 81 ] 88 | 82 Q 89 | 29 ‘ 90 | 83 Z 91 | 84 X 92 | 85 [ 93 | 86 = 94 | 87 + 95 | 88 § 96 | 89 _ 97 | 90 £ 98 | 91 & 99 | 92 # 100 | 93 > 101 | 94 < 102 | 95 ~ 103 | 96 € 104 | 97 @ 105 | 98 ¢ 106 | 99 » 107 | 100 « 108 | 47,5 fl 109 | 47,18 fi 110 | 101 ® 111 | 102 © 112 | 103 ¥ 113 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/street/testdata/charset_size=134.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 133 3 | 1 l 4 | 2 ’ 5 | 3 é 6 | 4 t 7 | 5 e 8 | 6 i 9 | 7 n 10 | 8 s 11 | 9 x 12 | 10 g 13 | 11 u 14 | 12 o 15 | 13 1 16 | 14 8 17 | 15 7 18 | 16 0 19 | 17 - 20 | 18 . 21 | 19 p 22 | 20 a 23 | 21 r 24 | 22 è 25 | 23 d 26 | 24 c 27 | 25 V 28 | 26 v 29 | 27 b 30 | 28 m 31 | 29 ) 32 | 30 C 33 | 31 z 34 | 32 S 35 | 33 y 36 | 34 , 37 | 35 k 38 | 36 É 39 | 37 A 40 | 38 h 41 | 39 E 42 | 40 » 43 | 41 D 44 | 42 / 45 | 43 H 46 | 44 M 47 | 45 ( 48 | 46 G 49 | 47 P 50 | 48 ç 51 | 2 ' 52 | 49 R 53 | 50 f 54 | 51 " 55 | 52 2 56 | 53 j 57 | 54 | 58 | 55 N 59 | 56 6 60 | 57 ° 61 | 58 5 62 | 59 T 63 | 60 O 64 | 61 U 65 | 62 3 66 | 63 % 67 | 64 9 68 | 65 q 69 | 66 Z 70 | 67 B 71 | 68 K 72 | 69 w 73 | 70 W 74 | 71 : 75 | 72 4 76 | 73 L 77 | 74 F 78 | 75 ] 79 | 76 ï 80 | 2 ‘ 81 | 77 I 82 | 78 J 83 | 79 ä 84 | 80 î 85 | 81 ; 86 | 82 à 87 | 83 ê 88 | 84 X 89 | 85 ü 90 | 86 Y 91 | 87 ô 92 | 88 = 93 | 89 + 94 | 90 \ 95 | 91 { 96 | 92 } 97 | 93 _ 98 | 94 Q 99 | 95 œ 100 | 96 ñ 101 | 97 * 102 | 98 ! 103 | 99 Ü 104 | 51 “ 105 | 100 â 106 | 101 Ç 107 | 102 Œ 108 | 103 û 109 | 104 ? 110 | 105 $ 111 | 106 ë 112 | 107 « 113 | 108 € 114 | 109 & 115 | 110 < 116 | 51 ” 117 | 111 æ 118 | 112 # 119 | 113 ® 120 | 114  121 | 115 È 122 | 116 > 123 | 117 [ 124 | 17 — 125 | 118 Æ 126 | 119 ù 127 | 120 Î 128 | 121 Ô 129 | 122 ÿ 130 | 123 À 131 | 124 Ê 132 | 125 @ 133 | 126 Ï 134 | 127 © 135 | 128 Ë 136 | 129 Ù 137 | 130 £ 138 | 131 Ÿ 139 | 132 Û 140 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/street/testdata/charset_size_10.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 9 3 | 1 a 4 | 2 b 5 | 3 r 6 | 4 n 7 | 4,5 m 8 | 6 f 9 | 7 . 10 | 8 , 11 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/street/testdata/mnist-tiny: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/street/testdata/mnist-tiny -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/street/testdata/numbers-16-tiny: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/street/testdata/numbers-16-tiny -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/street/testdata/numbers.charset_size=12.txt: -------------------------------------------------------------------------------- 1 | 0 2 | 11 3 | 1 9 4 | 2 8 5 | 3 7 6 | 4 6 7 | 5 1 8 | 6 4 9 | 7 0 10 | 8 3 11 | 9 5 12 | 10 2 13 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/swivel/nearest.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # 3 | # Copyright 2016 Google Inc. All Rights Reserved. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | """Simple tool for inspecting nearest neighbors and analogies.""" 18 | 19 | import re 20 | import sys 21 | from getopt import GetoptError, getopt 22 | 23 | from vecs import Vecs 24 | 25 | try: 26 | opts, args = getopt(sys.argv[1:], 'v:e:', ['vocab=', 'embeddings=']) 27 | except GetoptError, e: 28 | print >> sys.stderr, e 29 | sys.exit(2) 30 | 31 | opt_vocab = 'vocab.txt' 32 | opt_embeddings = None 33 | 34 | for o, a in opts: 35 | if o in ('-v', '--vocab'): 36 | opt_vocab = a 37 | if o in ('-e', '--embeddings'): 38 | opt_embeddings = a 39 | 40 | vecs = Vecs(opt_vocab, opt_embeddings) 41 | 42 | while True: 43 | sys.stdout.write('query> ') 44 | sys.stdout.flush() 45 | 46 | query = sys.stdin.readline().strip() 47 | if not query: 48 | break 49 | 50 | parts = re.split(r'\s+', query) 51 | 52 | if len(parts) == 1: 53 | res = vecs.neighbors(parts[0]) 54 | 55 | elif len(parts) == 3: 56 | vs = [vecs.lookup(w) for w in parts] 57 | if any(v is None for v in vs): 58 | print 'not in vocabulary: %s' % ( 59 | ', '.join(tok for tok, v in zip(parts, vs) if v is None)) 60 | 61 | continue 62 | 63 | res = vecs.neighbors(vs[2] - vs[0] + vs[1]) 64 | 65 | else: 66 | print 'use a single word to query neighbors, or three words for analogy' 67 | continue 68 | 69 | if not res: 70 | continue 71 | 72 | for word, sim in res[:20]: 73 | print '%0.4f: %s' % (sim, word) 74 | 75 | print 76 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM java:8 2 | 3 | ENV SYNTAXNETDIR=/opt/tensorflow PATH=$PATH:/root/bin 4 | 5 | RUN mkdir -p $SYNTAXNETDIR \ 6 | && cd $SYNTAXNETDIR \ 7 | && apt-get update \ 8 | && apt-get install git zlib1g-dev file swig python2.7 python-dev python-pip python-mock -y \ 9 | && pip install --upgrade pip \ 10 | && pip install -U protobuf==3.0.0 \ 11 | && pip install asciitree \ 12 | && pip install numpy \ 13 | && wget https://github.com/bazelbuild/bazel/releases/download/0.3.1/bazel-0.3.1-installer-linux-x86_64.sh \ 14 | && chmod +x bazel-0.3.1-installer-linux-x86_64.sh \ 15 | && ./bazel-0.3.1-installer-linux-x86_64.sh --user \ 16 | && git clone --recursive https://github.com/tensorflow/models.git \ 17 | && cd $SYNTAXNETDIR/models/syntaxnet/tensorflow \ 18 | && echo "\n\n\n\n" | ./configure \ 19 | && apt-get autoremove -y \ 20 | && apt-get clean 21 | 22 | RUN cd $SYNTAXNETDIR/models/syntaxnet \ 23 | && bazel test --genrule_strategy=standalone syntaxnet/... util/utf8/... 24 | 25 | WORKDIR $SYNTAXNETDIR/models/syntaxnet 26 | 27 | CMD [ "sh", "-c", "echo 'Bob brought the pizza to Alice.' | syntaxnet/demo.sh" ] 28 | 29 | # COMMANDS to build and run 30 | # =============================== 31 | # mkdir build && cp Dockerfile build/ && cd build 32 | # docker build -t syntaxnet . 33 | # docker run syntaxnet 34 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/WORKSPACE: -------------------------------------------------------------------------------- 1 | local_repository( 2 | name = "org_tensorflow", 3 | path = "tensorflow", 4 | ) 5 | 6 | load('@org_tensorflow//tensorflow:workspace.bzl', 'tf_workspace') 7 | tf_workspace() 8 | 9 | # Specify the minimum required Bazel version. 10 | load("@org_tensorflow//tensorflow:tensorflow.bzl", "check_version") 11 | check_version("0.3.0") 12 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/beam_search_training.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/syntaxnet/beam_search_training.png -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/ff_nn_schematic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/syntaxnet/ff_nn_schematic.png -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/looping-parser.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/syntaxnet/looping-parser.gif -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/sawman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/syntaxnet/sawman.png -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/base.h: -------------------------------------------------------------------------------- 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 | #ifndef SYNTAXNET_BASE_H_ 17 | #define SYNTAXNET_BASE_H_ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "tensorflow/core/lib/core/status.h" 25 | #include "tensorflow/core/lib/strings/strcat.h" 26 | #include "tensorflow/core/lib/strings/stringprintf.h" 27 | #include "tensorflow/core/platform/default/integral_types.h" 28 | #include "tensorflow/core/platform/mutex.h" 29 | #include "tensorflow/core/platform/protobuf.h" 30 | 31 | 32 | 33 | using tensorflow::int32; 34 | using tensorflow::int64; 35 | using tensorflow::uint64; 36 | using tensorflow::uint32; 37 | using tensorflow::uint32; 38 | using tensorflow::protobuf::TextFormat; 39 | using tensorflow::mutex_lock; 40 | using tensorflow::mutex; 41 | using std::map; 42 | using std::pair; 43 | using std::vector; 44 | using std::unordered_map; 45 | using std::unordered_set; 46 | typedef signed int char32; 47 | 48 | using tensorflow::StringPiece; 49 | using std::string; 50 | 51 | // namespace syntaxnet 52 | 53 | #endif // SYNTAXNET_BASE_H_ 54 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/demo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 Google Inc. 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 | # A script that runs a tokenizer, a part-of-speech tagger and a dependency 18 | # parser on an English text file, with one sentence per line. 19 | # 20 | # Example usage: 21 | # echo "Parsey McParseface is my favorite parser!" | syntaxnet/demo.sh 22 | 23 | # To run on a conll formatted file, add the --conll command line argument. 24 | # 25 | 26 | PARSER_EVAL=bazel-bin/syntaxnet/parser_eval 27 | MODEL_DIR=syntaxnet/models/parsey_mcparseface 28 | [[ "$1" == "--conll" ]] && INPUT_FORMAT=stdin-conll || INPUT_FORMAT=stdin 29 | 30 | $PARSER_EVAL \ 31 | --input=$INPUT_FORMAT \ 32 | --output=stdout-conll \ 33 | --hidden_layer_sizes=64 \ 34 | --arg_prefix=brain_tagger \ 35 | --graph_builder=structured \ 36 | --task_context=$MODEL_DIR/context.pbtxt \ 37 | --model_path=$MODEL_DIR/tagger-params \ 38 | --slim_model \ 39 | --batch_size=1024 \ 40 | --alsologtostderr \ 41 | | \ 42 | $PARSER_EVAL \ 43 | --input=stdin-conll \ 44 | --output=stdout-conll \ 45 | --hidden_layer_sizes=512,512 \ 46 | --arg_prefix=brain_parser \ 47 | --graph_builder=structured \ 48 | --task_context=$MODEL_DIR/context.pbtxt \ 49 | --model_path=$MODEL_DIR/parser-params \ 50 | --slim_model \ 51 | --batch_size=1024 \ 52 | --alsologtostderr \ 53 | | \ 54 | bazel-bin/syntaxnet/conll2tree \ 55 | --task_context=$MODEL_DIR/context.pbtxt \ 56 | --alsologtostderr 57 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/dictionary.proto: -------------------------------------------------------------------------------- 1 | // Protocol buffers for serializing string<=>index dictionaries. 2 | 3 | syntax = "proto2"; 4 | 5 | package syntaxnet; 6 | 7 | // Serializable representation of a string=>string pair. 8 | message StringToStringPair { 9 | // String representing the key. 10 | required string key = 1; 11 | 12 | // String representing the value. 13 | required string value = 2; 14 | } 15 | 16 | // Serializable representation of a string=>string mapping. 17 | message StringToStringMap { 18 | // Key=>value pairs. 19 | repeated StringToStringPair pair = 1; 20 | } 21 | 22 | // Affix table entry, for serialization of the affix tables. 23 | message AffixTableEntry { 24 | // Nested message for serializing a single affix. 25 | message AffixEntry { 26 | // The affix as a string. 27 | required string form = 1; 28 | 29 | // The length of the affix (this is non-trivial to compute due to UTF-8). 30 | required int32 length = 2; 31 | 32 | // The ID of the affix that is one character shorter, or -1 if none exists. 33 | required int32 shorter_id = 3; 34 | } 35 | 36 | // The type of affix table, as a string. 37 | required string type = 1; 38 | 39 | // The maximum affix length. 40 | required int32 max_length = 2; 41 | 42 | // The list of affixes, in order of affix ID. 43 | repeated AffixEntry affix = 3; 44 | } 45 | 46 | // A light-weight proto to store vectors in binary format. 47 | message TokenEmbedding { 48 | required bytes token = 1; // can be word or phrase, or URL, etc. 49 | 50 | // If available, raw count of this token in the training corpus. 51 | optional int64 count = 3; 52 | 53 | message Vector { 54 | repeated float values = 1 [packed = true]; 55 | } 56 | optional Vector vector = 2; 57 | }; 58 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/document_format.cc: -------------------------------------------------------------------------------- 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 | #include "syntaxnet/document_format.h" 17 | 18 | namespace syntaxnet { 19 | 20 | // Component registry for document formatters. 21 | REGISTER_CLASS_REGISTRY("document format", DocumentFormat); 22 | 23 | } // namespace syntaxnet 24 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/document_format.h: -------------------------------------------------------------------------------- 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 | // An interface for document formats. 17 | 18 | #ifndef SYNTAXNET_DOCUMENT_FORMAT_H__ 19 | #define SYNTAXNET_DOCUMENT_FORMAT_H__ 20 | 21 | #include 22 | #include 23 | 24 | #include "syntaxnet/utils.h" 25 | #include "syntaxnet/registry.h" 26 | #include "syntaxnet/sentence.pb.h" 27 | #include "syntaxnet/task_context.h" 28 | #include "tensorflow/core/lib/io/buffered_inputstream.h" 29 | 30 | namespace syntaxnet { 31 | 32 | // A document format component converts a key/value pair from a record to one or 33 | // more documents. The record format is used for selecting the document format 34 | // component. A document format component can be registered with the 35 | // REGISTER_DOCUMENT_FORMAT macro. 36 | class DocumentFormat : public RegisterableClass { 37 | public: 38 | DocumentFormat() {} 39 | virtual ~DocumentFormat() {} 40 | 41 | virtual void Setup(TaskContext *context) {} 42 | 43 | // Reads a record from the given input buffer with format specific logic. 44 | // Returns false if no record could be read because we reached end of file. 45 | virtual bool ReadRecord(tensorflow::io::BufferedInputStream *buffer, 46 | string *record) = 0; 47 | 48 | // Converts a key/value pair to one or more documents. 49 | virtual void ConvertFromString(const string &key, const string &value, 50 | vector *documents) = 0; 51 | 52 | // Converts a document to a key/value pair. 53 | virtual void ConvertToString(const Sentence &document, 54 | string *key, string *value) = 0; 55 | 56 | private: 57 | TF_DISALLOW_COPY_AND_ASSIGN(DocumentFormat); 58 | }; 59 | 60 | #define REGISTER_DOCUMENT_FORMAT(type, component) \ 61 | REGISTER_CLASS_COMPONENT(DocumentFormat, type, component) 62 | 63 | } // namespace syntaxnet 64 | 65 | #endif // SYNTAXNET_DOCUMENT_FORMAT_H__ 66 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/feature_extractor.proto: -------------------------------------------------------------------------------- 1 | // Protocol buffers for feature extractor. 2 | 3 | syntax = "proto2"; 4 | 5 | package syntaxnet; 6 | 7 | message Parameter { 8 | optional string name = 1; 9 | optional string value = 2; 10 | } 11 | 12 | // Descriptor for feature function. 13 | message FeatureFunctionDescriptor { 14 | // Feature function type. 15 | required string type = 1; 16 | 17 | // Feature function name. 18 | optional string name = 2; 19 | 20 | // Default argument for feature function. 21 | optional int32 argument = 3 [default = 0]; 22 | 23 | // Named parameters for feature descriptor. 24 | repeated Parameter parameter = 4; 25 | 26 | // Nested sub-feature function descriptors. 27 | repeated FeatureFunctionDescriptor feature = 7; 28 | }; 29 | 30 | // Descriptor for feature extractor. 31 | message FeatureExtractorDescriptor { 32 | // Top-level feature function for extractor. 33 | repeated FeatureFunctionDescriptor feature = 1; 34 | }; 35 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/load_parser_ops.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 | """Loads parser_ops shared library.""" 17 | 18 | import os.path 19 | import tensorflow as tf 20 | 21 | tf.load_op_library( 22 | os.path.join(tf.resource_loader.get_data_files_path(), 23 | 'parser_ops.so')) 24 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/fine-to-universal.map: -------------------------------------------------------------------------------- 1 | # . 2 | $ . 3 | '' . 4 | -LRB- . 5 | -RRB- . 6 | , . 7 | . . 8 | : . 9 | ADD X 10 | AFX PRT 11 | CC CONJ 12 | CD NUM 13 | DT DET 14 | EX DET 15 | FW X 16 | GW X 17 | HYPH . 18 | IN ADP 19 | JJ ADJ 20 | JJR ADJ 21 | JJS ADJ 22 | LS X 23 | MD VERB 24 | NFP . 25 | NN NOUN 26 | NNP NOUN 27 | NNPS NOUN 28 | NNS NOUN 29 | PDT DET 30 | POS PRT 31 | PRP PRON 32 | PRP$ PRON 33 | RB ADV 34 | RBR ADV 35 | RBS ADV 36 | RP PRT 37 | SYM X 38 | TO PRT 39 | UH X 40 | VB VERB 41 | VBD VERB 42 | VBG VERB 43 | VBN VERB 44 | VBP VERB 45 | VBZ VERB 46 | WDT DET 47 | WP PRON 48 | WP$ PRON 49 | WRB ADV 50 | `` . 51 | X X 52 | XX X 53 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/label-map: -------------------------------------------------------------------------------- 1 | 46 2 | punct 243160 3 | prep 194627 4 | pobj 186958 5 | det 170592 6 | nsubj 144821 7 | nn 144800 8 | amod 117242 9 | ROOT 90592 10 | dobj 88551 11 | aux 76523 12 | advmod 72893 13 | conj 59384 14 | cc 57532 15 | num 36350 16 | poss 35117 17 | dep 34986 18 | ccomp 29470 19 | cop 25991 20 | mark 25141 21 | xcomp 25111 22 | rcmod 16234 23 | auxpass 15740 24 | advcl 14996 25 | possessive 14866 26 | nsubjpass 14133 27 | pcomp 12488 28 | appos 11112 29 | partmod 11106 30 | neg 11090 31 | number 10658 32 | prt 7123 33 | quantmod 6653 34 | tmod 5418 35 | infmod 5134 36 | npadvmod 3213 37 | parataxis 3012 38 | mwe 2793 39 | expl 2712 40 | iobj 1642 41 | acomp 1632 42 | discourse 1381 43 | csubj 1225 44 | predet 1160 45 | preconj 749 46 | goeswith 146 47 | csubjpass 41 48 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/parser-params: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/parser-params -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/prefix-table: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/prefix-table -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/suffix-table: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/suffix-table -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/tag-map: -------------------------------------------------------------------------------- 1 | 49 2 | NN 285194 3 | IN 228165 4 | DT 179147 5 | NNP 175147 6 | JJ 125667 7 | NNS 115732 8 | , 97481 9 | . 85938 10 | RB 78513 11 | VB 63952 12 | CC 57554 13 | VBD 56635 14 | CD 55674 15 | PRP 55244 16 | VBZ 48126 17 | VBN 44458 18 | VBG 34524 19 | VBP 33669 20 | TO 28772 21 | MD 22364 22 | PRP$ 20706 23 | HYPH 18526 24 | POS 14905 25 | `` 12193 26 | '' 12154 27 | WDT 10267 28 | : 8713 29 | $ 7993 30 | WP 7336 31 | RP 7335 32 | WRB 6634 33 | JJR 6295 34 | NNPS 5917 35 | -RRB- 3904 36 | -LRB- 3840 37 | JJS 3596 38 | RBR 3186 39 | EX 2733 40 | UH 1521 41 | RBS 1467 42 | PDT 1271 43 | FW 928 44 | NFP 844 45 | SYM 652 46 | ADD 476 47 | LS 392 48 | WP$ 332 49 | GW 184 50 | AFX 42 51 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/tagger-params: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_mcparseface/tagger-params -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_universal/context-tokenize-zh.pbtxt: -------------------------------------------------------------------------------- 1 | Parameter { 2 | name: "brain_tokenizer_zh_embedding_dims" 3 | value: "32;32" 4 | } 5 | Parameter { 6 | name: "brain_tokenizer_zh_embedding_names" 7 | value: "chars;words" 8 | } 9 | Parameter { 10 | name: "brain_tokenizer_zh_features" 11 | value: "input.char " 12 | "input(1).char " 13 | "input(2).char " 14 | "input(3).char " 15 | "input(-1).char " 16 | "input(-2).char " 17 | "input(-3).char " 18 | "stack.char " 19 | "stack.offset(1).char " 20 | "stack.offset(-1).char " 21 | "stack(1).char " 22 | "stack(1).offset(1).char " 23 | "stack(1).offset(-1).char " 24 | "stack(2).char; " 25 | "last-word(1,min-freq=2) " 26 | "last-word(2,min-freq=2) " 27 | "last-word(3,min-freq=2)" 28 | } 29 | Parameter { 30 | name: "brain_tokenizer_zh_transition_system" 31 | value: "binary-segment-transitions" 32 | } 33 | input { 34 | name: "word-map" 35 | Part { 36 | file_pattern: "last-word-map" 37 | } 38 | } 39 | input { 40 | name: "char-map" 41 | Part { 42 | file_pattern: "char-map" 43 | } 44 | } 45 | input { 46 | name: "label-map" 47 | Part { 48 | file_pattern: "label-map" 49 | } 50 | } 51 | input { 52 | name: 'stdin-untoken' 53 | record_format: 'untokenized-text' 54 | Part { 55 | file_pattern: '-' 56 | } 57 | } 58 | input { 59 | name: 'stdout-conll' 60 | record_format: 'conll-sentence' 61 | Part { 62 | file_pattern: '-' 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_universal/parse.sh: -------------------------------------------------------------------------------- 1 | # A script that runs a morphological analyzer, a part-of-speech tagger and a 2 | # dependency parser on a text file, with one sentence per line. 3 | # 4 | # Example usage: 5 | # bazel build syntaxnet:parser_eval 6 | # cat sentences.txt | 7 | # syntaxnet/models/parsey_universal/parse.sh \ 8 | # $MODEL_DIRECTORY > output.conll 9 | # 10 | # To run on a conll formatted file, add the --conll command line argument: 11 | # cat sentences.conll | 12 | # syntaxnet/models/parsey_universal/parse.sh \ 13 | # --conll $MODEL_DIRECTORY > output.conll 14 | # 15 | # Models can be downloaded from 16 | # http://download.tensorflow.org/models/parsey_universal/.zip 17 | # for the languages listed at 18 | # https://github.com/tensorflow/models/blob/master/syntaxnet/universal.md 19 | # 20 | 21 | PARSER_EVAL=bazel-bin/syntaxnet/parser_eval 22 | CONTEXT=syntaxnet/models/parsey_universal/context.pbtxt 23 | if [[ "$1" == "--conll" ]]; then 24 | INPUT_FORMAT=stdin-conll 25 | shift 26 | else 27 | INPUT_FORMAT=stdin 28 | fi 29 | MODEL_DIR=$1 30 | 31 | $PARSER_EVAL \ 32 | --input=$INPUT_FORMAT \ 33 | --output=stdout-conll \ 34 | --hidden_layer_sizes=64 \ 35 | --arg_prefix=brain_morpher \ 36 | --graph_builder=structured \ 37 | --task_context=$CONTEXT \ 38 | --resource_dir=$MODEL_DIR \ 39 | --model_path=$MODEL_DIR/morpher-params \ 40 | --slim_model \ 41 | --batch_size=1024 \ 42 | --alsologtostderr \ 43 | | \ 44 | $PARSER_EVAL \ 45 | --input=stdin-conll \ 46 | --output=stdout-conll \ 47 | --hidden_layer_sizes=64 \ 48 | --arg_prefix=brain_tagger \ 49 | --graph_builder=structured \ 50 | --task_context=$CONTEXT \ 51 | --resource_dir=$MODEL_DIR \ 52 | --model_path=$MODEL_DIR/tagger-params \ 53 | --slim_model \ 54 | --batch_size=1024 \ 55 | --alsologtostderr \ 56 | | \ 57 | $PARSER_EVAL \ 58 | --input=stdin-conll \ 59 | --output=stdout-conll \ 60 | --hidden_layer_sizes=512,512 \ 61 | --arg_prefix=brain_parser \ 62 | --graph_builder=structured \ 63 | --task_context=$CONTEXT \ 64 | --resource_dir=$MODEL_DIR \ 65 | --model_path=$MODEL_DIR/parser-params \ 66 | --slim_model \ 67 | --batch_size=1024 \ 68 | --alsologtostderr 69 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_universal/tokenize.sh: -------------------------------------------------------------------------------- 1 | # A script that runs a tokenizer on a text file with one sentence per line. 2 | # 3 | # Example usage: 4 | # bazel build syntaxnet:parser_eval 5 | # cat untokenized-sentences.txt | 6 | # syntaxnet/models/parsey_universal/tokenize.sh \ 7 | # $MODEL_DIRECTORY > output.conll 8 | # 9 | # Models can be downloaded from 10 | # http://download.tensorflow.org/models/parsey_universal/.zip 11 | # for the languages listed at 12 | # https://github.com/tensorflow/models/blob/master/syntaxnet/universal.md 13 | # 14 | 15 | PARSER_EVAL=bazel-bin/syntaxnet/parser_eval 16 | CONTEXT=syntaxnet/models/parsey_universal/context.pbtxt 17 | INPUT_FORMAT=stdin-untoken 18 | MODEL_DIR=$1 19 | 20 | $PARSER_EVAL \ 21 | --input=$INPUT_FORMAT \ 22 | --output=stdin-untoken \ 23 | --hidden_layer_sizes=128,128 \ 24 | --arg_prefix=brain_tokenizer \ 25 | --graph_builder=greedy \ 26 | --task_context=$CONTEXT \ 27 | --resource_dir=$MODEL_DIR \ 28 | --model_path=$MODEL_DIR/tokenizer-params \ 29 | --batch_size=32 \ 30 | --alsologtostderr \ 31 | --slim_model 32 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/models/parsey_universal/tokenize_zh.sh: -------------------------------------------------------------------------------- 1 | # A script that runs a traditional Chinese tokenizer on a text file with one 2 | # sentence per line. 3 | # 4 | # Example usage: 5 | # bazel build syntaxnet:parser_eval 6 | # cat untokenized-sentences.txt | 7 | # syntaxnet/models/parsey_universal/tokenize_zh.sh \ 8 | # $MODEL_DIRECTORY > output.conll 9 | # 10 | # The traditional Chinese model can be downloaded from 11 | # http://download.tensorflow.org/models/parsey_universal/Chinese.zip 12 | # 13 | 14 | PARSER_EVAL=bazel-bin/syntaxnet/parser_eval 15 | CONTEXT=syntaxnet/models/parsey_universal/context-tokenize-zh.pbtxt 16 | INPUT_FORMAT=stdin-untoken 17 | MODEL_DIR=$1 18 | 19 | $PARSER_EVAL \ 20 | --input=$INPUT_FORMAT \ 21 | --output=stdin-untoken \ 22 | --hidden_layer_sizes=256,256 \ 23 | --arg_prefix=brain_tokenizer_zh \ 24 | --graph_builder=structured \ 25 | --task_context=$CONTEXT \ 26 | --resource_dir=$MODEL_DIR \ 27 | --model_path=$MODEL_DIR/tokenizer-params \ 28 | --batch_size=1024 \ 29 | --alsologtostderr \ 30 | --slim_model 31 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/parser_transitions.cc: -------------------------------------------------------------------------------- 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 | #include "syntaxnet/parser_transitions.h" 17 | 18 | #include "syntaxnet/parser_state.h" 19 | 20 | namespace syntaxnet { 21 | 22 | // Transition system registry. 23 | REGISTER_CLASS_REGISTRY("transition system", ParserTransitionSystem); 24 | 25 | void ParserTransitionSystem::PerformAction(ParserAction action, 26 | ParserState *state) const { 27 | PerformActionWithoutHistory(action, state); 28 | } 29 | 30 | } // namespace syntaxnet 31 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/registry.cc: -------------------------------------------------------------------------------- 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 | #include "syntaxnet/registry.h" 17 | 18 | namespace syntaxnet { 19 | 20 | // Global list of all component registries. 21 | RegistryMetadata *global_registry_list = nullptr; 22 | 23 | void RegistryMetadata::Register(RegistryMetadata *registry) { 24 | registry->set_link(global_registry_list); 25 | global_registry_list = registry; 26 | } 27 | 28 | } // namespace syntaxnet 29 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/sentence.proto: -------------------------------------------------------------------------------- 1 | // Protocol buffer specification for document analysis. 2 | 3 | syntax = "proto2"; 4 | 5 | package syntaxnet; 6 | 7 | // A Sentence contains the raw text contents of a sentence, as well as an 8 | // analysis. 9 | message Sentence { 10 | // Identifier for document. 11 | optional string docid = 1; 12 | 13 | // Raw text contents of the sentence. 14 | optional string text = 2; 15 | 16 | // Tokenization of the sentence. 17 | repeated Token token = 3; 18 | 19 | extensions 1000 to max; 20 | } 21 | 22 | // A document token marks a span of bytes in the document text as a token 23 | // or word. 24 | message Token { 25 | // Token word form. 26 | required string word = 1; 27 | 28 | // Start position of token in text. 29 | required int32 start = 2; 30 | 31 | // End position of token in text. Gives index of last byte, not one past 32 | // the last byte. If token came from lexer, excludes any trailing HTML tags. 33 | required int32 end = 3; 34 | 35 | // Head of this token in the dependency tree: the id of the token which has an 36 | // arc going to this one. If it is the root token of a sentence, then it is 37 | // set to -1. 38 | optional int32 head = 4 [default = -1]; 39 | 40 | // Part-of-speech tag for token. 41 | optional string tag = 5; 42 | 43 | // Coarse-grained word category for token. 44 | optional string category = 6; 45 | 46 | // Label for dependency relation between this token and its head. 47 | optional string label = 7; 48 | 49 | // Break level for tokens that indicates how it was separated from the 50 | // previous token in the text. 51 | enum BreakLevel { 52 | NO_BREAK = 0; // No separation between tokens. 53 | SPACE_BREAK = 1; // Tokens separated by space. 54 | LINE_BREAK = 2; // Tokens separated by line break. 55 | SENTENCE_BREAK = 3; // Tokens separated by sentence break. 56 | } 57 | 58 | optional BreakLevel break_level = 8 [default = SPACE_BREAK]; 59 | 60 | extensions 1000 to max; 61 | } 62 | 63 | // Stores information about the morphology of a token. 64 | message TokenMorphology { 65 | extend Token { 66 | optional TokenMorphology morphology = 63949837; 67 | } 68 | 69 | // Morphology is represented by a set of attribute values. 70 | message Attribute { 71 | required string name = 1; 72 | required string value = 2; 73 | } 74 | // This attribute field is designated to hold a single disambiguated analysis. 75 | repeated Attribute attribute = 3; 76 | }; 77 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/sentence_batch.cc: -------------------------------------------------------------------------------- 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 | #include "syntaxnet/sentence_batch.h" 17 | 18 | #include 19 | #include 20 | #include 21 | 22 | #include "syntaxnet/task_context.h" 23 | 24 | namespace syntaxnet { 25 | 26 | void SentenceBatch::Init(TaskContext *context) { 27 | reader_.reset(new TextReader(*context->GetInput(input_name_), context)); 28 | size_ = 0; 29 | } 30 | 31 | bool SentenceBatch::AdvanceSentence(int index) { 32 | if (sentences_[index] == nullptr) ++size_; 33 | sentences_[index].reset(); 34 | std::unique_ptr sentence(reader_->Read()); 35 | if (sentence == nullptr) { 36 | --size_; 37 | return false; 38 | } 39 | 40 | // Preprocess the new sentence for the parser state. 41 | sentences_[index] = std::move(sentence); 42 | return true; 43 | } 44 | 45 | } // namespace syntaxnet 46 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/sparse.proto: -------------------------------------------------------------------------------- 1 | // Protocol for passing around sparse sets of features. 2 | 3 | syntax = "proto2"; 4 | 5 | package syntaxnet; 6 | 7 | // A sparse set of features. 8 | // 9 | // If using SparseStringToIdTransformer, description is required and id should 10 | // be omitted; otherwise, id is required and description optional. 11 | // 12 | // id, weight, and description fields are all aligned if present (ie, any of 13 | // these that are non-empty should have the same # items). If weight is omitted, 14 | // 1.0 is used. 15 | message SparseFeatures { 16 | repeated uint64 id = 1; 17 | repeated float weight = 2; 18 | repeated string description = 3; 19 | }; 20 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/task_spec.proto: -------------------------------------------------------------------------------- 1 | // LINT: ALLOW_GROUPS 2 | // Protocol buffer specifications for task configuration. 3 | 4 | syntax = "proto2"; 5 | 6 | package syntaxnet; 7 | 8 | // Task input descriptor. 9 | message TaskInput { 10 | // Name of input resource. 11 | required string name = 1; 12 | 13 | // Name of stage responsible of creating this resource. 14 | optional string creator = 2; 15 | 16 | // File format for resource. 17 | repeated string file_format = 3; 18 | 19 | // Record format for resource. 20 | repeated string record_format = 4; 21 | 22 | // Is this resource multi-file? 23 | optional bool multi_file = 5 [default = false]; 24 | 25 | // An input can consist of multiple file sets. 26 | repeated group Part = 6 { 27 | // File pattern for file set. 28 | optional string file_pattern = 7; 29 | 30 | // File format for file set. 31 | optional string file_format = 8; 32 | 33 | // Record format for file set. 34 | optional string record_format = 9; 35 | } 36 | } 37 | 38 | // Task output descriptor. 39 | message TaskOutput { 40 | // Name of output resource. 41 | required string name = 1; 42 | 43 | // File format for output resource. 44 | optional string file_format = 2; 45 | 46 | // Record format for output resource. 47 | optional string record_format = 3; 48 | 49 | // Number of shards in output. If it is different from zero this output is 50 | // sharded. If the number of shards is set to -1 this means that the output is 51 | // sharded, but the number of shard is unknown. The files are then named 52 | // 'base-*-of-*'. 53 | optional int32 shards = 4 [default = 0]; 54 | 55 | // Base file name for output resource. If this is not set by the task 56 | // component it is set to a default value by the workflow engine. 57 | optional string file_base = 5; 58 | 59 | // Optional extension added to the file name. 60 | optional string file_extension = 6; 61 | } 62 | 63 | // A task specification is used for describing executing parameters. 64 | message TaskSpec { 65 | // Name of task. 66 | optional string task_name = 1; 67 | 68 | // Workflow task type. 69 | optional string task_type = 2; 70 | 71 | // Task parameters. 72 | repeated group Parameter = 3 { 73 | required string name = 4; 74 | optional string value = 5; 75 | } 76 | 77 | // Task inputs. 78 | repeated TaskInput input = 6; 79 | 80 | // Task outputs. 81 | repeated TaskOutput output = 7; 82 | } 83 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/test_main.cc: -------------------------------------------------------------------------------- 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 | // A program with a main that is suitable for unittests, including those 17 | // that also define microbenchmarks. Based on whether the user specified 18 | // the --benchmark_filter flag which specifies which benchmarks to run, 19 | // we will either run benchmarks or run the gtest tests in the program. 20 | 21 | #include "tensorflow/core/platform/platform.h" 22 | #include "tensorflow/core/platform/types.h" 23 | 24 | #if defined(PLATFORM_GOOGLE) || defined(__ANDROID__) 25 | 26 | // main() is supplied by gunit_main 27 | #else 28 | #include "gtest/gtest.h" 29 | #include "tensorflow/core/lib/core/stringpiece.h" 30 | #include "tensorflow/core/platform/test_benchmark.h" 31 | 32 | GTEST_API_ int main(int argc, char **argv) { 33 | std::cout << "Running main() from test_main.cc\n"; 34 | 35 | testing::InitGoogleTest(&argc, argv); 36 | for (int i = 1; i < argc; i++) { 37 | if (tensorflow::StringPiece(argv[i]).starts_with("--benchmarks=")) { 38 | const char *pattern = argv[i] + strlen("--benchmarks="); 39 | tensorflow::testing::Benchmark::Run(pattern); 40 | return 0; 41 | } 42 | } 43 | return RUN_ALL_TESTS(); 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/testdata/context.pbtxt: -------------------------------------------------------------------------------- 1 | Parameter { 2 | name: 'brain_parser_embedding_dims' 3 | value: '8;8;8' 4 | } 5 | Parameter { 6 | name: 'brain_parser_features' 7 | value: 'input.token.word input(1).token.word input(2).token.word stack.token.word stack(1).token.word stack(2).token.word;input.tag input(1).tag input(2).tag stack.tag stack(1).tag stack(2).tag;stack.child(1).label stack.child(1).sibling(-1).label stack.child(-1).label stack.child(-1).sibling(1).label' 8 | } 9 | Parameter { 10 | name: 'brain_parser_embedding_names' 11 | value: 'words;tags;labels' 12 | } 13 | input { 14 | name: 'training-corpus' 15 | record_format: 'conll-sentence' 16 | Part { 17 | file_pattern: 'syntaxnet/testdata/mini-training-set' 18 | } 19 | } 20 | input { 21 | name: 'tuning-corpus' 22 | record_format: 'conll-sentence' 23 | Part { 24 | file_pattern: 'syntaxnet/testdata/mini-training-set' 25 | } 26 | } 27 | input { 28 | name: 'parsed-tuning-corpus' 29 | creator: 'brain_parser/greedy' 30 | record_format: 'conll-sentence' 31 | } 32 | input { 33 | name: 'label-map' 34 | file_format: 'text' 35 | Part { 36 | file_pattern: 'OUTPATH/label-map' 37 | } 38 | } 39 | input { 40 | name: 'word-map' 41 | Part { 42 | file_pattern: 'OUTPATH/word-map' 43 | } 44 | } 45 | input { 46 | name: 'lcword-map' 47 | Part { 48 | file_pattern: 'OUTPATH/lcword-map' 49 | } 50 | } 51 | input { 52 | name: 'tag-map' 53 | Part { 54 | file_pattern: 'OUTPATH/tag-map' 55 | } 56 | } 57 | input { 58 | name: 'category-map' 59 | Part { 60 | file_pattern: 'OUTPATH/category-map' 61 | } 62 | } 63 | input { 64 | name: 'char-map' 65 | Part { 66 | file_pattern: 'OUTPATH/char-map' 67 | } 68 | } 69 | input { 70 | name: 'prefix-table' 71 | Part { 72 | file_pattern: 'OUTPATH/prefix-table' 73 | } 74 | } 75 | input { 76 | name: 'suffix-table' 77 | Part { 78 | file_pattern: 'OUTPATH/suffix-table' 79 | } 80 | } 81 | input { 82 | name: 'tag-to-category' 83 | Part { 84 | file_pattern: 'OUTPATH/tag-to-category' 85 | } 86 | } 87 | input { 88 | name: 'stdout' 89 | record_format: 'conll-sentence' 90 | Part { 91 | file_pattern: '-' 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/syntaxnet/workspace.cc: -------------------------------------------------------------------------------- 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 | #include "syntaxnet/workspace.h" 17 | 18 | #include "tensorflow/core/lib/strings/strcat.h" 19 | 20 | namespace syntaxnet { 21 | 22 | string WorkspaceRegistry::DebugString() const { 23 | string str; 24 | for (auto &it : workspace_names_) { 25 | const string &type_name = workspace_types_.at(it.first); 26 | for (size_t index = 0; index < it.second.size(); ++index) { 27 | const string &workspace_name = it.second[index]; 28 | tensorflow::strings::StrAppend(&str, "\n ", type_name, " :: ", 29 | workspace_name); 30 | } 31 | } 32 | return str; 33 | } 34 | 35 | VectorIntWorkspace::VectorIntWorkspace(int size) : elements_(size) {} 36 | 37 | VectorIntWorkspace::VectorIntWorkspace(int size, int value) 38 | : elements_(size, value) {} 39 | 40 | VectorIntWorkspace::VectorIntWorkspace(const vector &elements) 41 | : elements_(elements) {} 42 | 43 | string VectorIntWorkspace::TypeName() { return "Vector"; } 44 | 45 | VectorVectorIntWorkspace::VectorVectorIntWorkspace(int size) 46 | : elements_(size) {} 47 | 48 | string VectorVectorIntWorkspace::TypeName() { return "VectorVector"; } 49 | 50 | } // namespace syntaxnet 51 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/BUILD: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | cc_library( 4 | name = "utf", 5 | srcs = [ 6 | "rune.c", 7 | "runestrcat.c", 8 | "runestrchr.c", 9 | "runestrcmp.c", 10 | "runestrcpy.c", 11 | "runestrdup.c", 12 | "runestrecpy.c", 13 | "runestrlen.c", 14 | "runestrncat.c", 15 | "runestrncmp.c", 16 | "runestrncpy.c", 17 | "runestrrchr.c", 18 | "runestrstr.c", 19 | "runetype.c", 20 | "utfecpy.c", 21 | "utflen.c", 22 | "utfnlen.c", 23 | "utfrrune.c", 24 | "utfrune.c", 25 | "utfutf.c", 26 | ], 27 | hdrs = [ 28 | "runetypebody.c", 29 | "utf.h", 30 | "utfdef.h", 31 | ], 32 | includes = ["."], 33 | visibility = ["//visibility:public"], 34 | ) 35 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/README: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 1998-2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrcat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | Rune* 20 | runestrcat(Rune *s1, const Rune *s2) 21 | { 22 | 23 | runestrcpy((Rune*)runestrchr(s1, 0), s2); 24 | return s1; 25 | } 26 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | const 20 | Rune* 21 | runestrchr(const Rune *s, Rune c) 22 | { 23 | Rune c0 = c; 24 | Rune c1; 25 | 26 | if(c == 0) { 27 | while(*s++) 28 | ; 29 | return s-1; 30 | } 31 | 32 | while((c1 = *s++) != 0) 33 | if(c1 == c0) 34 | return s-1; 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrcmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | int 20 | runestrcmp(const Rune *s1, const Rune *s2) 21 | { 22 | Rune c1, c2; 23 | 24 | for(;;) { 25 | c1 = *s1++; 26 | c2 = *s2++; 27 | if(c1 != c2) { 28 | if(c1 > c2) 29 | return 1; 30 | return -1; 31 | } 32 | if(c1 == 0) 33 | return 0; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrcpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | Rune* 20 | runestrcpy(Rune *s1, const Rune *s2) 21 | { 22 | Rune *os1; 23 | 24 | os1 = s1; 25 | while((*s1++ = *s2++) != 0) 26 | ; 27 | return os1; 28 | } 29 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrdup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include 17 | #include "third_party/utf/utf.h" 18 | #include "third_party/utf/utfdef.h" 19 | 20 | Rune* 21 | runestrdup(const Rune *s) 22 | { 23 | Rune *ns; 24 | 25 | ns = (Rune*)malloc(sizeof(Rune)*(runestrlen(s) + 1)); 26 | if(ns == 0) 27 | return 0; 28 | 29 | return runestrcpy(ns, s); 30 | } 31 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrecpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | Rune* 20 | runestrecpy(Rune *s1, Rune *es1, const Rune *s2) 21 | { 22 | if(s1 >= es1) 23 | return s1; 24 | 25 | while((*s1++ = *s2++) != 0){ 26 | if(s1 == es1){ 27 | *--s1 = '\0'; 28 | break; 29 | } 30 | } 31 | return s1; 32 | } 33 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | long 20 | runestrlen(const Rune *s) 21 | { 22 | 23 | return runestrchr(s, 0) - s; 24 | } 25 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrncat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | Rune* 20 | runestrncat(Rune *s1, const Rune *s2, long n) 21 | { 22 | Rune *os1; 23 | 24 | os1 = s1; 25 | s1 = (Rune*)runestrchr(s1, 0); 26 | while((*s1++ = *s2++) != 0) 27 | if(--n < 0) { 28 | s1[-1] = 0; 29 | break; 30 | } 31 | return os1; 32 | } 33 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrncmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | int 20 | runestrncmp(const Rune *s1, const Rune *s2, long n) 21 | { 22 | Rune c1, c2; 23 | 24 | while(n > 0) { 25 | c1 = *s1++; 26 | c2 = *s2++; 27 | n--; 28 | if(c1 != c2) { 29 | if(c1 > c2) 30 | return 1; 31 | return -1; 32 | } 33 | if(c1 == 0) 34 | break; 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrncpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | Rune* 20 | runestrncpy(Rune *s1, const Rune *s2, long n) 21 | { 22 | int i; 23 | Rune *os1; 24 | 25 | os1 = s1; 26 | for(i = 0; i < n; i++) 27 | if((*s1++ = *s2++) == 0) { 28 | while(++i < n) 29 | *s1++ = 0; 30 | return os1; 31 | } 32 | return os1; 33 | } 34 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrrchr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | const 20 | Rune* 21 | runestrrchr(const Rune *s, Rune c) 22 | { 23 | const Rune *r; 24 | 25 | if(c == 0) 26 | return runestrchr(s, 0); 27 | r = 0; 28 | while((s = runestrchr(s, c)) != 0) 29 | r = s++; 30 | return r; 31 | } 32 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runestrstr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | /* 20 | * Return pointer to first occurrence of s2 in s1, 21 | * 0 if none 22 | */ 23 | const 24 | Rune* 25 | runestrstr(const Rune *s1, const Rune *s2) 26 | { 27 | const Rune *p, *pa, *pb; 28 | int c0, c; 29 | 30 | c0 = *s2; 31 | if(c0 == 0) 32 | return s1; 33 | s2++; 34 | for(p=runestrchr(s1, c0); p; p=runestrchr(p+1, c0)) { 35 | pa = p; 36 | for(pb=s2;; pb++) { 37 | c = *pb; 38 | if(c == 0) 39 | return p; 40 | if(c != *++pa) 41 | break; 42 | } 43 | } 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/runetype.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include "third_party/utf/utf.h" 15 | #include "third_party/utf/utfdef.h" 16 | 17 | static 18 | Rune* 19 | rbsearch(Rune c, Rune *t, int n, int ne) 20 | { 21 | Rune *p; 22 | int m; 23 | 24 | while(n > 1) { 25 | m = n >> 1; 26 | p = t + m*ne; 27 | if(c >= p[0]) { 28 | t = p; 29 | n = n-m; 30 | } else 31 | n = m; 32 | } 33 | if(n && c >= t[0]) 34 | return t; 35 | return 0; 36 | } 37 | 38 | /* 39 | * The "ideographic" property is hard to extract from UnicodeData.txt, 40 | * so it is hard coded here. 41 | * 42 | * It is defined in the Unicode PropList.txt file, for example 43 | * PropList-3.0.0.txt. Unlike the UnicodeData.txt file, the format of 44 | * PropList changes between versions. This property appears relatively static; 45 | * it is the same in version 4.0.1, except that version defines some >16 bit 46 | * chars as ideographic as well: 20000..2a6d6, and 2f800..2Fa1d. 47 | */ 48 | static Rune __isideographicr[] = { 49 | 0x3006, 0x3007, /* 3006 not in Unicode 2, in 2.1 */ 50 | 0x3021, 0x3029, 51 | 0x3038, 0x303a, /* not in Unicode 2 or 2.1 */ 52 | 0x3400, 0x4db5, /* not in Unicode 2 or 2.1 */ 53 | 0x4e00, 0x9fbb, /* 0x9FA6..0x9FBB added for 4.1.0? */ 54 | 0xf900, 0xfa2d, 55 | 0x20000, 0x2A6D6, 56 | 0x2F800, 0x2FA1D, 57 | }; 58 | 59 | int 60 | isideographicrune(Rune c) 61 | { 62 | Rune *p; 63 | 64 | p = rbsearch(c, __isideographicr, nelem(__isideographicr)/2, 2); 65 | if(p && c >= p[0] && c <= p[1]) 66 | return 1; 67 | return 0; 68 | } 69 | 70 | #include "third_party/utf/runetypebody.c" 71 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/utfdef.h: -------------------------------------------------------------------------------- 1 | #define uchar _utfuchar 2 | #define ushort _utfushort 3 | #define uint _utfuint 4 | #define ulong _utfulong 5 | #define vlong _utfvlong 6 | #define uvlong _utfuvlong 7 | 8 | typedef unsigned char uchar; 9 | typedef unsigned short ushort; 10 | typedef unsigned int uint; 11 | typedef unsigned long ulong; 12 | 13 | #define nelem(x) (sizeof(x)/sizeof((x)[0])) 14 | #define nil ((void*)0) 15 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/utfecpy.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | char* 20 | utfecpy(char *to, char *e, const char *from) 21 | { 22 | char *end; 23 | 24 | if(to >= e) 25 | return to; 26 | end = (char*)memccpy(to, from, '\0', e - to); 27 | if(end == nil){ 28 | end = e-1; 29 | while(end>to && (*--end&0xC0)==0x80) 30 | ; 31 | *end = '\0'; 32 | }else{ 33 | end--; 34 | } 35 | return end; 36 | } 37 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/utflen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | int 20 | utflen(const char *s) 21 | { 22 | int c; 23 | long n; 24 | Rune rune; 25 | 26 | n = 0; 27 | for(;;) { 28 | c = *(uchar*)s; 29 | if(c < Runeself) { 30 | if(c == 0) 31 | return n; 32 | s++; 33 | } else 34 | s += chartorune(&rune, s); 35 | n++; 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/utfnlen.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | int 20 | utfnlen(const char *s, long m) 21 | { 22 | int c; 23 | long n; 24 | Rune rune; 25 | const char *es; 26 | 27 | es = s + m; 28 | for(n = 0; s < es; n++) { 29 | c = *(uchar*)s; 30 | if(c < Runeself){ 31 | if(c == '\0') 32 | break; 33 | s++; 34 | continue; 35 | } 36 | if(!fullrune(s, es-s)) 37 | break; 38 | s += chartorune(&rune, s); 39 | } 40 | return n; 41 | } 42 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/utfrrune.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | const 20 | char* 21 | utfrrune(const char *s, Rune c) 22 | { 23 | long c1; 24 | Rune r; 25 | const char *s1; 26 | 27 | if(c < Runesync) /* not part of utf sequence */ 28 | return strrchr(s, c); 29 | 30 | s1 = 0; 31 | for(;;) { 32 | c1 = *(uchar*)s; 33 | if(c1 < Runeself) { /* one byte rune */ 34 | if(c1 == 0) 35 | return s1; 36 | if(c1 == c) 37 | s1 = s; 38 | s++; 39 | continue; 40 | } 41 | c1 = chartorune(&r, s); 42 | if(r == c) 43 | s1 = s; 44 | s += c1; 45 | } 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/utfrune.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | const 20 | char* 21 | utfrune(const char *s, Rune c) 22 | { 23 | long c1; 24 | Rune r; 25 | int n; 26 | 27 | if(c < Runesync) /* not part of utf sequence */ 28 | return strchr(s, c); 29 | 30 | for(;;) { 31 | c1 = *(uchar*)s; 32 | if(c1 < Runeself) { /* one byte rune */ 33 | if(c1 == 0) 34 | return 0; 35 | if(c1 == c) 36 | return s; 37 | s++; 38 | continue; 39 | } 40 | n = chartorune(&r, s); 41 | if(r == c) 42 | return s; 43 | s += n; 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/third_party/utf/utfutf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * The authors of this software are Rob Pike and Ken Thompson. 3 | * Copyright (c) 2002 by Lucent Technologies. 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose without fee is hereby granted, provided that this entire notice 6 | * is included in all copies of any software which is or includes a copy 7 | * or modification of this software and in all copies of the supporting 8 | * documentation for such software. 9 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED 10 | * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES MAKE ANY 11 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY 12 | * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. 13 | */ 14 | #include 15 | #include 16 | #include "third_party/utf/utf.h" 17 | #include "third_party/utf/utfdef.h" 18 | 19 | 20 | /* 21 | * Return pointer to first occurrence of s2 in s1, 22 | * 0 if none 23 | */ 24 | const 25 | char* 26 | utfutf(const char *s1, const char *s2) 27 | { 28 | const char *p; 29 | long f, n1, n2; 30 | Rune r; 31 | 32 | n1 = chartorune(&r, s2); 33 | f = r; 34 | if(f <= Runesync) /* represents self */ 35 | return strstr(s1, s2); 36 | 37 | n2 = strlen(s2); 38 | for(p=s1; (p=utfrune(p, f)) != 0; p+=n1) 39 | if(strncmp(p, s2, n2) == 0) 40 | return p; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/tools/bazel.rc: -------------------------------------------------------------------------------- 1 | build:cuda --crosstool_top=//third_party/gpus/crosstool 2 | 3 | build --define=use_fast_cpp_protos=true 4 | build --define=allow_oversize_protos=true 5 | build --copt -funsigned-char 6 | build -c opt 7 | 8 | build --spawn_strategy=standalone 9 | test --spawn_strategy=standalone 10 | run --spawn_strategy=standalone 11 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/util/utf8/BUILD: -------------------------------------------------------------------------------- 1 | licenses(["notice"]) 2 | 3 | # Requires --copt -funsigned-char when compiling (unsigned chars). 4 | 5 | cc_library( 6 | name = "unicodetext", 7 | srcs = [ 8 | "unicodetext.cc", 9 | "unilib.cc", 10 | ], 11 | hdrs = [ 12 | "unicodetext.h", 13 | "unilib.h", 14 | "unilib_utf8_utils.h", 15 | ], 16 | visibility = ["//visibility:public"], 17 | deps = [ 18 | "//syntaxnet:base", 19 | "//third_party/utf", 20 | ], 21 | ) 22 | 23 | cc_test( 24 | name = "unicodetext_unittest", 25 | srcs = [ 26 | "gtest_main.cc", 27 | "unicodetext_unittest.cc", 28 | ], 29 | deps = [ 30 | "@org_tensorflow//tensorflow/core:testlib", 31 | ":unicodetext", 32 | ], 33 | ) 34 | 35 | cc_binary( 36 | name = "unicodetext_main", 37 | srcs = ["unicodetext_main.cc"], 38 | deps = [":unicodetext"], 39 | ) 40 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/util/utf8/gtest_main.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Google Inc. 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 | // Author: sligocki@google.com (Shawn Ligocki) 18 | // 19 | // Build all tests with this main to run all tests. 20 | 21 | #include "gtest/gtest.h" 22 | 23 | int main(int argc, char **argv) { 24 | ::testing::InitGoogleTest(&argc, argv); 25 | return RUN_ALL_TESTS(); 26 | } 27 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/util/utf8/unicodetext_main.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Google Inc. 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 | // Author: sligocki@google.com (Shawn Ligocki) 18 | // 19 | // A basic main function to test that UnicodeText builds. 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | 26 | #include "util/utf8/unicodetext.h" 27 | 28 | int main(int argc, char** argv) { 29 | if (argc > 1) { 30 | printf("Bytes:\n"); 31 | std::string bytes(argv[1]); 32 | for (std::string::const_iterator iter = bytes.begin(); 33 | iter < bytes.end(); ++iter) { 34 | printf(" 0x%02X\n", *iter); 35 | } 36 | 37 | printf("Unicode codepoints:\n"); 38 | UnicodeText text(UTF8ToUnicodeText(bytes)); 39 | for (UnicodeText::const_iterator iter = text.begin(); 40 | iter < text.end(); ++iter) { 41 | printf(" U+%X\n", *iter); 42 | } 43 | } 44 | return EXIT_SUCCESS; 45 | } 46 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/util/utf8/unilib.cc: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Google Inc. 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 | // Author: sligocki@google.com (Shawn Ligocki) 18 | 19 | #include "util/utf8/unilib.h" 20 | 21 | #include "syntaxnet/base.h" 22 | #include "third_party/utf/utf.h" 23 | 24 | namespace UniLib { 25 | 26 | // Codepoints not allowed for interchange are: 27 | // C0 (ASCII) controls: U+0000 to U+001F excluding Space (SP, U+0020), 28 | // Horizontal Tab (HT, U+0009), Line-Feed (LF, U+000A), 29 | // Form Feed (FF, U+000C) and Carriage-Return (CR, U+000D) 30 | // C1 controls: U+007F to U+009F 31 | // Surrogates: U+D800 to U+DFFF 32 | // Non-characters: U+FDD0 to U+FDEF and U+xxFFFE to U+xxFFFF for all xx 33 | bool IsInterchangeValid(char32 c) { 34 | return !((c >= 0x00 && c <= 0x08) || c == 0x0B || (c >= 0x0E && c <= 0x1F) || 35 | (c >= 0x7F && c <= 0x9F) || 36 | (c >= 0xD800 && c <= 0xDFFF) || 37 | (c >= 0xFDD0 && c <= 0xFDEF) || (c&0xFFFE) == 0xFFFE); 38 | } 39 | 40 | int SpanInterchangeValid(const char* begin, int byte_length) { 41 | char32 rune; 42 | const char* p = begin; 43 | const char* end = begin + byte_length; 44 | while (p < end) { 45 | int bytes_consumed = charntorune(&rune, p, end - p); 46 | // We want to accept Runeerror == U+FFFD as a valid char, but it is used 47 | // by chartorune to indicate error. Luckily, the real codepoint is size 3 48 | // while errors return bytes_consumed <= 1. 49 | if ((rune == Runeerror && bytes_consumed <= 1) || 50 | !IsInterchangeValid(rune)) { 51 | break; // Found 52 | } 53 | p += bytes_consumed; 54 | } 55 | return p - begin; 56 | } 57 | 58 | } // namespace UniLib 59 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/util/utf8/unilib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Google Inc. 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 | // Routines to do manipulation of Unicode characters or text 18 | // 19 | // The StructurallyValid routines accept buffers of arbitrary bytes. 20 | // For CoerceToStructurallyValid(), the input buffer and output buffers may 21 | // point to exactly the same memory. 22 | // 23 | // In all other cases, the UTF-8 string must be structurally valid and 24 | // have all codepoints in the range U+0000 to U+D7FF or U+E000 to U+10FFFF. 25 | // Debug builds take a fatal error for invalid UTF-8 input. 26 | // The input and output buffers may not overlap at all. 27 | // 28 | // The char32 routines are here only for convenience; they convert to UTF-8 29 | // internally and use the UTF-8 routines. 30 | 31 | #ifndef UTIL_UTF8_UNILIB_H__ 32 | #define UTIL_UTF8_UNILIB_H__ 33 | 34 | #include 35 | #include "syntaxnet/base.h" 36 | 37 | // We export OneCharLen, IsValidCodepoint, and IsTrailByte from here, 38 | // but they are defined in unilib_utf8_utils.h. 39 | //#include "util/utf8/public/unilib_utf8_utils.h" // IWYU pragma: export 40 | 41 | namespace UniLib { 42 | 43 | // Returns the length in bytes of the prefix of src that is all 44 | // interchange valid UTF-8 45 | int SpanInterchangeValid(const char* src, int byte_length); 46 | inline int SpanInterchangeValid(const std::string& src) { 47 | return SpanInterchangeValid(src.data(), src.size()); 48 | } 49 | 50 | // Returns true if the source is all interchange valid UTF-8 51 | // "Interchange valid" is a stronger than structurally valid -- 52 | // no C0 or C1 control codes (other than CR LF HT FF) and no non-characters. 53 | bool IsInterchangeValid(char32 codepoint); 54 | inline bool IsInterchangeValid(const char* src, int byte_length) { 55 | return (byte_length == SpanInterchangeValid(src, byte_length)); 56 | } 57 | inline bool IsInterchangeValid(const std::string& src) { 58 | return IsInterchangeValid(src.data(), src.size()); 59 | } 60 | 61 | } // namespace UniLib 62 | 63 | #endif // UTIL_UTF8_PUBLIC_UNILIB_H_ 64 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/syntaxnet/util/utf8/unilib_utf8_utils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2010 Google Inc. 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 | #ifndef UTIL_UTF8_PUBLIC_UNILIB_UTF8_UTILS_H_ 18 | #define UTIL_UTF8_PUBLIC_UNILIB_UTF8_UTILS_H_ 19 | 20 | // These definitions are self-contained and have no dependencies. 21 | // They are also exported from unilib.h for legacy reasons. 22 | 23 | #include "syntaxnet/base.h" 24 | #include "third_party/utf/utf.h" 25 | 26 | namespace UniLib { 27 | 28 | // Returns true if 'c' is in the range [0, 0xD800) or [0xE000, 0x10FFFF] 29 | // (i.e., is not a surrogate codepoint). See also 30 | // IsValidCodepoint(const char* src) in util/utf8/public/unilib.h. 31 | inline bool IsValidCodepoint(char32 c) { 32 | return (static_cast(c) < 0xD800) 33 | || (c >= 0xE000 && c <= 0x10FFFF); 34 | } 35 | 36 | // Returns true if 'str' is the start of a structurally valid UTF-8 37 | // sequence and is not a surrogate codepoint. Returns false if str.empty() 38 | // or if str.length() < UniLib::OneCharLen(str[0]). Otherwise, this function 39 | // will access 1-4 bytes of src, where n is UniLib::OneCharLen(src[0]). 40 | inline bool IsUTF8ValidCodepoint(StringPiece str) { 41 | char32 c; 42 | int consumed; 43 | // It's OK if str.length() > consumed. 44 | return !str.empty() 45 | && isvalidcharntorune(str.data(), str.size(), &c, &consumed) 46 | && IsValidCodepoint(c); 47 | } 48 | 49 | // Returns the length (number of bytes) of the Unicode code point 50 | // starting at src, based on inspecting just that one byte. This 51 | // requires that src point to a well-formed UTF-8 string; the result 52 | // is undefined otherwise. 53 | inline int OneCharLen(const char* src) { 54 | return "\1\1\1\1\1\1\1\1\1\1\1\1\2\2\3\4"[(*src & 0xFF) >> 4]; 55 | } 56 | 57 | // Returns true if this byte is a trailing UTF-8 byte (10xx xxxx) 58 | inline bool IsTrailByte(char x) { 59 | // return (x & 0xC0) == 0x80; 60 | // Since trail bytes are always in [0x80, 0xBF], we can optimize: 61 | return static_cast(x) < -0x40; 62 | } 63 | 64 | } // namespace UniLib 65 | 66 | #endif // UTIL_UTF8_PUBLIC_UNILIB_UTF8_UTILS_H_ 67 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/textsum/BUILD: -------------------------------------------------------------------------------- 1 | package(default_visibility = [":internal"]) 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | exports_files(["LICENSE"]) 6 | 7 | package_group( 8 | name = "internal", 9 | packages = [ 10 | "//textsum/...", 11 | ], 12 | ) 13 | 14 | py_library( 15 | name = "seq2seq_attention_model", 16 | srcs = ["seq2seq_attention_model.py"], 17 | deps = [ 18 | ":seq2seq_lib", 19 | ], 20 | ) 21 | 22 | py_library( 23 | name = "seq2seq_lib", 24 | srcs = ["seq2seq_lib.py"], 25 | ) 26 | 27 | py_binary( 28 | name = "seq2seq_attention", 29 | srcs = ["seq2seq_attention.py"], 30 | deps = [ 31 | ":batch_reader", 32 | ":data", 33 | ":seq2seq_attention_decode", 34 | ":seq2seq_attention_model", 35 | ], 36 | ) 37 | 38 | py_library( 39 | name = "batch_reader", 40 | srcs = ["batch_reader.py"], 41 | deps = [ 42 | ":data", 43 | ":seq2seq_attention_model", 44 | ], 45 | ) 46 | 47 | py_library( 48 | name = "beam_search", 49 | srcs = ["beam_search.py"], 50 | ) 51 | 52 | py_library( 53 | name = "seq2seq_attention_decode", 54 | srcs = ["seq2seq_attention_decode.py"], 55 | deps = [ 56 | ":beam_search", 57 | ":data", 58 | ], 59 | ) 60 | 61 | py_library( 62 | name = "data", 63 | srcs = ["data.py"], 64 | ) 65 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/textsum/data/data: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/TSN/tf_model_zoo/models/textsum/data/data -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/textsum/data_convert_example.py: -------------------------------------------------------------------------------- 1 | """Example of Converting TextSum model data. 2 | Usage: 3 | python data_convert_example.py --command binary_to_text --in_file data/data --out_file data/text_data 4 | python data_convert_example.py --command text_to_binary --in_file data/text_data --out_file data/binary_data 5 | python data_convert_example.py --command binary_to_text --in_file data/binary_data --out_file data/text_data2 6 | diff data/text_data2 data/text_data 7 | """ 8 | 9 | import struct 10 | import sys 11 | 12 | import tensorflow as tf 13 | from tensorflow.core.example import example_pb2 14 | 15 | FLAGS = tf.app.flags.FLAGS 16 | tf.app.flags.DEFINE_string('command', 'binary_to_text', 17 | 'Either binary_to_text or text_to_binary.' 18 | 'Specify FLAGS.in_file accordingly.') 19 | tf.app.flags.DEFINE_string('in_file', '', 'path to file') 20 | tf.app.flags.DEFINE_string('out_file', '', 'path to file') 21 | 22 | def _binary_to_text(): 23 | reader = open(FLAGS.in_file, 'rb') 24 | writer = open(FLAGS.out_file, 'w') 25 | while True: 26 | len_bytes = reader.read(8) 27 | if not len_bytes: 28 | sys.stderr.write('Done reading\n') 29 | return 30 | str_len = struct.unpack('q', len_bytes)[0] 31 | tf_example_str = struct.unpack('%ds' % str_len, reader.read(str_len))[0] 32 | tf_example = example_pb2.Example.FromString(tf_example_str) 33 | examples = [] 34 | for key in tf_example.features.feature: 35 | examples.append('%s=%s' % (key, tf_example.features.feature[key].bytes_list.value[0])) 36 | writer.write('%s\n' % '\t'.join(examples)) 37 | reader.close() 38 | writer.close() 39 | 40 | 41 | def _text_to_binary(): 42 | inputs = open(FLAGS.in_file, 'r').readlines() 43 | writer = open(FLAGS.out_file, 'wb') 44 | for inp in inputs: 45 | tf_example = example_pb2.Example() 46 | for feature in inp.strip().split('\t'): 47 | (k, v) = feature.split('=') 48 | tf_example.features.feature[k].bytes_list.value.extend([v]) 49 | tf_example_str = tf_example.SerializeToString() 50 | str_len = len(tf_example_str) 51 | writer.write(struct.pack('q', str_len)) 52 | writer.write(struct.pack('%ds' % str_len, tf_example_str)) 53 | writer.close() 54 | 55 | 56 | def main(unused_argv): 57 | assert FLAGS.command and FLAGS.in_file and FLAGS.out_file 58 | if FLAGS.command == 'binary_to_text': 59 | _binary_to_text() 60 | elif FLAGS.command == 'text_to_binary': 61 | _text_to_binary() 62 | 63 | 64 | if __name__ == '__main__': 65 | tf.app.run() 66 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/transformer/README.md: -------------------------------------------------------------------------------- 1 | # Spatial Transformer Network 2 | 3 | The Spatial Transformer Network [1] allows the spatial manipulation of data within the network. 4 | 5 |
6 |

7 |
8 | 9 | ### API 10 | 11 | A Spatial Transformer Network implemented in Tensorflow 0.7 and based on [2]. 12 | 13 | #### How to use 14 | 15 |
16 |

17 |
18 | 19 | ```python 20 | transformer(U, theta, out_size) 21 | ``` 22 | 23 | #### Parameters 24 | 25 | U : float 26 | The output of a convolutional net should have the 27 | shape [num_batch, height, width, num_channels]. 28 | theta: float 29 | The output of the 30 | localisation network should be [num_batch, 6]. 31 | out_size: tuple of two ints 32 | The size of the output of the network 33 | 34 | 35 | #### Notes 36 | To initialize the network to the identity transform init ``theta`` to : 37 | 38 | ```python 39 | identity = np.array([[1., 0., 0.], 40 | [0., 1., 0.]]) 41 | identity = identity.flatten() 42 | theta = tf.Variable(initial_value=identity) 43 | ``` 44 | 45 | #### Experiments 46 | 47 |
48 |

49 |
50 | 51 | We used cluttered MNIST. Left column are the input images, right are the attended parts of the image by an STN. 52 | 53 | All experiments were run in Tensorflow 0.7. 54 | 55 | ### References 56 | 57 | [1] Jaderberg, Max, et al. "Spatial Transformer Networks." arXiv preprint arXiv:1506.02025 (2015) 58 | 59 | [2] https://github.com/skaae/transformer_network/blob/master/transformerlayer.py 60 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/transformer/data/README.md: -------------------------------------------------------------------------------- 1 | ### How to get the data 2 | 3 | #### Cluttered MNIST 4 | 5 | The cluttered MNIST dataset can be found here [1] or can be generated via [2]. 6 | 7 | Settings used for `cluttered_mnist.py` : 8 | 9 | ```python 10 | 11 | ORG_SHP = [28, 28] 12 | OUT_SHP = [40, 40] 13 | NUM_DISTORTIONS = 8 14 | dist_size = (5, 5) 15 | 16 | ``` 17 | 18 | [1] https://github.com/daviddao/spatial-transformer-tensorflow 19 | 20 | [2] https://github.com/skaae/recurrent-spatial-transformer-code/blob/master/MNIST_SEQUENCE/create_mnist_sequence.py -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/transformer/example.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 | from scipy import ndimage 16 | import tensorflow as tf 17 | from spatial_transformer import transformer 18 | import numpy as np 19 | import matplotlib.pyplot as plt 20 | 21 | # %% Create a batch of three images (1600 x 1200) 22 | # %% Image retrieved from: 23 | # %% https://raw.githubusercontent.com/skaae/transformer_network/master/cat.jpg 24 | im = ndimage.imread('cat.jpg') 25 | im = im / 255. 26 | im = im.reshape(1, 1200, 1600, 3) 27 | im = im.astype('float32') 28 | 29 | # %% Let the output size of the transformer be half the image size. 30 | out_size = (600, 800) 31 | 32 | # %% Simulate batch 33 | batch = np.append(im, im, axis=0) 34 | batch = np.append(batch, im, axis=0) 35 | num_batch = 3 36 | 37 | x = tf.placeholder(tf.float32, [None, 1200, 1600, 3]) 38 | x = tf.cast(batch, 'float32') 39 | 40 | # %% Create localisation network and convolutional layer 41 | with tf.variable_scope('spatial_transformer_0'): 42 | 43 | # %% Create a fully-connected layer with 6 output nodes 44 | n_fc = 6 45 | W_fc1 = tf.Variable(tf.zeros([1200 * 1600 * 3, n_fc]), name='W_fc1') 46 | 47 | # %% Zoom into the image 48 | initial = np.array([[0.5, 0, 0], [0, 0.5, 0]]) 49 | initial = initial.astype('float32') 50 | initial = initial.flatten() 51 | 52 | b_fc1 = tf.Variable(initial_value=initial, name='b_fc1') 53 | h_fc1 = tf.matmul(tf.zeros([num_batch, 1200 * 1600 * 3]), W_fc1) + b_fc1 54 | h_trans = transformer(x, h_fc1, out_size) 55 | 56 | # %% Run session 57 | sess = tf.Session() 58 | sess.run(tf.initialize_all_variables()) 59 | y = sess.run(h_trans, feed_dict={x: batch}) 60 | 61 | # plt.imshow(y[0]) 62 | -------------------------------------------------------------------------------- /TSN/tf_model_zoo/models/video_prediction/download_data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2016 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 | 18 | # Example: 19 | # 20 | # download_dataset.sh datafiles.txt ./tmp 21 | # 22 | # will download all of the files listed in the file, datafiles.txt, into 23 | # a directory, "./tmp". 24 | # 25 | # Each line of the datafiles.txt file should contain the path from the 26 | # bucket root to a file. 27 | 28 | ARGC="$#" 29 | LISTING_FILE=push_datafiles.txt 30 | if [ "${ARGC}" -ge 1 ]; then 31 | LISTING_FILE=$1 32 | fi 33 | OUTPUT_DIR="./" 34 | if [ "${ARGC}" -ge 2 ]; then 35 | OUTPUT_DIR=$2 36 | fi 37 | 38 | echo "OUTPUT_DIR=$OUTPUT_DIR" 39 | 40 | mkdir "${OUTPUT_DIR}" 41 | 42 | function download_file { 43 | FILE=$1 44 | BUCKET="https://storage.googleapis.com/brain-robotics-data" 45 | URL="${BUCKET}/${FILE}" 46 | OUTPUT_FILE="${OUTPUT_DIR}/${FILE}" 47 | DIRECTORY=`dirname ${OUTPUT_FILE}` 48 | echo DIRECTORY=$DIRECTORY 49 | mkdir -p "${DIRECTORY}" 50 | curl --output ${OUTPUT_FILE} ${URL} 51 | } 52 | 53 | while read filename; do 54 | download_file $filename 55 | done <${LISTING_FILE} 56 | -------------------------------------------------------------------------------- /demo_activity/bsn/Evaluation/eval_proposal.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/demo_activity/bsn/Evaluation/eval_proposal.pyc -------------------------------------------------------------------------------- /demo_activity/bsn/Evaluation/utils.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/demo_activity/bsn/Evaluation/utils.pyc -------------------------------------------------------------------------------- /demo_activity/bsn/bsn_clean_train_dataset_dpn92.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ### feature path "k600_resnet152_fold_0_rescale", "k600_resnet152_fold_0_nonrescale" 3 | #for backbone in 'k600_resnet152' 'k600_dpn92' 4 | backbone='dpn92' 5 | fold=2 6 | arch="k600_${backbone}_fold_${fold}_200" 7 | video_info="../video_info.csv" 8 | video_anno="../video_anno.json" 9 | result_file="./output/result_proposal.json" 10 | feat_path_nonrescale="../output_ftrs_RGB_dpn92" 11 | subopts_nonrescale="--feature_path ${feat_path_nonrescale} --video_info ${video_info} --video_anno ${video_anno} --arch ${arch} --fix_scale nonrescale" 12 | ######### nonrescale #### 13 | python main.py --module TEM --mode inference --tem_batch_size 1 ${subopts_nonrescale} 14 | 15 | python main.py --module PGM ${subopts_nonrescale} 16 | 17 | python main.py --module PEM --mode inference --pem_batch_size 1 ${subopts_nonrescale} 18 | 19 | python main.py --module Post_processing ${subopts_nonrescale} --result_file ${result_file} 20 | -------------------------------------------------------------------------------- /demo_activity/bsn/checkpoint/k600_dpn92_fold_2_200_pem_best.pth.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/demo_activity/bsn/checkpoint/k600_dpn92_fold_2_200_pem_best.pth.tar -------------------------------------------------------------------------------- /demo_activity/bsn/checkpoint/k600_dpn92_fold_2_200_tem_best.pth.tar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/demo_activity/bsn/checkpoint/k600_dpn92_fold_2_200_tem_best.pth.tar -------------------------------------------------------------------------------- /demo_activity/bsn/checkpoint/k600_dpn92_fold_2_200nonrescale_opts.json: -------------------------------------------------------------------------------- 1 | {"pem_batch_size": 16, "pem_step_gamma": 0.1, "module": "Post_processing", "pem_u_ratio_m": 1, "feature_path": "../output_ftrs_RGB_dpn92", "tem_hidden_dim": 512, "pem_top_K": 500, "num_sample_end": 8, "pem_feat_dim": 32, "fix_scale": "nonrescale", "video_anno": "../video_anno.json", "checkpoint_path": "./checkpoint", "pgm_threshold": 0.5, "pgm_thread": 32, "arch": "k600_dpn92_fold_2_200", "eval_json": "./Evaluation/data/activity_net.v1-3.min.json", "tem_epoch": 20, "pem_epoch": 20, "tem_step_gamma": 0.1, "tem_weight_decay": 0.0001, "pem_inference_subset": "validation", "tem_step_size": 7, "num_sample_start": 8, "post_process_top_K": 100, "num_sample_action": 16, "pem_high_iou_thres": 0.6, "pem_step_size": 10, "tem_feat_dim": 200, "temporal_scale": 100, "pem_hidden_dim": 256, "soft_nms_low_thres": 0.65, "pem_training_lr": 0.01, "pem_u_ratio_l": 2, "tem_training_lr": 0.001, "pem_low_iou_thres": 0.2, "soft_nms_alpha": 0.75, "bsp_boundary_ratio": 0.2, "pem_top_K_inference": 1000, "save_fig_path": "./output/evaluation_result.jpg", "soft_nms_high_thres": 0.9, "tem_match_thres": 0.5, "num_sample_interpld": 3, "video_info": "../video_info.csv", "boundary_ratio": 0.03, "mode": "train", "tem_batch_size": 16, "pem_weight_decay": 1e-05, "post_process_thread": 64, "result_file": "./output/result_proposal.json"} -------------------------------------------------------------------------------- /demo_activity/bsn/checkpoint/k600_dpn92_fold_2_200rescale_opts.json: -------------------------------------------------------------------------------- 1 | {"pem_batch_size": 16, "pem_step_gamma": 0.1, "module": "Evaluation", "pem_u_ratio_m": 1, "feature_path": "./data/dpn92_rescale_feats", "tem_hidden_dim": 512, "pem_top_K": 500, "num_sample_end": 8, "pem_feat_dim": 32, "fix_scale": "rescale", "video_anno": "./data/activitynet_annotations/dpn92_anet_anno_anet.json", "checkpoint_path": "./checkpoint", "pgm_threshold": 0.5, "pgm_thread": 32, "arch": "k600_dpn92_fold_2_200", "eval_json": "./data/activitynet_annotations/3fold_csv/fold_2_activity_net.v1-3.min.json", "tem_epoch": 20, "pem_epoch": 20, "tem_step_gamma": 0.1, "tem_weight_decay": 0.0001, "pem_inference_subset": "validation", "tem_step_size": 7, "num_sample_start": 8, "post_process_top_K": 100, "num_sample_action": 16, "pem_high_iou_thres": 0.6, "pem_step_size": 10, "tem_feat_dim": 200, "temporal_scale": 100, "pem_hidden_dim": 256, "soft_nms_low_thres": 0.65, "pem_training_lr": 0.01, "pem_u_ratio_l": 2, "tem_training_lr": 0.001, "pem_low_iou_thres": 0.2, "soft_nms_alpha": 0.75, "bsp_boundary_ratio": 0.2, "pem_top_K_inference": 1000, "save_fig_path": "./output/evaluation_result.jpg", "soft_nms_high_thres": 0.9, "tem_match_thres": 0.5, "num_sample_interpld": 3, "video_info": "./data/activitynet_annotations/3fold_csv/fold_2_video_info.csv", "boundary_ratio": 0.03, "mode": "train", "tem_batch_size": 16, "pem_weight_decay": 1e-05, "post_process_thread": 64, "result_file": "./output/dpn92_result_proposal.json"} -------------------------------------------------------------------------------- /demo_activity/ops/__init__.py: -------------------------------------------------------------------------------- 1 | from ops.basic_ops import * -------------------------------------------------------------------------------- /demo_activity/ops/basic_ops.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import math 3 | 4 | 5 | class Identity(torch.nn.Module): 6 | def forward(self, input): 7 | return input 8 | 9 | 10 | class SegmentConsensus(torch.autograd.Function): 11 | 12 | def __init__(self, consensus_type, dim=1): 13 | self.consensus_type = consensus_type 14 | self.dim = dim 15 | self.shape = None 16 | 17 | def forward(self, input_tensor): 18 | self.shape = input_tensor.size() 19 | if self.consensus_type == 'avg': 20 | output = input_tensor.mean(dim=self.dim, keepdim=True) 21 | elif self.consensus_type == 'identity': 22 | output = input_tensor 23 | else: 24 | output = None 25 | 26 | return output 27 | 28 | def backward(self, grad_output): 29 | if self.consensus_type == 'avg': 30 | grad_in = grad_output.expand(self.shape) / float(self.shape[self.dim]) 31 | elif self.consensus_type == 'identity': 32 | grad_in = grad_output 33 | else: 34 | grad_in = None 35 | 36 | return grad_in 37 | 38 | 39 | class ConsensusModule(torch.nn.Module): 40 | 41 | def __init__(self, consensus_type, dim=1): 42 | super(ConsensusModule, self).__init__() 43 | self.consensus_type = consensus_type if consensus_type != 'rnn' else 'identity' 44 | self.dim = dim 45 | 46 | def forward(self, input): 47 | return SegmentConsensus(self.consensus_type, self.dim)(input) 48 | -------------------------------------------------------------------------------- /demo_activity/ops/utils.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import numpy as np 3 | from sklearn.metrics import confusion_matrix 4 | 5 | def get_grad_hook(name): 6 | def hook(m, grad_in, grad_out): 7 | print((name, grad_out[0].data.abs().mean(), grad_in[0].data.abs().mean())) 8 | print((grad_out[0].size())) 9 | print((grad_in[0].size())) 10 | 11 | print((grad_out[0])) 12 | print((grad_in[0])) 13 | 14 | return hook 15 | 16 | 17 | def softmax(scores): 18 | es = np.exp(scores - scores.max(axis=-1)[..., None]) 19 | return es / es.sum(axis=-1)[..., None] 20 | 21 | 22 | def log_add(log_a, log_b): 23 | return log_a + np.log(1 + np.exp(log_b - log_a)) 24 | 25 | 26 | def class_accuracy(prediction, label): 27 | cf = confusion_matrix(prediction, label) 28 | cls_cnt = cf.sum(axis=1) 29 | cls_hit = np.diag(cf) 30 | 31 | cls_acc = cls_hit / cls_cnt.astype(float) 32 | 33 | mean_cls_acc = cls_acc.mean() 34 | 35 | return cls_acc, mean_cls_acc -------------------------------------------------------------------------------- /demo_activity/pretrain/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/demo_activity/pretrain/__init__.py -------------------------------------------------------------------------------- /demo_activity/pretrain/include.py: -------------------------------------------------------------------------------- 1 | import os 2 | from datetime import datetime 3 | PROJECT_PATH = os.path.dirname(os.path.realpath(__file__)) 4 | IDENTIFIER = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') 5 | 6 | 7 | #numerical libs 8 | import math 9 | import numpy as np 10 | import random 11 | import PIL 12 | import cv2 13 | import matplotlib 14 | matplotlib.use('TkAgg') 15 | #matplotlib.use('WXAgg') 16 | #matplotlib.use('Qt4Agg') 17 | #matplotlib.use('Qt5Agg') #Qt4Agg 18 | print(matplotlib.get_backend()) 19 | #print(matplotlib.__version__) 20 | 21 | 22 | # torch libs 23 | import torch 24 | from torch.utils.data.dataset import Dataset 25 | from torch.utils.data import DataLoader 26 | from torch.utils.data.sampler import * 27 | 28 | import torch.nn as nn 29 | import torch.nn.functional as F 30 | import torch.optim as optim 31 | from torch.nn.parallel.data_parallel import data_parallel 32 | 33 | 34 | # std libs 35 | import collections 36 | import copy 37 | import numbers 38 | import inspect 39 | import shutil 40 | from timeit import default_timer as timer 41 | import itertools 42 | from collections import OrderedDict 43 | 44 | import csv 45 | import pandas as pd 46 | import pickle 47 | import glob 48 | import sys 49 | from distutils.dir_util import copy_tree 50 | import time 51 | 52 | import matplotlib.pyplot as plt 53 | from mpl_toolkits.mplot3d import Axes3D 54 | 55 | from skimage.transform import resize as skimage_resize 56 | 57 | 58 | 59 | 60 | # constant # 61 | PI = np.pi 62 | INF = np.inf 63 | EPS = 1e-12 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /demo_activity/pretrain/se_module.py: -------------------------------------------------------------------------------- 1 | from torch import nn 2 | 3 | 4 | class SELayer(nn.Module): 5 | def __init__(self, channel, reduction=16): 6 | super(SELayer, self).__init__() 7 | self.avg_pool = nn.AdaptiveAvgPool2d(1) 8 | self.fc = nn.Sequential( 9 | nn.Linear(channel, int(channel/reduction), bias=False), 10 | nn.ReLU(inplace=True), 11 | nn.Linear(int(channel/reduction), channel, bias=False), 12 | nn.Sigmoid() 13 | ) 14 | 15 | def forward(self, x): 16 | b, c, _, _ = x.size() 17 | y = self.avg_pool(x).view(b, c) 18 | y = self.fc(y).view(b, c, 1, 1) 19 | return x * y.expand_as(x) 20 | -------------------------------------------------------------------------------- /demo_activity/result_process.py: -------------------------------------------------------------------------------- 1 | import json 2 | import sys 3 | import os 4 | import numpy as np 5 | import pandas as pd 6 | 7 | video_label_name_path, logits_path, res_path, video_info, save_path = sys.argv[1:] 8 | # video_label_name_path = './bsn/data/activitynet_annotations/action_name.csv' 9 | # logits_path = 'output_ftrs_RGB_dpn92/v_00Dk03Jr70M.csv' 10 | # res_path = './bsn/output/result_proposal.json' 11 | # video_info = './video_info.csv' 12 | # save_path = 'final_result.json' 13 | 14 | action_name = pd.read_csv(video_label_name_path) 15 | label2name = sorted(list(action_name.values.reshape(-1))) 16 | 17 | with open(res_path) as f: 18 | results = json.load(f) 19 | results = results['results'] 20 | 21 | video_info = pd.read_csv(video_info) 22 | video_duration = video_info.seconds[0] 23 | video_featureFrame = video_info.featureFrame[0] 24 | video_name = video_info.video[0]+'.mp4' 25 | result_info = {} 26 | result_info['filename'] = video_name 27 | result_info['duration'] = video_duration 28 | new_res = [] 29 | 30 | logits = pd.read_csv(os.path.join(logits_path, video_info.video[0]+'.csv')).values 31 | 32 | for key in results.keys(): 33 | one_results = results[key] 34 | for result in one_results[:5]: 35 | start_idx = max(int(result['segment'][0]/video_duration*video_featureFrame/16), 0) 36 | end_idx = min(int(result['segment'][1]/video_duration*video_featureFrame/16), int(video_featureFrame/16)) 37 | segment_logits = logits[start_idx:end_idx, :] 38 | label = np.argmax(np.bincount(np.argmax(segment_logits, axis=1))) 39 | result['label'] = label2name[label] 40 | new_res.append(result) 41 | result_info['results'] = new_res 42 | with open(save_path, 'w') as f: 43 | json.dump(result_info, f) 44 | print 'Save result json in path: ', save_path -------------------------------------------------------------------------------- /demo_activity/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # conda env 3 | #/users/lindq/.conda/envs/pytoch_py2 4 | 5 | # tsn inference 6 | #conda activate py27_pytorch0.3.1 7 | 8 | CUDA_VISIBLE_DEVICES=3 python extract_anet_feature.py $1 # video_path 9 | 10 | # bsn inference 11 | #conda activate pytoch_py2 12 | cd bsn 13 | CUDA_VISIBLE_DEVICES=3 sh bsn_clean_train_dataset_dpn92.sh 14 | 15 | # process results 16 | cd .. 17 | # video_label_name_path, logits_path, res_path, video_info, save_path 18 | python result_process.py ./bsn/data/activitynet_annotations/action_name.csv ./output_ftrs_RGB_dpn92 ./bsn/output/result_proposal.json ./video_info.csv ./final_result.json 19 | -------------------------------------------------------------------------------- /demo_activity/v_Vk-aKj0R65o.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Line290/ActivityNet_task_1/5e985e4455d91af52cccb654040eae2573388c1c/demo_activity/v_Vk-aKj0R65o.mp4 --------------------------------------------------------------------------------